FUSIONFactory.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. //using System.Diagnostics;
  4. #if _SINP
  5. using Wayne.ForecourtControl.Nfs;
  6. #endif
  7. //using Wayne.Softseal;
  8. //--using DWItaly.Sinp.Utility;
  9. namespace Wayne.ForecourtControl.Fusion
  10. {
  11. public static class FUSIONFactory
  12. {
  13. //public static SINPFileTrace tracer = null;
  14. //public static IForecourtControl fusionForecourtControl = null;
  15. public static Dictionary<int, IForecourtControl> fusionForecourtControlList = new Dictionary<int, IForecourtControl>();
  16. // Methods
  17. public static IForecourtControl CreateForecourtControl(int deviceId)
  18. {
  19. IForecourtControl fusionForecourtControl = CreateFUSIONForecourtControlLocal(deviceId, ForecourtEntityTypes.All, null);
  20. return fusionForecourtControl;
  21. }
  22. public static IForecourtControl CreateForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes)
  23. {
  24. IForecourtControl fusionForecourtControl = CreateFUSIONForecourtControlLocal(deviceId, managedEntityTypes, null);
  25. return fusionForecourtControl;
  26. }
  27. public static IForecourtControl CreateForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
  28. {
  29. IForecourtControl fusionForecourtControl = CreateFUSIONForecourtControlLocal(deviceId, managedEntityTypes, managedPumpIds);
  30. return fusionForecourtControl;
  31. }
  32. private static IForecourtControl CreateFUSIONForecourtControlLocal(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
  33. {
  34. //if (tracer == null)
  35. //{
  36. // tracer = new SINPFileTrace("ForecourtServer.ini", "Trace", "FControlFUSION");
  37. // Trace.Listeners.Add(tracer);
  38. //}
  39. IForecourtControl fusionForecourtControl = null;
  40. byte[] validationInfo = null;
  41. if (!fusionForecourtControlList.ContainsKey(deviceId))
  42. {
  43. try
  44. {
  45. string softsealAssembly = ConfigurationParams.getSINPPath("bin\\") + "fusionSoftseal.dll";
  46. System.Reflection.Assembly assembly = null;
  47. Trace.WriteLine(string.Format("softsealAssembly: '{0}'", softsealAssembly));
  48. if (System.IO.File.Exists(softsealAssembly))
  49. assembly = System.Reflection.Assembly.LoadFrom(softsealAssembly);
  50. if (assembly == null)
  51. {
  52. softsealAssembly = ConfigurationParams.getSINPPath("") + "fusionSoftseal.dll";
  53. Trace.WriteLine(string.Format("NOT FOUND ... try softsealAssembly: '{0}'", softsealAssembly));
  54. if (System.IO.File.Exists(softsealAssembly))
  55. assembly = System.Reflection.Assembly.LoadFrom(softsealAssembly);
  56. }
  57. if (assembly != null)
  58. {
  59. Trace.WriteLine(string.Format("FOUND softsealAssembly: '{0}'", softsealAssembly));
  60. Type fusionSoftsealType = assembly.GetType("Wayne.Softseal.FusionSoftseal");
  61. Object fusionSoftsealObject = Activator.CreateInstance(fusionSoftsealType);
  62. object retVal;
  63. System.Reflection.MethodInfo mtdValidate = fusionSoftsealType.GetMethod("Validate");
  64. retVal = mtdValidate.Invoke(fusionSoftsealObject, null);
  65. validationInfo = (byte[])retVal;
  66. }
  67. else
  68. Trace.WriteLine(string.Format("NOT FOUND ! softsealAssembly: '{0}'", softsealAssembly));
  69. //IFusionSoftseal fusionSoftseal = Wayne.Softseal.FusionSoftseal.CreateFusionSoftseal();
  70. //validationInfo = fusionSoftseal.Validate();
  71. //if (validationInfo != null)
  72. {
  73. fusionForecourtControl = new FUSIONForecourtControl(deviceId, managedEntityTypes, managedPumpIds);
  74. FUSIONFactory.fusionForecourtControlList.Add(deviceId, fusionForecourtControl);
  75. Trace.WriteLine(string.Format("FUSIONForecourtControl created"));
  76. //((FUSIONForecourtControl)fusionForecourtControl).validationInfo = validationString;
  77. ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.LogOnAddValidationInfo(validationInfo);
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. Trace.WriteLine(string.Format("Errore: {0}", ex.Message));
  83. }
  84. }
  85. else
  86. fusionForecourtControl = fusionForecourtControlList[deviceId];
  87. return fusionForecourtControl;
  88. }
  89. public static string getFUSIONFwRelease(int deviceId, string sConnectionString)
  90. {
  91. string sFwRelease = "";
  92. // fwRelease string is composed by: version.release.hotfix
  93. IForecourtControl fusionForecourtControl = null;
  94. fusionForecourtControl = CreateForecourtControl(deviceId);
  95. if (((FUSIONForecourtControl)fusionForecourtControl).manager.Connect(sConnectionString))
  96. {
  97. ((FUSIONForecourtControl)fusionForecourtControl).manager.versionInfoWakeUpEvent.Reset();
  98. ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.VersionInfo(null, null, null);
  99. ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.GetCountrySettings(null, null, null);
  100. ((FUSIONForecourtControl)fusionForecourtControl).manager.versionInfoWakeUpEvent.WaitOne();
  101. sFwRelease = ((FUSIONForecourtControl)fusionForecourtControl).manager.getFwRelease();
  102. }
  103. return sFwRelease;
  104. }
  105. public static bool LogOnValidationInfo(int deviceId, byte[] validationInfo)
  106. {
  107. IForecourtControl fusionForecourtControl = null;
  108. fusionForecourtControl = CreateForecourtControl(deviceId);
  109. if ((FUSIONForecourtControl)fusionForecourtControl == null)
  110. return false;
  111. ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.LogOnAddValidationInfo(validationInfo);
  112. return true;
  113. }
  114. }
  115. }