protected bool StartAdapter(DeviceLicense device) { if (device == null) { return(false); } if (CheckAdapter()) { return(false); } if (adapter.Start(new string[] { device.FeatureCode.ToString() })) { Program.Log.Write(LogType.Debug, "Adapter starting succeeded.\r\n"); return(true); } else { Program.Log.Write(LogType.Warning, "Adapter starting failed.\r\n"); Program.Log.Write(adapter.LastError); this.Stop(); return(false); } }
protected override void OnStart(string[] args) { StringBuilder sb = new StringBuilder(); if (args != null) { foreach (string a in args) { sb.Append(a).Append(" "); } } Program.Log.Write(LogType.Debug, "Arguments: " + sb.ToString()); DeviceLicense device = licensecontroler.Start(args); if (device == null) { return; } if (!StartAdapter(device)) { return; } messager.NotifyServiceStart(); garbagecollector.Start(); }
static void Main(string[] args) { if (args == null || args.Length < 1) { return; } string header = args[0]; if (header.Length < 1) { return; } GWLicenseAgent agt = new GWLicenseAgent(true); GWLicense gatewaylic = agt.LoginGetLicenseLogout(); StringBuilder sb = new StringBuilder(); sb.Append(header); if (gatewaylic == null) { // Login dog or read license data failed. //sb.Append("NOTFOUND"); sb.Append("00000000"); } else { DeviceLicense licSender = gatewaylic.FindDevice( DeviceName.HL7_SENDER.ToString(), DeviceType.HL7, DirectionType.OUTBOUND); DeviceLicense licReceiver = gatewaylic.FindDevice( DeviceName.HL7_RECEIVER.ToString(), DeviceType.HL7, DirectionType.INBOUND); getEncodedLicense(sb, licSender, gatewaylic); getEncodedLicense(sb, licReceiver, gatewaylic); } DataCrypto dc = new DataCrypto( "DES", // Encrypt algorithm name. "skic8fh35l093kg8vj5u98jnx01plm938vuikjmna45hgjvnmyqtxzap09lxtsei" // Key ); string content = dc.Encrypto(sb.ToString()); using (StreamWriter sw = File.CreateText(Application.StartupPath + "\\CheckDog.dat")) { sw.Write(content); } //using (StreamWriter sw = File.CreateText(Application.StartupPath + "\\CheckDog.DescryptoTest.txt")) //{ // sw.Write(dc.Decrypto(content)); //} }
private DeviceLicense ValidateLicense(bool retry) { DeviceLicense device = null; Program.Log.Write("==== Validate License Begin ===="); if (_name == GWLicenseHelper.LightMWLOutDeviceName) { device = GWLicenseHelper.LightMWLOutDeviceLicense; Program.Log.Write("Find Light MWL Outbound Interface License."); } else { GWLicenseAgent agent = new GWLicenseAgent(retry); GWLicense license = agent.LoginGetLicenseLogout(Program.Log); if (license == null) { goto ExitValidation; } device = license.FindDevice(_name, _type, _direction); if (device == null) { Program.Log.Write(LogType.Warning, "Cannot find license information for this device."); goto ExitValidation; } if (device.MaxInterfaceCount == 0) { device = null; Program.Log.Write(LogType.Warning, "License of this device was disabled. "); goto ExitValidation; } if (device.IsExpired(license.Header.CreateDate)) { device = null; Program.Log.Write(LogType.Warning, "License of this device was expired. License create date: " + license.Header.CreateDate.ToShortDateString()); goto ExitValidation; } } ExitValidation: Program.Log.Write("==== Validate License End ===="); if (device == null) { Program.Log.Write(LogType.Warning, "Validate license failed, stop NT service."); _service.Stop(); } return(device); }
private bool CheckLicense(InterfaceType type) { int icount = Program.ConfigMgt.Config.GetInterfaceCount(type);; string strDeviceName; DeviceType dType; DirectionType directType; if (InterfaceType.Receiver == type) { strDeviceName = "HL7_RECEIVER"; dType = DeviceType.HL7; directType = DirectionType.INBOUND; } else { strDeviceName = "HL7_SENDER"; dType = DeviceType.HL7; directType = DirectionType.OUTBOUND; } DeviceLicense lic = Program.License.FindDevice (strDeviceName, dType, directType); if (lic == null) { MessageBoxHelper.ShowInformation("Can not find licence for this type of interface."); return(false); } int maxCount = lic.MaxInterfaceCount; if (maxCount == 0) { MessageBoxHelper.ShowInformation("You licence is disabled"); return(false); } if (lic.IsExpired(Program.License.Header.CreateDate)) { MessageBoxHelper.ShowInformation("You licence is expired"); return(false); } if (icount >= maxCount) { MessageBoxHelper.ShowInformation("You interface number has reached the max count."); return(false); } return(true); }
protected override void OnStart(string[] args) { DumpArgument(args); if (Program.License.Config.Enabled) { DeviceLicense device = licensecontroler.Start(); if (device == null) { return; } } _container.Start(); NotifyServiceStatusChange(0); }
public DeviceLicense Start() { DeviceLicense device = ValidateLicense(false); if (device == null) { return(null); } //DeviceLicense device = new DeviceLicense(); _timer.Interval = TimerInterval; _timer.Start(); _log.Write("License Controler started."); return(device); }
public DeviceLicense Start(string[] args) { bool retry = (args == null || args.Length < 1 || args[0] != AdapterConfigArgument.InIM); //DeviceLicense device = ValidateLicense(retry); DeviceLicense device = new DeviceLicense(); if (device == null) { return(null); } //DeviceLicense device = new DeviceLicense(); _timer.Interval = TimerInterval; _timer.Start(); Program.Log.Write("License Controler started."); return(device); }
static void getEncodedLicense(StringBuilder sb, DeviceLicense devicelic, GWLicense gatewaylic) { if (sb == null) { return; } if (devicelic == null || gatewaylic == null) { // There is not license information in the dog for this interface. sb.Append("0000"); //sb.Append("NULL"); } else { // Encoding license information. sb.Append(getString(devicelic.MaxInterfaceCount)); if (devicelic.IsExpired(gatewaylic.Header.CreateDate)) { sb.Append('0'); } else { sb.Append('1'); } string strFeature = getString(devicelic.FeatureCode); if (strFeature == null || strFeature.Length < 2) { sb.Append('0'); } else { sb.Append(strFeature[1]); } } }
private void FillDeviceList(GCDeviceCollection dlist) { this.listViewDevice.Items.Clear(); if (dlist == null) { return; } List <int> deviceIDs = new List <int>(); foreach (GCDevice d in dlist) { deviceIDs.Add(d.DeviceID); } Dictionary <int, int> countList = interfaceMgt.GetInterfaceCount(deviceIDs.ToArray()); foreach (GCDevice o in dlist) { GCDeviceAgent d = o as GCDeviceAgent; if (d == null) { continue; } // don't need to read DeviceDir file DeviceRec dr = d.DeviceRec; ListViewItem i = this.listViewDevice.Items.Add(dr.ID.ToString()); i.SubItems.Add(dr.Name); i.SubItems.Add(DataHelper.GetTypeName(dr.Type)); i.SubItems.Add(dr.Description); i.Tag = d; if (countList != null) { int icount = countList[d.DeviceID]; string str = icount.ToString(); //DeviceLicenseLevel level = Program.License.FindLicenseLevel // (dr.Name, DataHelper.GetType(dr.Type), DataHelper.GetDirection(dr.Direction)); DeviceLicense lic = Program.License.FindDevice (dr.Name, DataHelper.GetType(dr.Type), DataHelper.GetDirection(dr.Direction)); string strMax = ""; if (lic != null) { int maxCount = lic.MaxInterfaceCount; if (maxCount == 0) { strMax = " (Disable)"; i.ForeColor = Color.Gray; i.Tag = null; } else { if (lic.IsExpired(Program.License.Header.CreateDate)) { strMax = " (Expired)"; i.ForeColor = Color.Gray; i.Tag = null; } else { if (maxCount == DeviceLicense.InfiniteInterfaceCount) { strMax = " (Max: infinte)"; } else { strMax = " (Max: " + maxCount.ToString() + ")"; if (icount >= maxCount) { i.ForeColor = Color.Gray; i.Tag = null; } } } } } else { strMax = " (Unknown)"; //US28109-TA93905 #region //暂时去掉加接口时的权限验证 //i.ForeColor = Color.Gray; //i.Tag = null; #endregion } i.SubItems.Add(str + strMax); } else { i.ForeColor = Color.Gray; i.Tag = null; } } }