FUSIONVir.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using Wayne.Lib;
  4. using Wayne.ForecourtControl.Fusion;
  5. #if _SINP
  6. using Wayne.ForecourtControl.Nfs;
  7. #endif
  8. namespace Wayne.ForecourtControl.Vir.Fusion
  9. {
  10. internal class FUSIONVirId: IVirId
  11. {
  12. // Fields
  13. private int deviceId;
  14. private string virId;
  15. // Methods
  16. public FUSIONVirId(int deviceId, string virId)
  17. {
  18. this.deviceId = deviceId;
  19. this.virId = virId;
  20. }
  21. public string Id
  22. {
  23. get { return virId; }
  24. }
  25. }
  26. internal class FUSIONVir : IVir //, IDisposable
  27. {
  28. // Fields
  29. private int id;
  30. List<IVirId> virIdList;
  31. public FUSIONManager manager;
  32. // Events
  33. public event EventHandler<VIRStateChangedEventArgs> OnVirIdStateChange;
  34. // Methods
  35. public FUSIONVir(int fcId, int id)
  36. {
  37. //Trace.Add(this);
  38. if (!FUSIONFactory.fusionForecourtControlList.ContainsKey(fcId))
  39. {
  40. Trace.WriteLine(string.Format("fusionForecourtControl id={0} NOT exist - creating", fcId));
  41. Wayne.ForecourtControl.Fusion.FUSIONFactory.CreateForecourtControl(fcId);
  42. }
  43. if (FUSIONFactory.fusionForecourtControlList.ContainsKey(fcId))
  44. {
  45. Trace.WriteLine(string.Format("fusionForecourtControl id={0} adding event OnConnectionStateChange", fcId));
  46. manager = ((FUSIONForecourtControl)(FUSIONFactory.fusionForecourtControlList[fcId])).manager;
  47. //this.manager.ifsfManager.clientSocket.OnConnectionStateChange += new EventHandler<ConnectionChangedEventArgs>(clientSocket_OnConnectionStateChange); //new EventHandler<ConnectionChangedEventArgs>(this, (IntPtr)this.clientSocket_OnConnectionStateChange);
  48. }
  49. else
  50. Trace.WriteLine(string.Format("fusionForecourtControl id={0} NOT exist - error!!!", fcId));
  51. this.id = id;
  52. this.virIdList = new List<IVirId>();
  53. if (manager != null)
  54. manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_Vir, id, null, null, null);
  55. }
  56. // Properties
  57. public int Id
  58. {
  59. get
  60. {
  61. return this.id;
  62. }
  63. }
  64. public System.Collections.ObjectModel.ReadOnlyCollection<IVirId> VirIds
  65. {
  66. get { return virIdList.AsReadOnly(); }
  67. }
  68. //public void Dispose()
  69. //{
  70. // foreach (FUSIONVirId virId in this.virIdList)
  71. // {
  72. // virId.Dispose();
  73. // }
  74. //}
  75. public FUSIONVirId getVirId(string virId)
  76. {
  77. foreach (FUSIONVirId virIdElem in virIdList)
  78. {
  79. if (virIdElem.Id == virId)
  80. return virIdElem;
  81. }
  82. return null;
  83. }
  84. public DeviceConnectionState State(string virId)
  85. {
  86. FUSIONVirId virIdElem = getVirId(virId);
  87. if (virIdElem != null)
  88. {
  89. return DeviceConnectionState.Connected;
  90. }
  91. return DeviceConnectionState.Disconnected;
  92. }
  93. public void Connected(string virId)
  94. {
  95. FUSIONVirId virIdElem = getVirId(virId);
  96. if (virIdElem == null)
  97. {
  98. this.virIdList.Add(new FUSIONVirId(this.Id, virId));
  99. if (this.OnVirIdStateChange != null)
  100. {
  101. this.OnVirIdStateChange.BeginInvoke(this, new VIRStateChangedEventArgs(this.Id, virId, DeviceConnectionState.Connected), null, null);
  102. }
  103. Trace.WriteLine(string.Format("Connected: virId={0} added", virId));
  104. }
  105. else
  106. Trace.WriteLine(string.Format("Connected: virId={0} already connected", virId));
  107. }
  108. public void Disconnected(string virId)
  109. {
  110. FUSIONVirId virIdElem = getVirId(virId);
  111. if (virIdElem != null)
  112. {
  113. this.virIdList.Remove(virIdElem);
  114. if (this.OnVirIdStateChange != null)
  115. {
  116. this.OnVirIdStateChange.BeginInvoke(this, new VIRStateChangedEventArgs(this.Id, virId, DeviceConnectionState.Disconnected), null, null);
  117. }
  118. Trace.WriteLine(string.Format("Disconnected: virId={0} removed", virId));
  119. }
  120. else
  121. Trace.WriteLine(string.Format("Disconnected: virId={0} not found!", virId));
  122. }
  123. }
  124. }