FUSIONTwin.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using Wayne.Lib;
  3. #if _SINP
  4. using Wayne.ForecourtControl.Nfs;
  5. #endif
  6. namespace Wayne.ForecourtControl.Fusion
  7. {
  8. /// <summary>
  9. /// </summary>
  10. public interface ITwin
  11. {
  12. /// <summary>
  13. /// Opens or closes the station.
  14. /// </summary>
  15. /// <param name="userToken">A user supplied object that will be returned in the requestCompleted callback</param>
  16. void OpenMasterAsync(EventHandler<Wayne.Lib.AsyncCompletedEventArgs> requestCompleted, object userToken);
  17. event EventHandler OnMasterReady;
  18. }
  19. public static class FUSIONTwinFactory
  20. {
  21. private static FUSIONTwin twin = null;
  22. public static ITwin CreateTwin(int deviceId)
  23. {
  24. twin = new FUSIONTwin(deviceId);
  25. return twin;
  26. }
  27. public static ITwin getTwin()
  28. { return twin; }
  29. }
  30. internal class FUSIONTwin: ITwin
  31. {
  32. private FUSIONForecourtControl forecourtControl;
  33. public FUSIONTwin(int deviceId)
  34. {
  35. if (FUSIONFactory.fusionForecourtControlList.ContainsKey(deviceId))
  36. this.forecourtControl = (FUSIONForecourtControl)(FUSIONFactory.fusionForecourtControlList[deviceId]);
  37. }
  38. public event EventHandler OnMasterReady;
  39. internal void FireOnTwinMasterReady()
  40. {
  41. try
  42. {
  43. if (this.OnMasterReady != null)
  44. {
  45. Trace.WriteLine("init FireOnTwinMasterReady");
  46. this.OnMasterReady(this, EventArgs.Empty);
  47. Trace.WriteLine("end FireOnTwinMasterReady");
  48. }
  49. else
  50. Trace.WriteLine("FireOnTwinMasterReady - OnMasterReady is null");
  51. }
  52. catch(Exception ex)
  53. {
  54. Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
  55. }
  56. }
  57. public void OpenMasterAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  58. {
  59. this.forecourtControl.manager.ifsfManager.TwinOpenMaster(requestCompleted, userToken, this);
  60. }
  61. }
  62. }