MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ConnectInfo.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace MyCaffe.basecode
8{
12 [Serializable]
13 public class ConnectInfo
14 {
15 TYPE m_location = TYPE.NONE;
16 string m_strServer;
17 string m_strUn;
18 string m_strPw;
19 string m_strDb;
20
24 public enum TYPE
25 {
29 NONE,
33 LOCAL,
37 REMOTE,
41 AZURE
42 }
43
52 public ConnectInfo(string strServer = null, string strDb = "DNN", string strUn = null, string strPw = null, TYPE location = TYPE.NONE)
53 {
54 m_strServer = strServer;
55 m_strDb = strDb;
56 m_strUn = strUn;
57 m_strPw = strPw;
58 m_location = location;
59 }
60
66 public bool Compare(ConnectInfo ci)
67 {
68 if (ci.Server != m_strServer)
69 return false;
70
71 if (ci.Database != m_strDb)
72 return false;
73
74 if (ci.Username != m_strUn)
75 return false;
76
77 if (ci.Password != m_strPw)
78 return false;
79
80 if (ci.Location != m_location)
81 return false;
82
83 return true;
84 }
85
90 public override string ToString()
91 {
92 if (m_strServer == null)
93 return m_strDb;
94
95 if (m_strServer == "AZURE")
96 return m_strServer;
97
98 return m_strServer + "\\" + m_strDb;
99 }
100
106 public string ToString(string strAzure)
107 {
108 if (m_strServer.Contains(strAzure))
109 return "AZURE";
110
111 return ToString();
112 }
113
118 {
119 get { return m_location; }
120 set { m_location = value; }
121 }
122
126 public string Server
127 {
128 get { return m_strServer; }
129 set { m_strServer = value; }
130 }
131
135 public string Database
136 {
137 get { return m_strDb; }
138 set { m_strDb = value; }
139 }
140
144 public string Username
145 {
146 get { return m_strUn; }
147 }
148
152 public string Password
153 {
154 get { return m_strPw; }
155 }
156
161 public string ToInfoString()
162 {
163 if (Server == "DEFAULT" || Server == "AZURE")
164 return Server;
165
166 return Server + ";" + Database + ";" + Username + ";" + Password;
167 }
168
173 public string ToKeyValuePairs()
174 {
175 string str = "";
176
177 str += "Type\t" + Location.ToString() + ";";
178 str += "Server\t" + Server + ";";
179 str += "Database\t" + Database + ";";
180 str += "Username\t" + Username + ";";
181 str += "Password\t" + Password + ";";
182
183 return str;
184 }
185
191 public static ConnectInfo ParseKeyValuePairs(string strKeyValPairs)
192 {
193 string[] rgstr = strKeyValPairs.Split(';');
194 string strServer = null;
195 string strDatabase = null;
196 string strUsername = null;
197 string strPassword = null;
198 string strType = null;
199 TYPE location = TYPE.NONE;
200
201 foreach (string str1 in rgstr)
202 {
203 if (!string.IsNullOrEmpty(str1))
204 {
205 string[] rgstr1 = str1.Split('\t');
206 if (rgstr1.Length != 2)
207 throw new Exception("ConnectInfo: Invalid key-value pair!");
208
209 if (rgstr1[0] == "Type")
210 strType = rgstr1[1];
211
212 else if (rgstr1[0] == "Server")
213 strServer = rgstr1[1];
214
215 else if (rgstr1[0] == "Database")
216 strDatabase = rgstr1[1];
217
218 else if (rgstr1[0] == "Username")
219 strUsername = rgstr1[1];
220
221 else if (rgstr1[0] == "Password")
222 strPassword = rgstr1[1];
223 }
224 }
225
226 if (strType == TYPE.AZURE.ToString())
227 location = TYPE.AZURE;
228 else if (strType == TYPE.REMOTE.ToString())
229 location = TYPE.REMOTE;
230 else if (strType == TYPE.LOCAL.ToString())
231 location = TYPE.LOCAL;
232
233 if (strServer.Length == 0)
234 strServer = null;
235
236 if (strDatabase.Length == 0)
237 strDatabase = null;
238
239 if (strUsername.Length == 0)
240 strUsername = null;
241
242 if (strPassword.Length == 0)
243 strPassword = null;
244
245 return new ConnectInfo(strServer, strDatabase, strUsername, strPassword, location);
246 }
247 }
248}
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
Definition: ConnectInfo.cs:14
ConnectInfo(string strServer=null, string strDb="DNN", string strUn=null, string strPw=null, TYPE location=TYPE.NONE)
The constructor.
Definition: ConnectInfo.cs:52
string ToInfoString()
Returns a string representation of the connection information.
Definition: ConnectInfo.cs:161
string Server
Get/set the server.
Definition: ConnectInfo.cs:127
string Username
Returns the username.
Definition: ConnectInfo.cs:145
TYPE
Defines the generic connection location
Definition: ConnectInfo.cs:25
override string ToString()
Returns a string representation of the connection.
Definition: ConnectInfo.cs:90
string Database
Get/set the database.
Definition: ConnectInfo.cs:136
bool Compare(ConnectInfo ci)
Compare another ConnectInfo with this one.
Definition: ConnectInfo.cs:66
string Password
Returns the password.
Definition: ConnectInfo.cs:153
TYPE Location
Get/set the generic location type.
Definition: ConnectInfo.cs:118
string ToString(string strAzure)
Returns a string representation of the connection.
Definition: ConnectInfo.cs:106
string ToKeyValuePairs()
Returns the connection information as a set of key-value pairs.
Definition: ConnectInfo.cs:173
static ConnectInfo ParseKeyValuePairs(string strKeyValPairs)
Parses a key-value pair string containing the connection information and returns a ConnectInfo.
Definition: ConnectInfo.cs:191
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
@ NONE
No training category specified.