-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJARVISDataSourceManager.cs
More file actions
138 lines (132 loc) · 5.69 KB
/
Copy pathJARVISDataSourceManager.cs
File metadata and controls
138 lines (132 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace JARVIS4
{
/// <summary>
/// This class handles all data source management, i.e. adding of data sources, testing connections, removing of data sources
/// </summary>
public static class JARVISDataSourceManager
{
/// <summary>
/// Private Declaration of variables that will be shared throughout
/// </summary>
private static string file_directory = @"C:\JARVIS4\UserDefinedDataSources";
public static StatusObject AddDataSource(string Server, string Database, string UserID, string Password)
{
StatusObject SO = new StatusObject();
try
{
SqlConnection connection = new SqlConnection(String.Format("server={0};database={1};user id={2};password={3}", Server, Database, UserID, Password));
// Test the database connection
connection.Open();
connection.Close();
// If the connection succeeds then save it to a textfile somewhere and return a new JARVISDataSource
Directory.CreateDirectory(file_directory);
StreamWriter datasource_file = new StreamWriter(String.Format(@"{0}\SqlAuthDataSources.txt", file_directory), append: true);
datasource_file.WriteLine(String.Format("{0},{1},{2},{3}", Server, Database, UserID, Password));
datasource_file.Close();
JARVISDataSource new_data_source = new JARVISDataSource(Server, Database, UserID, Password);
SO.UDDynamic = new_data_source;
}
catch(Exception e)
{
SO = new StatusObject(e.Message, "JARVISDataSourceManager_AddDataSource", StatusObject.StatusCode.FAILURE, e.ToString());
}
return SO;
}
public static StatusObject AddDataSource(string Server, string Database)
{
StatusObject SO = new StatusObject();
try
{
SqlConnection connection = new SqlConnection(String.Format("server={0};database={1};trusted_connection=true", Server, Database));
// Test the database connection
connection.Open();
connection.Close();
// If the connection succeeds then save it to a textfile somewhere and return a new JARVISDataSource
Directory.CreateDirectory(file_directory);
StreamWriter datasource_file = new StreamWriter(String.Format(@"{0}\WinAuthDataSources.txt", file_directory), append: true);
datasource_file.WriteLine(String.Format("{0},{1},{2}", Server, Database, true));
datasource_file.Close();
JARVISDataSource new_data_source = new JARVISDataSource(Server, Database);
SO.UDDynamic = new_data_source;
}
catch (Exception e)
{
SO = new StatusObject(e.Message, "JARVISDataSourceManager_AddDataSource", StatusObject.StatusCode.FAILURE, e.ToString());
}
return SO;
}
public static StatusObject ConnectToDataSource()
{
StatusObject SO = new StatusObject();
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Server=sql2008kl;Database=claims_dev;user id=sa;password=password";
connection.Open();
connection.Close();
}
catch (Exception e)
{
SO = new StatusObject(e.Message, "JARVISDataSourceManager_01", StatusObject.StatusCode.FAILURE, e.ToString());
}
return SO;
}
public static StatusObject ConnectToDataSource(string server, string database, string user_id, string password)
{
StatusObject SO = new StatusObject();
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = String.Format("Server={0};Database={1};user id={2};password={3}", server, database, user_id, password);
connection.Open();
connection.Close();
}
catch (Exception e)
{
SO = new StatusObject(e.Message, "JARVISDataSourceManager_01", StatusObject.StatusCode.FAILURE, e.ToString());
}
return SO;
}
/// <summary>
/// Load all data sources
/// </summary>
/// <param name="file_path"></param>
/// <returns></returns>
public static StatusObject LoadDataSourceConnectionInformation(out List<JARVISDataSource> DataSourceList)
{
StatusObject SO = new StatusObject();
try
{
DataSourceList = new List<JARVISDataSource>();
}
catch(Exception e)
{
DataSourceList = new List<JARVISDataSource>();
}
return SO;
}
/// <summary>
/// This function will build a map of any datasource, create a list of indexed sql query strings
/// </summary>
/// <returns></returns>
public static StatusObject BuildDataSourceMapping()
{
StatusObject SO = new StatusObject();
try
{
}
catch(Exception e)
{
SO = new StatusObject(e.Message, "JARVISDataSourceManager", StatusObject.StatusCode.FAILURE, e.ToString());
}
return SO;
}
}
}