source: BMXNET_RPMS_dotNET_UTILITIES-BMX/trunk/cs/bmx_0200scr/BMX2/BMXNet/BMXNetConnection.cs@ 1088

Last change on this file since 1088 was 815, checked in by Sam Habiel, 14 years ago

Initial commit of C# Source Code. Now to try to get it to compile.

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