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); }