source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Ado/BMXNetConnection.cs@ 1180

Last change on this file since 1180 was 1146, checked in by Sam Habiel, 13 years ago

Initial Import of BMX4

File size: 8.6 KB
Line 
1using System;
2using System.Data;
3using System.Diagnostics;
4using System.Reflection;
5using System.Security.Principal;
6
7namespace IndianHealthService.BMXNet.Ado
8{
9 /// <summary>
10 /// BMXNET implementaiton of DbConnection. This class can be used like
11 /// any ADO.NET DbConnection implementation or the suggested RemoteSession API's can
12 /// be used.
13 ///
14 /// See ADO.NET documentation for details of this class.
15 /// </summary>
16 internal class BMXNetConnection : System.Data.Common.DbConnection, IDbConnection
17 {
18 private ConnectionState m_state;
19 private string m_sConnString;
20
21
22 private BMXNetSessionConnection m_sessionConnection;
23
24 public BMXNetSessionConnection SessionConnection
25 {
26 get { return m_sessionConnection; }
27 set { m_sessionConnection = value; }
28 }
29 private RPMSDb m_RPMSDb;
30 private int m_nTimeout;
31 private string m_sDatabase;
32
33 private string m_sAccess;
34 private string m_sVerify;
35 private int m_nPort;
36 private string m_sAddress;
37 private string m_sAppContext;
38 private bool m_bUseWinIdent;
39
40 // default constructor.
41 public BMXNetConnection()
42 {
43 // Initialize the connection object into the closed state.
44 m_state = ConnectionState.Closed;
45
46 //TAE ... crazy this.m_rpx = new BMXNetBroker();
47 }
48
49 public BMXNetConnection(string sConnString)
50 {
51 // Initialize the connection object into a closed state.
52 m_state = ConnectionState.Closed;
53 this.ConnectionString = sConnString;
54
55
56 }
57
58 public BMXNetConnection(BMXNetSessionConnection aConnection)
59 {
60 if (aConnection.IsConnected)
61 {
62 m_state = ConnectionState.Open;
63 this.SessionConnection = aConnection;
64 m_RPMSDb = new RPMSDb(this.SessionConnection);
65
66 }
67 else
68 {
69 m_state = ConnectionState.Closed;
70 }
71 }
72
73 /****
74 * IMPLEMENT THE REQUIRED PROPERTIES.
75 ****/
76 override public string ConnectionString
77 {
78 get
79 {
80 return m_sConnString;
81 }
82 set
83 {
84 m_nTimeout = 0;
85 try
86 {
87 // Parse values from connect string
88 m_sConnString = value;
89 string sSemi = ";";
90 string sEq = "=";
91 string sU = "^";
92 char[] cSemi = sSemi.ToCharArray();
93 char[] cEq = sEq.ToCharArray();
94 char[] cU = sU.ToCharArray();
95 string [] saSplit = m_sConnString.Split(cSemi);
96 string [] saProp;
97 string [] saTemp;
98 string sPropName;
99 string sPropVal;
100 for (int j = 0; j<saSplit.Length; j++)
101 {
102 saProp = saSplit[j].Split(cEq);
103 if (saProp.Length != 2)
104 {
105 //throw invalid parameter exception
106 }
107 sPropName = saProp[0];
108 sPropVal = saProp[1];
109 sPropName = sPropName.ToUpper();
110 if (sPropName == "PASSWORD")
111 {
112 saTemp = sPropVal.Split(cU);
113 if (saTemp.Length != 2)
114 {
115 //throw invalid parameter exception
116 }
117
118 m_sAccess = saTemp[0];
119 m_sVerify = saTemp[1];
120 }
121 if (sPropName == "ACCESS CODE")
122 {
123 m_sAccess = sPropVal;
124 }
125 if (sPropName == "VERIFY CODE")
126 {
127 m_sVerify = sPropVal;
128 }
129 if ((sPropName == "LOCATION") || (sPropName == "PORT"))
130 {
131 m_nPort = Convert.ToInt16(sPropVal);
132 }
133 if (sPropName == "DATA SOURCE")
134 {
135 m_sAddress = sPropVal;
136 m_sDatabase = sPropVal;
137 }
138 if (sPropName == "EXTENDED PROPERTIES")
139 {
140 m_sAppContext = sPropVal;
141 }
142 if (sPropName == "WINIDENT")
143 {
144 m_bUseWinIdent = false;
145 sPropVal = sPropVal.ToUpper();
146 if (sPropVal == "TRUE")
147 m_bUseWinIdent = true;
148 }
149 }
150
151 }
152 catch (Exception e)
153 {
154 if (m_bUseWinIdent)
155 {
156 //so something
157 }
158 //re-throw exception
159 throw e;
160 }
161
162 }
163 }
164
165 public override int ConnectionTimeout
166 {
167 get
168 {
169 // Returns the connection time-out value set in the connection
170 // string. Zero indicates an indefinite time-out period.
171 return m_nTimeout;
172 }
173 }
174
175 override public string Database
176 {
177 get
178 {
179 // Returns an initial database as set in the connection string.
180 // An empty string indicates not set - do not return a null reference.
181 return m_sDatabase;
182 }
183 }
184
185 public override ConnectionState State
186 {
187 get { return m_state; }
188 }
189
190 public ConnectionState SetState
191 {
192 set
193 {
194 m_state = value;
195 }
196 }
197
198
199
200 /****
201 * IMPLEMENT THE REQUIRED METHODS.
202 ****/
203
204 new public IDbTransaction BeginTransaction()
205 {
206 throw new NotSupportedException();
207 }
208
209 protected override System.Data.Common.DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
210 {
211 throw new Exception("The method or operation is not implemented.");
212 }
213
214 new public IDbTransaction BeginTransaction(IsolationLevel level)
215 {
216 throw new NotSupportedException();
217 }
218
219 override public void ChangeDatabase(string dbName)
220 {
221 //should dbname include address, port, access & verify?
222 /*
223 * Change the database setting on the back-end. Note that it is a method
224 * and not a property because the operation requires an expensive
225 * round trip.
226 */
227 }
228
229 override public void Open()
230 {
231 /*
232 * Open the RPMS connection and set the ConnectionState
233 * property.
234 */
235 //If the connection is already open, then return.
236 //If you wan't to re-open an already open connection,
237 //you must first close it.
238
239 //TAE Confirm it's open
240 if (this.SessionConnection == null || (!this.SessionConnection.IsConnected))
241 {
242 this.SetState = ConnectionState.Closed;
243 throw new BMXNetException("BMXLib is not available for ADO.NET connection.");
244 }
245
246 this.SetState = ConnectionState.Open;
247
248 //TAE
249 //if (m_rpx == true)
250 // return;
251
252
253 //TAE
254 /*
255 try
256 {
257 m_state = ConnectionState.Connecting;
258 m_rpx = new BMXNetNativeLib();
259
260 m_rpx.MServerPort = m_nPort;
261 bool bRet = false;
262 if (this.m_bUseWinIdent == true)
263 {
264 WindowsIdentity winIdent = WindowsIdentity.GetCurrent();
265 bRet = m_rpx.OpenConnection(m_sAddress, winIdent);
266 }
267 else
268 {
269 bRet = m_rpx.OpenConnection(m_sAddress, m_sAccess, m_sVerify);
270 }
271 if (bRet == true)
272 {
273 m_state = ConnectionState.Open;
274 }
275 else
276 {
277 m_state = ConnectionState.Closed;
278 return;
279 }
280 m_RPMSDb = new RPMSDb(m_rpx);
281
282 }
283
284 catch (Exception ex)
285 {
286 string s = ex.Message + ex.StackTrace;
287 throw new BMXNetException(s);
288 }*/
289 }
290
291 override public void Close()
292 {
293 /*
294 * Close the rpms connection and set the ConnectionState
295 * property.
296 */
297 try
298 {
299 if (this.State == ConnectionState.Closed)
300 return;
301 this.SetState = ConnectionState.Closed;
302 }
303 catch (Exception ex)
304 {
305 Debug.Write(ex.Message + ex.StackTrace);
306 }
307 }
308
309 new public IDbCommand CreateCommand()
310 {
311 // Return a new instance of a command object.
312 BMXNetCommand comm = new BMXNetCommand();
313 comm.Connection = this;
314 return comm;
315 }
316
317 override protected System.Data.Common.DbCommand CreateDbCommand()
318 {
319 // Return a new instance of a command object.
320 BMXNetCommand comm = new BMXNetCommand();
321 comm.Connection = this;
322 return comm;
323 }
324
325 public override string DataSource
326 {
327 get { throw new Exception("The method or operation is not implemented."); }
328 }
329
330 public override string ServerVersion
331 {
332 get { throw new Exception("The method or operation is not implemented."); }
333 }
334
335 /*
336 * Implementation specific properties / methods.
337 */
338 internal RPMSDb RPMSDb
339 {
340 get { return m_RPMSDb; }
341 }
342
343 void IDisposable.Dispose()
344 {
345 this.Dispose(true);
346 System.GC.SuppressFinalize(this);
347 }
348
349 //protected override void Dispose(bool disposing)
350 //{
351 // /*
352 // * Dispose of the object and perform any cleanup.
353 // */
354
355 // if (m_state == ConnectionState.Open)
356 // {
357 // this.Close();
358 // }
359 //}
360
361 }
362}
Note: See TracBrowser for help on using the repository browser.