| 1 | using System; | 
|---|
| 2 | using System.Data; | 
|---|
| 3 | using System.Diagnostics; | 
|---|
| 4 | using System.IO; | 
|---|
| 5 | using System.IO.IsolatedStorage; | 
|---|
| 6 | using System.Runtime.Serialization; | 
|---|
| 7 | using System.Runtime.Serialization.Formatters; | 
|---|
| 8 | using System.Runtime.Serialization.Formatters.Soap; | 
|---|
| 9 | using System.Windows.Forms; | 
|---|
| 10 | using System.Security.Principal; | 
|---|
| 11 | using System.Text; | 
|---|
| 12 | using System.Security.Cryptography; | 
|---|
| 13 | using System.Timers; | 
|---|
| 14 | using System.Threading; | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | namespace IndianHealthService.BMXNet | 
|---|
| 18 | { | 
|---|
| 19 | public class BMXNetEventArgs : EventArgs | 
|---|
| 20 | { | 
|---|
| 21 | public string BMXParam; | 
|---|
| 22 | public string BMXEvent; | 
|---|
| 23 | } | 
|---|
| 24 |  | 
|---|
| 25 | /// <summary> | 
|---|
| 26 | /// Contains methods and properties to support RPMS Login for .NET applications | 
|---|
| 27 | /// </summary> | 
|---|
| 28 | public class BMXNetConnectInfo : System.Windows.Forms.Control | 
|---|
| 29 | { | 
|---|
| 30 |  | 
|---|
| 31 | /// <summary> | 
|---|
| 32 | /// Serializes RPMS server address and port | 
|---|
| 33 | /// </summary> | 
|---|
| 34 | [SerializableAttribute] | 
|---|
| 35 | private class ServerData | 
|---|
| 36 | { | 
|---|
| 37 | public string   m_sAddress = ""; | 
|---|
| 38 | public int              m_nPort = 0; | 
|---|
| 39 | public string   m_sNamespace = ""; | 
|---|
| 40 |  | 
|---|
| 41 | public ServerData() | 
|---|
| 42 | { | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | public ServerData(string sAddress, int nPort) | 
|---|
| 46 | { | 
|---|
| 47 | this.m_nPort = nPort; | 
|---|
| 48 | this.m_sAddress = sAddress; | 
|---|
| 49 | this.m_sNamespace = ""; | 
|---|
| 50 | } | 
|---|
| 51 | public ServerData(string sAddress, int nPort, string sNamespace) | 
|---|
| 52 | { | 
|---|
| 53 | this.m_nPort = nPort; | 
|---|
| 54 | this.m_sAddress = sAddress; | 
|---|
| 55 | this.m_sNamespace = sNamespace; | 
|---|
| 56 | } | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | public BMXNetConnectInfo() | 
|---|
| 60 | { | 
|---|
| 61 | m_BMXBroker = new BMXNetSocketBroker(); | 
|---|
| 62 |  | 
|---|
| 63 | //Initialize BMXNetEvent timer | 
|---|
| 64 | m_timerEvent = new System.Timers.Timer(); | 
|---|
| 65 | m_timerEvent.Elapsed+=new ElapsedEventHandler(OnEventTimer); | 
|---|
| 66 | m_timerEvent.Interval = 10000; | 
|---|
| 67 | m_timerEvent.Enabled = false; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | public BMXNetBroker Broker | 
|---|
| 71 | { | 
|---|
| 72 | get { return (BMXNetBroker)this.NativeBroker; } | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 |  | 
|---|
| 76 |  | 
|---|
| 77 | #region BMXNetEvent | 
|---|
| 78 |  | 
|---|
| 79 | private System.Timers.Timer m_timerEvent; | 
|---|
| 80 | public delegate void BMXNetEventDelegate(Object obj, BMXNetEventArgs e); | 
|---|
| 81 | public event BMXNetEventDelegate BMXNetEvent; | 
|---|
| 82 |  | 
|---|
| 83 | /// <summary> | 
|---|
| 84 | /// Enables and disables event polling for the RPMS connection | 
|---|
| 85 | /// </summary> | 
|---|
| 86 | public bool EventPollingEnabled | 
|---|
| 87 | { | 
|---|
| 88 | get | 
|---|
| 89 | { | 
|---|
| 90 | return m_timerEvent.Enabled; | 
|---|
| 91 | } | 
|---|
| 92 | set | 
|---|
| 93 | { | 
|---|
| 94 | //                              Debug.Write("ConnectInfo handle: " + this.Handle.ToString() + "\n"); | 
|---|
| 95 | //System.IntPtr pHandle = this.Handle; | 
|---|
| 96 | m_timerEvent.Enabled = value; | 
|---|
| 97 | } | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | /// <summary> | 
|---|
| 101 | /// Sets and retrieves the interval in milliseconds for RPMS event polling | 
|---|
| 102 | /// </summary> | 
|---|
| 103 | public double EventPollingInterval | 
|---|
| 104 | { | 
|---|
| 105 | get | 
|---|
| 106 | { | 
|---|
| 107 | return m_timerEvent.Interval; | 
|---|
| 108 | } | 
|---|
| 109 | set | 
|---|
| 110 | { | 
|---|
| 111 | m_timerEvent.Interval = value; | 
|---|
| 112 | } | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | /// <summary> | 
|---|
| 116 | /// Register interest in an RPMS event. | 
|---|
| 117 | /// </summary> | 
|---|
| 118 | /// <param name="EventName"></param> | 
|---|
| 119 | /// <returns></returns> | 
|---|
| 120 | public int SubscribeEvent(string EventName) | 
|---|
| 121 | { | 
|---|
| 122 | try | 
|---|
| 123 | { | 
|---|
| 124 | //System.IntPtr pHandle = this.Handle; | 
|---|
| 125 | DataTable dt; | 
|---|
| 126 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); | 
|---|
| 127 | if (this.IsHandleCreated == false) | 
|---|
| 128 | { | 
|---|
| 129 | this.CreateHandle(); | 
|---|
| 130 | } | 
|---|
| 131 | dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT REGISTER^" + EventName, "dt"}); | 
|---|
| 132 |  | 
|---|
| 133 | //                              dt = RPMSDataTable("BMX EVENT REGISTER^" + EventName, "dt"); | 
|---|
| 134 | DataRow dr = dt.Rows[0]; | 
|---|
| 135 | int nRet = (int) dr["ERRORID"]; | 
|---|
| 136 | return nRet; | 
|---|
| 137 | } | 
|---|
| 138 | catch (Exception ex) | 
|---|
| 139 | { | 
|---|
| 140 | Debug.Write(ex.Message); | 
|---|
| 141 | return 99; | 
|---|
| 142 | } | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | /// <summary> | 
|---|
| 146 | /// Unregister an RPMS event | 
|---|
| 147 | /// </summary> | 
|---|
| 148 | /// <param name="EventName"></param> | 
|---|
| 149 | /// <returns></returns> | 
|---|
| 150 | public int UnSubscribeEvent(string EventName) | 
|---|
| 151 | { | 
|---|
| 152 | try | 
|---|
| 153 | { | 
|---|
| 154 | DataTable dt; | 
|---|
| 155 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); | 
|---|
| 156 | if (this.IsHandleCreated == false) | 
|---|
| 157 | { | 
|---|
| 158 | this.CreateHandle(); | 
|---|
| 159 | } | 
|---|
| 160 | dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT UNREGISTER^" + EventName, "dt"}); | 
|---|
| 161 |  | 
|---|
| 162 | DataRow dr = dt.Rows[0]; | 
|---|
| 163 | int nRet = (int) dr["ERRORID"]; | 
|---|
| 164 | return nRet; | 
|---|
| 165 | } | 
|---|
| 166 | catch (Exception ex) | 
|---|
| 167 | { | 
|---|
| 168 | Debug.Write(ex.Message); | 
|---|
| 169 | return 99; | 
|---|
| 170 | } | 
|---|
| 171 | } | 
|---|
| 172 |  | 
|---|
| 173 | /// <summary> | 
|---|
| 174 | ///  Raise an RPMS event | 
|---|
| 175 | /// </summary> | 
|---|
| 176 | /// <param name="EventName">The name of the event to raise</param> | 
|---|
| 177 | /// <param name="Param">Parameters associated with the event</param> | 
|---|
| 178 | /// <param name="RaiseBack">True if the event should be raised back to the caller</param> | 
|---|
| 179 | /// <returns></returns> | 
|---|
| 180 | public int RaiseEvent(string EventName, string Param, bool RaiseBack) | 
|---|
| 181 | { | 
|---|
| 182 | string sBack = (RaiseBack == true)?"TRUE":"FALSE"; | 
|---|
| 183 | try | 
|---|
| 184 | { | 
|---|
| 185 | DataTable dt; | 
|---|
| 186 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); | 
|---|
| 187 | if (this.IsHandleCreated == false) | 
|---|
| 188 | { | 
|---|
| 189 | this.CreateHandle(); | 
|---|
| 190 | } | 
|---|
| 191 | dt = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT RAISE^" + EventName + "^" + Param + "^" + sBack + "^", "dt"}); | 
|---|
| 192 |  | 
|---|
| 193 | DataRow dr = dt.Rows[0]; | 
|---|
| 194 | int nRet = (int) dr["ERRORID"]; | 
|---|
| 195 | return nRet; | 
|---|
| 196 | } | 
|---|
| 197 | catch (Exception ex) | 
|---|
| 198 | { | 
|---|
| 199 | Debug.Write(ex.Message); | 
|---|
| 200 | return 99; | 
|---|
| 201 | } | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 204 | /// <summary> | 
|---|
| 205 | /// Sets and retrieves the number of times that the Event Timer will generage a BMXNet AutoFire event. | 
|---|
| 206 | /// For example, if AutoFire == 3, then every 3rd time the Event Timer fires, it will generate an AutoFire event. | 
|---|
| 207 | /// </summary> | 
|---|
| 208 | public int AutoFire | 
|---|
| 209 | { | 
|---|
| 210 | get | 
|---|
| 211 | { | 
|---|
| 212 | return m_nAutoFireIncrements; | 
|---|
| 213 | } | 
|---|
| 214 | set | 
|---|
| 215 | { | 
|---|
| 216 | m_nAutoFireIncrements = value; | 
|---|
| 217 | } | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | //Retrieve events registered by this session | 
|---|
| 221 | private int m_nAutoFireIncrements = 0; | 
|---|
| 222 | private int m_nAutoFireCount = 0; | 
|---|
| 223 |  | 
|---|
| 224 | private void OnEventTimer(object source, ElapsedEventArgs e) | 
|---|
| 225 | { | 
|---|
| 226 | try | 
|---|
| 227 | { | 
|---|
| 228 | this.NativeBroker.BMXRWL.AcquireWriterLock(5); | 
|---|
| 229 | try | 
|---|
| 230 | { | 
|---|
| 231 | this.m_timerEvent.Enabled = false; | 
|---|
| 232 |  | 
|---|
| 233 | Object obj = this; | 
|---|
| 234 | BMXNetEventArgs args = new BMXNetEventArgs(); | 
|---|
| 235 | m_nAutoFireCount++; | 
|---|
| 236 | if ((m_nAutoFireIncrements > 0)&&(m_nAutoFireCount >= m_nAutoFireIncrements)) | 
|---|
| 237 | { | 
|---|
| 238 | m_nAutoFireCount = 0; | 
|---|
| 239 | args.BMXEvent = "BMXNet AutoFire"; | 
|---|
| 240 | args.BMXParam = ""; | 
|---|
| 241 | if (BMXNetEvent != null) | 
|---|
| 242 | { | 
|---|
| 243 | BMXNetEvent(obj, args); | 
|---|
| 244 | } | 
|---|
| 245 | this.m_timerEvent.Enabled = true; | 
|---|
| 246 | return; | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 | if (!this.Broker.IsConnected) | 
|---|
| 250 | { | 
|---|
| 251 | this.m_timerEvent.Enabled = true; | 
|---|
| 252 | return; | 
|---|
| 253 | } | 
|---|
| 254 |  | 
|---|
| 255 | DataTable dtEvents = new DataTable("BMXNetEvents"); | 
|---|
| 256 |  | 
|---|
| 257 | try | 
|---|
| 258 | { | 
|---|
| 259 | if (this.IsHandleCreated == false) | 
|---|
| 260 | { | 
|---|
| 261 | this.CreateHandle(); | 
|---|
| 262 | } | 
|---|
| 263 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); | 
|---|
| 264 | dtEvents = (DataTable) this.Invoke(rdtd, new object[] {"BMX EVENT POLL", "BMXNetEvents"}); | 
|---|
| 265 | } | 
|---|
| 266 | catch (Exception ex) | 
|---|
| 267 | { | 
|---|
| 268 | string sMsg = ex.Message; | 
|---|
| 269 | this.m_timerEvent.Enabled = true; | 
|---|
| 270 | return; | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | try | 
|---|
| 274 | { | 
|---|
| 275 | if (dtEvents.Rows.Count == 0) | 
|---|
| 276 | { | 
|---|
| 277 | this.m_timerEvent.Enabled = true; | 
|---|
| 278 | return; | 
|---|
| 279 | } | 
|---|
| 280 | } | 
|---|
| 281 | catch(Exception ex) | 
|---|
| 282 | { | 
|---|
| 283 | Debug.Write("upper Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n"); | 
|---|
| 284 | } | 
|---|
| 285 | try | 
|---|
| 286 | { | 
|---|
| 287 | //If events exist, raise BMXNetEvent | 
|---|
| 288 | foreach (DataRow dr in dtEvents.Rows) | 
|---|
| 289 | { | 
|---|
| 290 | args.BMXEvent = dr["EVENT"].ToString(); | 
|---|
| 291 | args.BMXParam = dr["PARAM"].ToString(); | 
|---|
| 292 | if (BMXNetEvent != null) | 
|---|
| 293 | { | 
|---|
| 294 | BMXNetEvent(obj, args); | 
|---|
| 295 | } | 
|---|
| 296 | } | 
|---|
| 297 | this.m_timerEvent.Enabled = true; | 
|---|
| 298 | return; | 
|---|
| 299 | } | 
|---|
| 300 | catch(Exception ex) | 
|---|
| 301 | { | 
|---|
| 302 | Debug.Write("lower Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n"); | 
|---|
| 303 | } | 
|---|
| 304 | } | 
|---|
| 305 | catch(Exception ex) | 
|---|
| 306 | { | 
|---|
| 307 | Debug.Write("Exception in BMXNetConnectInfo.OnEventTimer: " + ex.Message + "\n"); | 
|---|
| 308 | } | 
|---|
| 309 | finally | 
|---|
| 310 | { | 
|---|
| 311 | this.NativeBroker.BMXRWL.ReleaseWriterLock(); | 
|---|
| 312 | this.m_timerEvent.Enabled = true; | 
|---|
| 313 | } | 
|---|
| 314 | } | 
|---|
| 315 | catch | 
|---|
| 316 | { | 
|---|
| 317 | Debug.Write("     OnEventTimer failed to obtain lock.\n"); | 
|---|
| 318 | } | 
|---|
| 319 | } | 
|---|
| 320 |  | 
|---|
| 321 | #endregion BMXNetEvent | 
|---|
| 322 |  | 
|---|
| 323 | #region Fields | 
|---|
| 324 |  | 
|---|
| 325 | private ServerData                              m_ServerData; | 
|---|
| 326 | private string                                  m_sServerAddress; | 
|---|
| 327 | private int                                             m_nServerPort; | 
|---|
| 328 | private string                  m_sServerNamespace; | 
|---|
| 329 | private string                                  m_sDUZ2; | 
|---|
| 330 | private int                                             m_nDivisionCount = 0; | 
|---|
| 331 | private string                                  m_sUserName; | 
|---|
| 332 | private string                                  m_sDivision; | 
|---|
| 333 | private string                                  m_sAppcontext; | 
|---|
| 334 | private BMXNetBroker m_BMXBroker; | 
|---|
| 335 | private bool                                    m_bAutoServer = false; | 
|---|
| 336 | private bool                                    m_bAutoLogin = false; | 
|---|
| 337 |  | 
|---|
| 338 | #endregion Fields | 
|---|
| 339 |  | 
|---|
| 340 | #region Properties | 
|---|
| 341 |  | 
|---|
| 342 | //              /// <summary> | 
|---|
| 343 | //              /// Set and retrieve the timeout in milliseconds for locking the transmit port. | 
|---|
| 344 | //              /// If the transmit port is unavailable an ApplicationException will be thrown. | 
|---|
| 345 | //              /// </summary> | 
|---|
| 346 | //              public int TransmitLockTimeout | 
|---|
| 347 | //              { | 
|---|
| 348 | //                      get | 
|---|
| 349 | //                      { | 
|---|
| 350 | //                              return m_nTransmitLockTimeout; | 
|---|
| 351 | //                      } | 
|---|
| 352 | //                      set | 
|---|
| 353 | //                      { | 
|---|
| 354 | //                              m_nTransmitLockTimeout = value; | 
|---|
| 355 | //                      } | 
|---|
| 356 | //              } | 
|---|
| 357 |  | 
|---|
| 358 | /// <summary> | 
|---|
| 359 | /// Set and retrieve the timeout, in milliseconds, to receive a response from the RPMS server. | 
|---|
| 360 | /// If the retrieve time exceeds the timeout, an exception will be thrown and the connection will be closed. | 
|---|
| 361 | /// The default is 30 seconds. | 
|---|
| 362 | /// </summary> | 
|---|
| 363 | public int ReceiveTimeout | 
|---|
| 364 | { | 
|---|
| 365 | get { return this.NativeBroker.ReceiveTimeout; } | 
|---|
| 366 | set { this.NativeBroker.ReceiveTimeout = value; } | 
|---|
| 367 | } | 
|---|
| 368 |  | 
|---|
| 369 | public string MServerNameSpace | 
|---|
| 370 | { | 
|---|
| 371 | get | 
|---|
| 372 | { | 
|---|
| 373 | return this.NativeBroker.MServerNamespace; | 
|---|
| 374 | } | 
|---|
| 375 | set | 
|---|
| 376 | { | 
|---|
| 377 | this.NativeBroker.MServerNamespace = value; | 
|---|
| 378 | } | 
|---|
| 379 | } | 
|---|
| 380 |  | 
|---|
| 381 | public BMXNetSocketBroker NativeBroker | 
|---|
| 382 | { | 
|---|
| 383 | get | 
|---|
| 384 | { | 
|---|
| 385 | return (BMXNetSocketBroker)m_BMXBroker; | 
|---|
| 386 | } | 
|---|
| 387 | } | 
|---|
| 388 |  | 
|---|
| 389 | public string AppContext | 
|---|
| 390 | { | 
|---|
| 391 | get | 
|---|
| 392 | { | 
|---|
| 393 | return m_sAppcontext; | 
|---|
| 394 | } | 
|---|
| 395 | set | 
|---|
| 396 | { | 
|---|
| 397 | if (this.Broker.IsConnected) | 
|---|
| 398 | { | 
|---|
| 399 | try | 
|---|
| 400 | { | 
|---|
| 401 | try | 
|---|
| 402 | { | 
|---|
| 403 | m_BMXBroker.AppContext = value; | 
|---|
| 404 | m_sAppcontext = value; | 
|---|
| 405 | } | 
|---|
| 406 | catch (Exception ex) | 
|---|
| 407 | { | 
|---|
| 408 | Debug.Write(ex.Message); | 
|---|
| 409 | throw ex; | 
|---|
| 410 | } | 
|---|
| 411 | finally | 
|---|
| 412 | { | 
|---|
| 413 | } | 
|---|
| 414 | } | 
|---|
| 415 | catch (ApplicationException aex) | 
|---|
| 416 | { | 
|---|
| 417 | // The writer lock request timed out. | 
|---|
| 418 | Debug.Write("BMXNetConnectInfo.AppContext lock request timed out.\n"); | 
|---|
| 419 | throw aex; | 
|---|
| 420 | } | 
|---|
| 421 | }//end if | 
|---|
| 422 | }//end set | 
|---|
| 423 | } | 
|---|
| 424 |  | 
|---|
| 425 | public bool Connected | 
|---|
| 426 | { | 
|---|
| 427 | get | 
|---|
| 428 | { | 
|---|
| 429 | return this.Broker.IsConnected; | 
|---|
| 430 | } | 
|---|
| 431 | } | 
|---|
| 432 |  | 
|---|
| 433 | public string UserName | 
|---|
| 434 | { | 
|---|
| 435 | get | 
|---|
| 436 | { | 
|---|
| 437 | return this.m_sUserName; | 
|---|
| 438 | } | 
|---|
| 439 | } | 
|---|
| 440 |  | 
|---|
| 441 | public string DivisionName | 
|---|
| 442 | { | 
|---|
| 443 | get | 
|---|
| 444 | { | 
|---|
| 445 | return this.m_sDivision; | 
|---|
| 446 | } | 
|---|
| 447 | } | 
|---|
| 448 |  | 
|---|
| 449 | /// <summary> | 
|---|
| 450 | /// Returns a string representation of DUZ | 
|---|
| 451 | /// </summary> | 
|---|
| 452 | public string DUZ | 
|---|
| 453 | { | 
|---|
| 454 | get | 
|---|
| 455 | { | 
|---|
| 456 | return this.NativeBroker.DUZ; | 
|---|
| 457 | } | 
|---|
| 458 | } | 
|---|
| 459 |  | 
|---|
| 460 | /// <summary> | 
|---|
| 461 | /// Sets and Returns DUZ(2) | 
|---|
| 462 | /// </summary> | 
|---|
| 463 | public string DUZ2 | 
|---|
| 464 | { | 
|---|
| 465 | get | 
|---|
| 466 | { | 
|---|
| 467 | return m_sDUZ2; | 
|---|
| 468 | } | 
|---|
| 469 | set | 
|---|
| 470 | { | 
|---|
| 471 | try | 
|---|
| 472 | { | 
|---|
| 473 | //Set DUZ(2) in M partition | 
|---|
| 474 | DataTable dt = this.RPMSDataTable("BMXSetFac^" + value, "SetDUZ2"); | 
|---|
| 475 | Debug.Assert(dt.Rows.Count == 1); | 
|---|
| 476 | DataRow dr = dt.Rows[0]; | 
|---|
| 477 | string sDUZ2 = dr["FACILITY_IEN"].ToString(); | 
|---|
| 478 | if (sDUZ2 != "0") | 
|---|
| 479 | { | 
|---|
| 480 | m_sDUZ2 = sDUZ2; | 
|---|
| 481 | this.m_sDivision = dr["FACILITY_NAME"].ToString(); | 
|---|
| 482 | } | 
|---|
| 483 | } | 
|---|
| 484 | catch (Exception ex) | 
|---|
| 485 | { | 
|---|
| 486 | Debug.Write("DUZ2.Set failed: " + ex.Message + "\n"); | 
|---|
| 487 | } | 
|---|
| 488 | } | 
|---|
| 489 | } | 
|---|
| 490 |  | 
|---|
| 491 | /// <summary> | 
|---|
| 492 | /// Gets the address of the  RPMS Server | 
|---|
| 493 | /// </summary> | 
|---|
| 494 | public string MServerAddress | 
|---|
| 495 | { | 
|---|
| 496 | get | 
|---|
| 497 | { | 
|---|
| 498 | return this.m_sServerAddress; | 
|---|
| 499 | } | 
|---|
| 500 | } | 
|---|
| 501 |  | 
|---|
| 502 | /// <summary> | 
|---|
| 503 | /// Gets the port on which the MServer is connected | 
|---|
| 504 | /// </summary> | 
|---|
| 505 | public int MServerPort | 
|---|
| 506 | { | 
|---|
| 507 | get | 
|---|
| 508 | { | 
|---|
| 509 | return this.m_nServerPort; | 
|---|
| 510 | } | 
|---|
| 511 | } | 
|---|
| 512 |  | 
|---|
| 513 | public DataTable UserDivisions | 
|---|
| 514 | { | 
|---|
| 515 | get | 
|---|
| 516 | { | 
|---|
| 517 | DataTable dt = this.GetUserDivisions(); | 
|---|
| 518 | return dt; | 
|---|
| 519 | } | 
|---|
| 520 | } | 
|---|
| 521 |  | 
|---|
| 522 | #endregion Properties | 
|---|
| 523 |  | 
|---|
| 524 | #region Methods | 
|---|
| 525 |  | 
|---|
| 526 | public void CloseConnection() | 
|---|
| 527 | { | 
|---|
| 528 | //TODO: Make thread safe | 
|---|
| 529 | this.m_bAutoServer = false; | 
|---|
| 530 | this.m_bAutoLogin = false; | 
|---|
| 531 | m_BMXBroker.CloseConnection(); | 
|---|
| 532 | } | 
|---|
| 533 |  | 
|---|
| 534 | /// <summary> | 
|---|
| 535 | /// For backwards compatibility.  Internally calls LoadConnectInfo() | 
|---|
| 536 | /// </summary> | 
|---|
| 537 | public void Login() | 
|---|
| 538 | { | 
|---|
| 539 | LoadConnectInfo(); | 
|---|
| 540 | } | 
|---|
| 541 |  | 
|---|
| 542 |  | 
|---|
| 543 |  | 
|---|
| 544 | /// <summary> | 
|---|
| 545 | /// Called to connect to an M server | 
|---|
| 546 | /// Server address, port, Access and Verify codes will be | 
|---|
| 547 | /// prompted for depending on whether these values are | 
|---|
| 548 | /// cached. | 
|---|
| 549 | /// </summary> | 
|---|
| 550 | public void LoadConnectInfo() | 
|---|
| 551 | { | 
|---|
| 552 | m_bAutoServer = true; | 
|---|
| 553 | m_bAutoLogin = true; | 
|---|
| 554 | LoadConnectInfo("",0,"",""); | 
|---|
| 555 | } | 
|---|
| 556 |  | 
|---|
| 557 | /// <summary> | 
|---|
| 558 | /// Called to connect to the M server specified by | 
|---|
| 559 | /// server address and listener port.  The default namespace on the server will be used. | 
|---|
| 560 | /// Access and Verify codes will be prompted if | 
|---|
| 561 | /// valid values for the current Windows Identity are | 
|---|
| 562 | /// not cached on the server. | 
|---|
| 563 | /// </summary> | 
|---|
| 564 | /// <param name="MServerAddress">The IP address or name of the MServer</param> | 
|---|
| 565 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param> | 
|---|
| 566 | public void LoadConnectInfo(string MServerAddress, int Port) | 
|---|
| 567 | { | 
|---|
| 568 | LoadConnectInfo(MServerAddress, Port, "", "", ""); | 
|---|
| 569 | } | 
|---|
| 570 |  | 
|---|
| 571 | /// <summary> | 
|---|
| 572 | /// Called to connect to the M server specified by | 
|---|
| 573 | /// server address, listener port and namespace. | 
|---|
| 574 | /// Access and Verify codes will be prompted if | 
|---|
| 575 | /// valid values for the current Windows Identity are | 
|---|
| 576 | /// not cached on the server. | 
|---|
| 577 | /// </summary> | 
|---|
| 578 | /// <param name="MServerAddress">The IP address or name of the MServer</param> | 
|---|
| 579 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param> | 
|---|
| 580 | /// <param name="Namespace">The namespace in which the BMXNet application will run</param> | 
|---|
| 581 | public void LoadConnectInfo(string MServerAddress, int Port, string Namespace) | 
|---|
| 582 | { | 
|---|
| 583 | m_bAutoServer = false; | 
|---|
| 584 | m_bAutoLogin = true; | 
|---|
| 585 | LoadConnectInfo(MServerAddress, Port,"","", Namespace); | 
|---|
| 586 | } | 
|---|
| 587 |  | 
|---|
| 588 | /// <summary> | 
|---|
| 589 | /// Called to connect to an M server | 
|---|
| 590 | /// using specific Access and Verify codes. | 
|---|
| 591 | /// Server address and port will be prompted if they | 
|---|
| 592 | /// are not cached in local storage. | 
|---|
| 593 | /// </summary> | 
|---|
| 594 | /// <param name="AccessCode">The user's access code</param> | 
|---|
| 595 | /// <param name="VerifyCode">The user's verify code</param> | 
|---|
| 596 | public void LoadConnectInfo(string AccessCode, string VerifyCode) | 
|---|
| 597 | { | 
|---|
| 598 | m_bAutoServer = true; | 
|---|
| 599 | m_bAutoLogin = false; | 
|---|
| 600 | LoadConnectInfo("", 0,AccessCode,VerifyCode); | 
|---|
| 601 | } | 
|---|
| 602 |  | 
|---|
| 603 | /// <summary> | 
|---|
| 604 | /// Called to connect to a specific M server | 
|---|
| 605 | /// using specific Access and Verify codes. | 
|---|
| 606 | /// </summary> | 
|---|
| 607 | /// <param name="AccessCode">The user's access code</param> | 
|---|
| 608 | /// <param name="VerifyCode">The user's verify code</param> | 
|---|
| 609 | /// <param name="MServerAddress">The IP address or name of the MServer</param> | 
|---|
| 610 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param> | 
|---|
| 611 | public void LoadConnectInfo(string MServerAddress, int Port, | 
|---|
| 612 | string AccessCode, string VerifyCode) | 
|---|
| 613 | { | 
|---|
| 614 | LoadConnectInfo(MServerAddress, Port, AccessCode, VerifyCode, ""); | 
|---|
| 615 | } | 
|---|
| 616 |  | 
|---|
| 617 | /// <summary> | 
|---|
| 618 | /// Called to connect to a specific namespace on the M server | 
|---|
| 619 | /// using specific Access and Verify codes. | 
|---|
| 620 | /// </summary> | 
|---|
| 621 | /// <param name="AccessCode">The user's access code</param> | 
|---|
| 622 | /// <param name="VerifyCode">The user's verify code</param> | 
|---|
| 623 | /// <param name="MServerAddress">The IP address or name of the MServer</param> | 
|---|
| 624 | /// <param name="Port">The port on which the BMXNet Monitor is listening</param> | 
|---|
| 625 | /// <param name="Namespace">The namespace in which the BMXNet application will run</param> | 
|---|
| 626 | public void LoadConnectInfo(string MServerAddress, int Port, | 
|---|
| 627 | string AccessCode, string VerifyCode, string Namespace) | 
|---|
| 628 | { | 
|---|
| 629 | //Throws exception if unable to connect to RPMS | 
|---|
| 630 |  | 
|---|
| 631 | /* | 
|---|
| 632 | * Get RPMS Server Address and Port from local storage. | 
|---|
| 633 | * Prompt for them if they're not there. | 
|---|
| 634 | * | 
|---|
| 635 | * Throw exception if unable to get address/port | 
|---|
| 636 | */ | 
|---|
| 637 |  | 
|---|
| 638 |  | 
|---|
| 639 | m_sServerAddress = MServerAddress; | 
|---|
| 640 | m_nServerPort = Port; | 
|---|
| 641 | m_sServerNamespace = Namespace; | 
|---|
| 642 |  | 
|---|
| 643 | /* | 
|---|
| 644 | * Connect to RPMS using current windows identity | 
|---|
| 645 | * Execute BMXNetGetCodes(NTDomain/UserName) to get encrypted AV codes | 
|---|
| 646 | * | 
|---|
| 647 | */ | 
|---|
| 648 |  | 
|---|
| 649 | this.NativeBroker.CloseConnection(); | 
|---|
| 650 | this.NativeBroker.MServerPort = m_nServerPort; | 
|---|
| 651 | this.NativeBroker.MServerNamespace = m_sServerNamespace; | 
|---|
| 652 |  | 
|---|
| 653 | string sLoginError = ""; | 
|---|
| 654 | WindowsIdentity winIdentity = WindowsIdentity.GetCurrent(); | 
|---|
| 655 | string  sIdentName = winIdentity.Name; | 
|---|
| 656 | string  sIdentType = winIdentity.AuthenticationType; | 
|---|
| 657 | bool    bIdentIsAuth = winIdentity.IsAuthenticated; | 
|---|
| 658 | bool    bRet = false; | 
|---|
| 659 | if (m_bAutoLogin == true) | 
|---|
| 660 | { | 
|---|
| 661 | try | 
|---|
| 662 | { | 
|---|
| 663 | //Attempt Auto-login using WindowsIdentity | 
|---|
| 664 |  | 
|---|
| 665 | if (bIdentIsAuth == false) | 
|---|
| 666 | { | 
|---|
| 667 | throw new BMXNetException("Current Windows User is not authenticated"); | 
|---|
| 668 | } | 
|---|
| 669 | bRet = this.NativeBroker.OpenConnection(m_sServerAddress, winIdentity); | 
|---|
| 670 |  | 
|---|
| 671 | try | 
|---|
| 672 | { | 
|---|
| 673 | string sDuz = m_BMXBroker.DUZ; | 
|---|
| 674 | int nDuz = Convert.ToInt16(sDuz); | 
|---|
| 675 | } | 
|---|
| 676 | catch (Exception exCV) | 
|---|
| 677 | { | 
|---|
| 678 | Debug.Write("OpenConnection failed: " + exCV.Message); | 
|---|
| 679 | //Debug.Assert(false); | 
|---|
| 680 | throw new Exception(exCV.Message); | 
|---|
| 681 | } | 
|---|
| 682 | } | 
|---|
| 683 | catch (Exception ex) | 
|---|
| 684 | { | 
|---|
| 685 | Debug.Write(ex.Message); | 
|---|
| 686 | sLoginError = ex.Message; | 
|---|
| 687 | } | 
|---|
| 688 | } | 
|---|
| 689 |  | 
|---|
| 690 | if (!m_BMXBroker.IsConnected) //BMXNET Login failed or m_bAutoLogin == false | 
|---|
| 691 | { | 
|---|
| 692 | try | 
|---|
| 693 | { | 
|---|
| 694 | //If autologin was attempted and | 
|---|
| 695 | //error message anything other than | 
|---|
| 696 | //"invalid AV code pair" | 
|---|
| 697 | // or "User BMXNET,APPLICATION does not have access to option BMXRPC", | 
|---|
| 698 | // or current windows user is not authenticated or is a guest | 
|---|
| 699 | //then rethrow exception. | 
|---|
| 700 | if ((m_bAutoLogin) | 
|---|
| 701 | &&(BMXNetBroker.FindSubString(sLoginError, "Not a valid ACCESS CODE/VERIFY CODE pair.") == -1) | 
|---|
| 702 | && (BMXNetBroker.FindSubString(sLoginError, "User BMXNET,APPLICATION does not have access to option BMXRPC") == -1) | 
|---|
| 703 | && (BMXNetBroker.FindSubString(sLoginError, "Not a valid Windows Identity map value.") == -1) | 
|---|
| 704 | && (BMXNetBroker.FindSubString(sLoginError, "Current Windows User is not authenticated") == -1) | 
|---|
| 705 | && (BMXNetBroker.FindSubString(sLoginError, "Windows Integrated Security Not Allowed on this port.") == -1) | 
|---|
| 706 | ) | 
|---|
| 707 | { | 
|---|
| 708 | throw new BMXNetException(sLoginError); | 
|---|
| 709 | } | 
|---|
| 710 |  | 
|---|
| 711 |  | 
|---|
| 712 | bRet = this.NativeBroker.OpenConnection(m_sServerAddress, AccessCode, VerifyCode); | 
|---|
| 713 |  | 
|---|
| 714 | //Map Windows Identity to logged-in RPMS user | 
|---|
| 715 | if (bIdentIsAuth && m_BMXBroker.IsConnected) | 
|---|
| 716 | { | 
|---|
| 717 | m_BMXBroker.AppContext = "BMXRPC"; | 
|---|
| 718 | string sRes = m_BMXBroker.TransmitRPC("BMXNetSetUser", sIdentName); | 
|---|
| 719 | Debug.Write("LoadConnectInfo BMXNetSetUser returned " + sRes + "\n"); | 
|---|
| 720 | } | 
|---|
| 721 | } | 
|---|
| 722 | catch (Exception ex) | 
|---|
| 723 | { | 
|---|
| 724 | Debug.Write(ex.Message); | 
|---|
| 725 | m_BMXBroker.CloseConnection(); | 
|---|
| 726 | throw ex; //this exception will be caught by the caller. | 
|---|
| 727 | } | 
|---|
| 728 | }//End if (m_BMXBroker.Connected == false) | 
|---|
| 729 |  | 
|---|
| 730 | try | 
|---|
| 731 | { | 
|---|
| 732 | Debug.Assert(this.Broker.IsConnected); | 
|---|
| 733 | m_BMXBroker.AppContext = "BMXRPC"; | 
|---|
| 734 | string sRpc = "BMX USER"; | 
|---|
| 735 | Debug.Assert(m_BMXBroker.AppContext == "BMXRPC"); | 
|---|
| 736 |  | 
|---|
| 737 | bool bCtxt = false; | 
|---|
| 738 | int nCtxt = 0; | 
|---|
| 739 | do | 
|---|
| 740 | { | 
|---|
| 741 | try | 
|---|
| 742 | { | 
|---|
| 743 | m_sUserName = m_BMXBroker.TransmitRPC(sRpc, this.DUZ); | 
|---|
| 744 | bCtxt = true; | 
|---|
| 745 | Debug.Write("BMXNet::LoadConnectInfo succeeded.\n"); | 
|---|
| 746 | } | 
|---|
| 747 | catch (Exception ex) | 
|---|
| 748 | { | 
|---|
| 749 | Debug.Write("BMXNet::LoadConnectInfo retrying: " + ex.Message + "\n"); | 
|---|
| 750 | m_BMXBroker.AppContext = "BMXRPC"; | 
|---|
| 751 | nCtxt++; | 
|---|
| 752 | if (nCtxt > 4) | 
|---|
| 753 | throw ex; | 
|---|
| 754 | } | 
|---|
| 755 | }while (bCtxt == false); | 
|---|
| 756 |  | 
|---|
| 757 |  | 
|---|
| 758 | System.Data.DataTable rsDivisions; | 
|---|
| 759 | rsDivisions =  this.GetUserDivisions(); | 
|---|
| 760 | m_nDivisionCount = rsDivisions.Rows.Count; | 
|---|
| 761 |  | 
|---|
| 762 | //The MOST_RECENT_LOOKUP field contains DUZ(2) | 
|---|
| 763 | foreach (System.Data.DataRow r in rsDivisions.Rows) | 
|---|
| 764 | { | 
|---|
| 765 | string sTemp = r["MOST_RECENT_LOOKUP"].ToString(); | 
|---|
| 766 | if ((sTemp == "1") || (rsDivisions.Rows.Count == 1)) | 
|---|
| 767 | { | 
|---|
| 768 | this.m_sDivision = r["FACILITY_NAME"].ToString(); | 
|---|
| 769 | this.m_sDUZ2 = r["FACILITY_IEN"].ToString(); | 
|---|
| 770 | break; | 
|---|
| 771 | } | 
|---|
| 772 | } | 
|---|
| 773 | } | 
|---|
| 774 | catch(Exception bmxEx) | 
|---|
| 775 | { | 
|---|
| 776 | m_BMXBroker.CloseConnection(); | 
|---|
| 777 | string sMessage =  bmxEx.Message + bmxEx.StackTrace; | 
|---|
| 778 | throw new BMXNetException(sMessage); | 
|---|
| 779 | } | 
|---|
| 780 | return; | 
|---|
| 781 | } | 
|---|
| 782 |  | 
|---|
| 783 | private DataTable GetUserDivisions() | 
|---|
| 784 | { | 
|---|
| 785 | try | 
|---|
| 786 | { | 
|---|
| 787 | DataTable tb = this.RPMSDataTable("BMXGetFacRS^" + this.DUZ, "DivisionTable"); | 
|---|
| 788 | return tb; | 
|---|
| 789 | } | 
|---|
| 790 | catch (Exception bmxEx) | 
|---|
| 791 | { | 
|---|
| 792 | string sMessage =  bmxEx.Message + bmxEx.StackTrace; | 
|---|
| 793 | throw new BMXNetException(sMessage); | 
|---|
| 794 |  | 
|---|
| 795 | } | 
|---|
| 796 | } | 
|---|
| 797 |  | 
|---|
| 798 |  | 
|---|
| 799 |  | 
|---|
| 800 | public string GetDSN(string sAppContext) | 
|---|
| 801 | { | 
|---|
| 802 | string sDsn = "Data source="; | 
|---|
| 803 | if (sAppContext == "") | 
|---|
| 804 | sAppContext = "BMXRPC"; | 
|---|
| 805 |  | 
|---|
| 806 | if (!m_BMXBroker.IsConnected) | 
|---|
| 807 | return sDsn.ToString(); | 
|---|
| 808 |  | 
|---|
| 809 | sDsn += this.m_sServerAddress ; | 
|---|
| 810 | sDsn += ";Location="; | 
|---|
| 811 | sDsn += this.m_nServerPort.ToString(); | 
|---|
| 812 | sDsn += ";Extended Properties="; | 
|---|
| 813 | sDsn += sAppContext; | 
|---|
| 814 |  | 
|---|
| 815 | return sDsn; | 
|---|
| 816 | } | 
|---|
| 817 |  | 
|---|
| 818 |  | 
|---|
| 819 | public bool Lock(string sVariable, string sIncrement, string sTimeOut) | 
|---|
| 820 | { | 
|---|
| 821 | bool                    bRet = false; | 
|---|
| 822 | string                  sErrorMessage = ""; | 
|---|
| 823 |  | 
|---|
| 824 | if (!this.Broker.IsConnected) | 
|---|
| 825 | { | 
|---|
| 826 | return bRet; | 
|---|
| 827 | } | 
|---|
| 828 | try | 
|---|
| 829 | { | 
|---|
| 830 | bRet = this.NativeBroker.Lock(sVariable, sIncrement, sTimeOut); | 
|---|
| 831 | return bRet; | 
|---|
| 832 | } | 
|---|
| 833 | catch(Exception ex) | 
|---|
| 834 | { | 
|---|
| 835 | sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message; | 
|---|
| 836 | throw ex; | 
|---|
| 837 | } | 
|---|
| 838 | } | 
|---|
| 839 |  | 
|---|
| 840 | delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName); | 
|---|
| 841 | delegate DataTable RPMSDataTableDelegate2(string CommandString, string TableName, DataSet dsDataSet); | 
|---|
| 842 |  | 
|---|
| 843 | /// <summary> | 
|---|
| 844 | /// Creates and names a DataTable using the command in CommandString | 
|---|
| 845 | /// and the name in TableName. | 
|---|
| 846 | /// </summary> | 
|---|
| 847 | /// <param name="CommandString"> The SQL or RPC call</param> | 
|---|
| 848 | /// <param name="TableName">The name of the resulting table</param> | 
|---|
| 849 | /// <returns> | 
|---|
| 850 | /// Returns the resulting DataTable. | 
|---|
| 851 | /// </returns> | 
|---|
| 852 | public DataTable RPMSDataTable(string CommandString, string TableName) | 
|---|
| 853 | { | 
|---|
| 854 | return this.RPMSDataTable(CommandString, TableName, null); | 
|---|
| 855 | } | 
|---|
| 856 |  | 
|---|
| 857 | /// <summary> | 
|---|
| 858 | /// Creates and names a DataTable using the command in CommandString | 
|---|
| 859 | /// and the name in TableName then adds it to DataSet. | 
|---|
| 860 | /// </summary> | 
|---|
| 861 | /// <param name="CommandString">The SQL or RPC call</param> | 
|---|
| 862 | /// <param name="TableName">The name of the resulting table</param> | 
|---|
| 863 | /// <param name="dsDataSet">The dataset in which to place the table</param> | 
|---|
| 864 | /// <returns> | 
|---|
| 865 | /// Returns the resulting DataTable. | 
|---|
| 866 | /// </returns> | 
|---|
| 867 | public DataTable RPMSDataTable(string CommandString, string TableName, DataSet dsDataSet) | 
|---|
| 868 | { | 
|---|
| 869 | //Retrieves a recordset from RPMS | 
|---|
| 870 | //Debug.Assert(this.InvokeRequired == false); | 
|---|
| 871 | string                  sErrorMessage = ""; | 
|---|
| 872 | DataTable               dtResult = new DataTable(TableName); | 
|---|
| 873 |  | 
|---|
| 874 | if (!this.Broker.IsConnected) | 
|---|
| 875 | return dtResult; | 
|---|
| 876 |  | 
|---|
| 877 | try | 
|---|
| 878 | { | 
|---|
| 879 | BMXNetConnection rpmsConn = new BMXNetConnection(m_BMXBroker); | 
|---|
| 880 | BMXNetCommand cmd = (BMXNetCommand) rpmsConn.CreateCommand(); | 
|---|
| 881 | BMXNetDataAdapter da = new BMXNetDataAdapter(); | 
|---|
| 882 |  | 
|---|
| 883 | cmd.CommandText = CommandString; | 
|---|
| 884 | da.SelectCommand = cmd; | 
|---|
| 885 | if (dsDataSet == null) | 
|---|
| 886 | { | 
|---|
| 887 | da.Fill(dtResult); | 
|---|
| 888 | } | 
|---|
| 889 | else | 
|---|
| 890 | { | 
|---|
| 891 | da.Fill(dsDataSet, TableName); | 
|---|
| 892 | dtResult = dsDataSet.Tables[TableName]; | 
|---|
| 893 | } | 
|---|
| 894 | Debug.Write(dtResult.TableName + " DataTable retrieved\n"); | 
|---|
| 895 | return dtResult; | 
|---|
| 896 | } | 
|---|
| 897 | catch (Exception ex) | 
|---|
| 898 | { | 
|---|
| 899 | sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message; | 
|---|
| 900 | throw ex; | 
|---|
| 901 | } | 
|---|
| 902 | } | 
|---|
| 903 |  | 
|---|
| 904 | public int RPMSDataTableAsyncQue(string CommandString, string EventName) | 
|---|
| 905 | { | 
|---|
| 906 | try | 
|---|
| 907 | { | 
|---|
| 908 | string sCommand = "BMX ASYNC QUEUE^"; | 
|---|
| 909 | //replace ^'s in CommandString with $c(30)'s | 
|---|
| 910 | char[] cDelim = new char[1]; | 
|---|
| 911 | cDelim[0] = (char) 30; | 
|---|
| 912 | string sDelim = cDelim[0].ToString(); | 
|---|
| 913 | CommandString = CommandString.Replace("^", sDelim); | 
|---|
| 914 | sCommand = sCommand + CommandString + "^" + EventName; | 
|---|
| 915 |  | 
|---|
| 916 | DataTable dt = new DataTable(); | 
|---|
| 917 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); | 
|---|
| 918 | if (this.IsHandleCreated == false) | 
|---|
| 919 | { | 
|---|
| 920 | this.CreateHandle(); | 
|---|
| 921 | } | 
|---|
| 922 |  | 
|---|
| 923 | dt = (DataTable) this.Invoke(rdtd, new object[] {sCommand, "Que"}); | 
|---|
| 924 |  | 
|---|
| 925 | DataRow dr = dt.Rows[0]; | 
|---|
| 926 | int nErrorID = Convert.ToInt32(dr["ERRORID"]); | 
|---|
| 927 | int nParam = Convert.ToInt32(dr["PARAM"]); | 
|---|
| 928 |  | 
|---|
| 929 | if (nErrorID == 0) | 
|---|
| 930 | { | 
|---|
| 931 | return 0; | 
|---|
| 932 | } | 
|---|
| 933 | else | 
|---|
| 934 | { | 
|---|
| 935 | return nParam; | 
|---|
| 936 | } | 
|---|
| 937 | } | 
|---|
| 938 | catch (Exception ex) | 
|---|
| 939 | { | 
|---|
| 940 | Debug.Write("RPMSDataTableAsyncQue  error: " + ex.Message + "\n"); | 
|---|
| 941 | throw ex; | 
|---|
| 942 | } | 
|---|
| 943 | } | 
|---|
| 944 |  | 
|---|
| 945 | public DataTable RPMSDataTableAsyncGet(string AsyncInfo, string TableName) | 
|---|
| 946 | { | 
|---|
| 947 | return RPMSDataTableAsyncGet(AsyncInfo, TableName, null); | 
|---|
| 948 | } | 
|---|
| 949 |  | 
|---|
| 950 | public DataTable RPMSDataTableAsyncGet(string AsyncInfo, string TableName, DataSet dsDataSet) | 
|---|
| 951 | { | 
|---|
| 952 | try | 
|---|
| 953 | { | 
|---|
| 954 | string sCommand = "BMX ASYNC GET^" + AsyncInfo; | 
|---|
| 955 |  | 
|---|
| 956 | DataTable dt; | 
|---|
| 957 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RPMSDataTable); | 
|---|
| 958 | RPMSDataTableDelegate2 rdtd2 = new RPMSDataTableDelegate2(RPMSDataTable); | 
|---|
| 959 | if (this.IsHandleCreated == false) | 
|---|
| 960 | { | 
|---|
| 961 | this.CreateHandle(); | 
|---|
| 962 | } | 
|---|
| 963 |  | 
|---|
| 964 | if (dsDataSet == null) | 
|---|
| 965 | { | 
|---|
| 966 | dt = (DataTable) this.Invoke(rdtd, new object[] {sCommand, TableName}); | 
|---|
| 967 | } | 
|---|
| 968 | else | 
|---|
| 969 | { | 
|---|
| 970 | dt = (DataTable) this.Invoke(rdtd2, new object[] {sCommand, TableName, dsDataSet}); | 
|---|
| 971 | } | 
|---|
| 972 | return dt; | 
|---|
| 973 | } | 
|---|
| 974 | catch (Exception ex) | 
|---|
| 975 | { | 
|---|
| 976 | Debug.Write("RPMSDataTableAsyncGet error: " + ex.Message + "\n"); | 
|---|
| 977 | throw ex; | 
|---|
| 978 | } | 
|---|
| 979 | } | 
|---|
| 980 |  | 
|---|
| 981 | #endregion Methods | 
|---|
| 982 |  | 
|---|
| 983 | #region Local Storage | 
|---|
| 984 | /* | 
|---|
| 985 | public void ChangeServerInfo() | 
|---|
| 986 | { | 
|---|
| 987 | //Get existing values from isolated storage | 
|---|
| 988 | ServerData serverData = new ServerData(); | 
|---|
| 989 | Stream stStorage = null; | 
|---|
| 990 | try | 
|---|
| 991 | { | 
|---|
| 992 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); | 
|---|
| 993 | string sFileName = "mserver0200.dat"; | 
|---|
| 994 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Open, isStore); | 
|---|
| 995 | IFormatter formatter = new SoapFormatter(); | 
|---|
| 996 | serverData = (ServerData)formatter.Deserialize(stStorage); | 
|---|
| 997 | stStorage.Close(); | 
|---|
| 998 | } | 
|---|
| 999 | catch (Exception ex) | 
|---|
| 1000 | { | 
|---|
| 1001 | Debug.Write(ex.Message); | 
|---|
| 1002 | if (stStorage != null) | 
|---|
| 1003 | stStorage.Close(); | 
|---|
| 1004 | } | 
|---|
| 1005 |  | 
|---|
| 1006 | try | 
|---|
| 1007 | { | 
|---|
| 1008 | hDServerInfo dsi = new DServerInfo(); | 
|---|
| 1009 | dsi.InitializePage(serverData.m_sAddress, serverData.m_nPort, serverData.m_sNamespace); | 
|---|
| 1010 | if (dsi.ShowDialog() != DialogResult.OK) | 
|---|
| 1011 | { | 
|---|
| 1012 | throw new BMXNetException("User cancelled."); | 
|---|
| 1013 | } | 
|---|
| 1014 | serverData.m_sAddress = dsi.MServerAddress; | 
|---|
| 1015 | serverData.m_nPort = dsi.MServerPort; | 
|---|
| 1016 | serverData.m_sNamespace = dsi.MServerNamespace; | 
|---|
| 1017 |  | 
|---|
| 1018 | this.m_sServerAddress = dsi.MServerAddress; | 
|---|
| 1019 | this.m_nServerPort = dsi.MServerPort; | 
|---|
| 1020 | this.m_sServerNamespace = dsi.MServerNamespace; | 
|---|
| 1021 |  | 
|---|
| 1022 | //Save port and address to isolated storage | 
|---|
| 1023 | try | 
|---|
| 1024 | { | 
|---|
| 1025 | string sFileName = "mserver0200.dat"; | 
|---|
| 1026 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); | 
|---|
| 1027 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Create, isStore); | 
|---|
| 1028 | IFormatter formatter = new SoapFormatter(); | 
|---|
| 1029 | formatter.Serialize(stStorage, serverData); | 
|---|
| 1030 | stStorage.Close(); | 
|---|
| 1031 | } | 
|---|
| 1032 | catch (Exception ex) | 
|---|
| 1033 | { | 
|---|
| 1034 | Debug.Write(ex.Message); | 
|---|
| 1035 | if (stStorage != null) | 
|---|
| 1036 | stStorage.Close(); | 
|---|
| 1037 | } | 
|---|
| 1038 |  | 
|---|
| 1039 | } | 
|---|
| 1040 | catch (Exception ex) | 
|---|
| 1041 | { | 
|---|
| 1042 | Debug.Write(ex.Message); | 
|---|
| 1043 | if (stStorage != null) | 
|---|
| 1044 | stStorage.Close(); | 
|---|
| 1045 | if (ex.Message == "User cancelled.") | 
|---|
| 1046 | { | 
|---|
| 1047 | throw ex; | 
|---|
| 1048 | } | 
|---|
| 1049 | } | 
|---|
| 1050 |  | 
|---|
| 1051 | } | 
|---|
| 1052 | */ | 
|---|
| 1053 |  | 
|---|
| 1054 |  | 
|---|
| 1055 | /* | 
|---|
| 1056 | private void GetServerInfo(ref int nPort, ref string sAddress, ref string sNamespace) | 
|---|
| 1057 | { | 
|---|
| 1058 | //Get values from isolated storage | 
|---|
| 1059 | bool bLoaded = false; | 
|---|
| 1060 | Stream stStorage = null; | 
|---|
| 1061 | try | 
|---|
| 1062 | { | 
|---|
| 1063 | m_ServerData = new ServerData(); | 
|---|
| 1064 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); | 
|---|
| 1065 | string sFileName = "mserver0200.dat"; | 
|---|
| 1066 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Open, isStore); | 
|---|
| 1067 | IFormatter formatter = new SoapFormatter(); | 
|---|
| 1068 | m_ServerData = (ServerData)formatter.Deserialize(stStorage); | 
|---|
| 1069 | stStorage.Close(); | 
|---|
| 1070 | sAddress = m_ServerData.m_sAddress; | 
|---|
| 1071 | nPort = m_ServerData.m_nPort; | 
|---|
| 1072 | sNamespace = m_ServerData.m_sNamespace; | 
|---|
| 1073 |  | 
|---|
| 1074 | bLoaded = true; | 
|---|
| 1075 | return; | 
|---|
| 1076 | } | 
|---|
| 1077 | catch (Exception ex) | 
|---|
| 1078 | { | 
|---|
| 1079 | Debug.Write(ex.Message); | 
|---|
| 1080 | if (stStorage != null) | 
|---|
| 1081 | stStorage.Close(); | 
|---|
| 1082 | } | 
|---|
| 1083 | try | 
|---|
| 1084 | { | 
|---|
| 1085 | //If unable to deserialize, display dialog to collect values | 
|---|
| 1086 | if (bLoaded == false) | 
|---|
| 1087 | { | 
|---|
| 1088 | DServerInfo dsi = new DServerInfo(); | 
|---|
| 1089 | dsi.InitializePage("", 10501, ""); | 
|---|
| 1090 | if (dsi.ShowDialog() != DialogResult.OK) | 
|---|
| 1091 | { | 
|---|
| 1092 | throw new BMXNetException("Unable to get M Server information"); | 
|---|
| 1093 | } | 
|---|
| 1094 | m_ServerData.m_sAddress = dsi.MServerAddress; | 
|---|
| 1095 | m_ServerData.m_nPort = dsi.MServerPort; | 
|---|
| 1096 | m_ServerData.m_sNamespace = dsi.MServerNamespace; | 
|---|
| 1097 | } | 
|---|
| 1098 |  | 
|---|
| 1099 | sAddress = m_ServerData.m_sAddress; | 
|---|
| 1100 | nPort = m_ServerData.m_nPort; | 
|---|
| 1101 | sNamespace = m_ServerData.m_sNamespace; | 
|---|
| 1102 |  | 
|---|
| 1103 | //Save port and address to isolated storage | 
|---|
| 1104 | try | 
|---|
| 1105 | { | 
|---|
| 1106 | string sFileName = "mserver0200.dat"; | 
|---|
| 1107 | IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForAssembly(); | 
|---|
| 1108 | stStorage = new IsolatedStorageFileStream(sFileName, FileMode.Create, isStore); | 
|---|
| 1109 | IFormatter formatter = new SoapFormatter(); | 
|---|
| 1110 | formatter.Serialize(stStorage, m_ServerData); | 
|---|
| 1111 | stStorage.Close(); | 
|---|
| 1112 | } | 
|---|
| 1113 | catch (Exception ex) | 
|---|
| 1114 | { | 
|---|
| 1115 | Debug.Write(ex.Message); | 
|---|
| 1116 | if (stStorage != null) | 
|---|
| 1117 | stStorage.Close(); | 
|---|
| 1118 | } | 
|---|
| 1119 |  | 
|---|
| 1120 | return; | 
|---|
| 1121 | } | 
|---|
| 1122 | catch (Exception ex) | 
|---|
| 1123 | { | 
|---|
| 1124 | Debug.Write(ex.Message); | 
|---|
| 1125 | if (stStorage != null) | 
|---|
| 1126 | stStorage.Close(); | 
|---|
| 1127 | throw ex; | 
|---|
| 1128 | } | 
|---|
| 1129 |  | 
|---|
| 1130 | }*/ | 
|---|
| 1131 |  | 
|---|
| 1132 |  | 
|---|
| 1133 |  | 
|---|
| 1134 | #endregion | 
|---|
| 1135 |  | 
|---|
| 1136 | } | 
|---|
| 1137 | } | 
|---|
| 1138 |  | 
|---|