123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- //using System.Diagnostics;
- #if _SINP
- using Wayne.ForecourtControl.Nfs;
- #endif
- //using Wayne.Softseal;
- //--using DWItaly.Sinp.Utility;
- namespace Wayne.ForecourtControl.Fusion
- {
- public static class FUSIONFactory
- {
- //public static SINPFileTrace tracer = null;
- //public static IForecourtControl fusionForecourtControl = null;
- public static Dictionary<int, IForecourtControl> fusionForecourtControlList = new Dictionary<int, IForecourtControl>();
- // Methods
- public static IForecourtControl CreateForecourtControl(int deviceId)
- {
- IForecourtControl fusionForecourtControl = CreateFUSIONForecourtControlLocal(deviceId, ForecourtEntityTypes.All, null);
- return fusionForecourtControl;
- }
- public static IForecourtControl CreateForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes)
- {
- IForecourtControl fusionForecourtControl = CreateFUSIONForecourtControlLocal(deviceId, managedEntityTypes, null);
- return fusionForecourtControl;
- }
- public static IForecourtControl CreateForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
- {
- IForecourtControl fusionForecourtControl = CreateFUSIONForecourtControlLocal(deviceId, managedEntityTypes, managedPumpIds);
- return fusionForecourtControl;
- }
- private static IForecourtControl CreateFUSIONForecourtControlLocal(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
- {
- //if (tracer == null)
- //{
- // tracer = new SINPFileTrace("ForecourtServer.ini", "Trace", "FControlFUSION");
- // Trace.Listeners.Add(tracer);
- //}
- IForecourtControl fusionForecourtControl = null;
- byte[] validationInfo = null;
- if (!fusionForecourtControlList.ContainsKey(deviceId))
- {
- try
- {
- string softsealAssembly = ConfigurationParams.getSINPPath("bin\\") + "fusionSoftseal.dll";
- System.Reflection.Assembly assembly = null;
- Trace.WriteLine(string.Format("softsealAssembly: '{0}'", softsealAssembly));
- if (System.IO.File.Exists(softsealAssembly))
- assembly = System.Reflection.Assembly.LoadFrom(softsealAssembly);
- if (assembly == null)
- {
- softsealAssembly = ConfigurationParams.getSINPPath("") + "fusionSoftseal.dll";
- Trace.WriteLine(string.Format("NOT FOUND ... try softsealAssembly: '{0}'", softsealAssembly));
- if (System.IO.File.Exists(softsealAssembly))
- assembly = System.Reflection.Assembly.LoadFrom(softsealAssembly);
- }
- if (assembly != null)
- {
- Trace.WriteLine(string.Format("FOUND softsealAssembly: '{0}'", softsealAssembly));
- Type fusionSoftsealType = assembly.GetType("Wayne.Softseal.FusionSoftseal");
- Object fusionSoftsealObject = Activator.CreateInstance(fusionSoftsealType);
- object retVal;
- System.Reflection.MethodInfo mtdValidate = fusionSoftsealType.GetMethod("Validate");
- retVal = mtdValidate.Invoke(fusionSoftsealObject, null);
- validationInfo = (byte[])retVal;
- }
- else
- Trace.WriteLine(string.Format("NOT FOUND ! softsealAssembly: '{0}'", softsealAssembly));
- //IFusionSoftseal fusionSoftseal = Wayne.Softseal.FusionSoftseal.CreateFusionSoftseal();
- //validationInfo = fusionSoftseal.Validate();
- //if (validationInfo != null)
- {
- fusionForecourtControl = new FUSIONForecourtControl(deviceId, managedEntityTypes, managedPumpIds);
- FUSIONFactory.fusionForecourtControlList.Add(deviceId, fusionForecourtControl);
- Trace.WriteLine(string.Format("FUSIONForecourtControl created"));
- //((FUSIONForecourtControl)fusionForecourtControl).validationInfo = validationString;
- ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.LogOnAddValidationInfo(validationInfo);
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Errore: {0}", ex.Message));
- }
- }
- else
- fusionForecourtControl = fusionForecourtControlList[deviceId];
- return fusionForecourtControl;
- }
- public static string getFUSIONFwRelease(int deviceId, string sConnectionString)
- {
- string sFwRelease = "";
- // fwRelease string is composed by: version.release.hotfix
- IForecourtControl fusionForecourtControl = null;
- fusionForecourtControl = CreateForecourtControl(deviceId);
- if (((FUSIONForecourtControl)fusionForecourtControl).manager.Connect(sConnectionString))
- {
- ((FUSIONForecourtControl)fusionForecourtControl).manager.versionInfoWakeUpEvent.Reset();
- ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.VersionInfo(null, null, null);
- ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.GetCountrySettings(null, null, null);
- ((FUSIONForecourtControl)fusionForecourtControl).manager.versionInfoWakeUpEvent.WaitOne();
- sFwRelease = ((FUSIONForecourtControl)fusionForecourtControl).manager.getFwRelease();
- }
- return sFwRelease;
- }
- public static bool LogOnValidationInfo(int deviceId, byte[] validationInfo)
- {
- IForecourtControl fusionForecourtControl = null;
- fusionForecourtControl = CreateForecourtControl(deviceId);
- if ((FUSIONForecourtControl)fusionForecourtControl == null)
- return false;
- ((FUSIONForecourtControl)fusionForecourtControl).manager.ifsfManager.LogOnAddValidationInfo(validationInfo);
- return true;
- }
- }
- }
|