protected override void OnStart(string[] args) { try { bool IsStartBroker = false; if (Storage.IsLicenceCheck == "1") { //Identifier.Contains("_Mobile") || !actstation.Identifier.Contains("_DashBoard") var RootDir = System.Reflection.Assembly.GetExecutingAssembly().Location; RootDir = RootDir.Replace("AMS.Broker.WatchDogService.exe", ""); RootDir = RootDir + "2020License"; //RootDir=@"E:\Installshield\Broker\Release\2020License"; string OnlyfileName = null; int length1 = 0; if (Directory.Exists(RootDir)) { string[] filePaths = Directory.GetFiles(RootDir, "*.lic", SearchOption.AllDirectories); var directory = new DirectoryInfo(RootDir); if (directory.GetFiles().Length > 0) { var MyFile = (from f in directory.GetFiles("*.lic", SearchOption.AllDirectories) orderby f.LastWriteTime descending select f).First(); string SuccessGUID = "425330e9-8c97-434a-a9af-7b63602ef05e"; string FailureGUID = "fd7f39ad-415d-4d18-b758-8ee6f1b83c7c"; string MachineName = Environment.MachineName; string MAcAddress = null; NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); String sMacAddress = string.Empty; foreach (NetworkInterface adapter in nics) { if (sMacAddress == String.Empty && adapter.GetPhysicalAddress().ToString() != "")// only return MAC Address from first card { //IPInterfaceProperties properties = adapter.GetIPProperties(); Line is not required MAcAddress = adapter.GetPhysicalAddress().ToString(); } } if (filePaths.Count() > 0) { string _fileName = MyFile.FullName; // length1 = _fileName.Length - RootDir.Length - 1; OnlyfileName = MyFile.Name; byte[] buffer; FileStream fileStream = new FileStream(_fileName, FileMode.Open, FileAccess.Read); try { int length = (int)fileStream.Length; // get file length buffer = new byte[length]; // create buffer int count; // actual number of bytes read int sum = 0; // total number of bytes read // read until Read method returns 0 (end of the stream has been reached) while ((count = fileStream.Read(buffer, sum, length - sum)) > 0) { sum += count; // sum is a buffer offset for next reading } string LicTableId = null; string GUID = null; var InputData = OnlyfileName.Split('_'); if (InputData != null) { LicTableId = InputData[0]; GUID = InputData[1]; } string key1 = "0000000000000000"; var key = key1.Substring(LicTableId.Length, 16 - LicTableId.Length) + LicTableId; string outpath = RootDir + "//Output.txt"; string inpath = RootDir + "//Input.txt"; string bufferstring = System.Text.Encoding.Default.GetString(buffer); System.IO.File.WriteAllBytes(inpath, buffer); DecryptFile(outpath, inpath, key); string ReadFileDt = System.IO.File.ReadAllText(outpath); var SecondDecryptData = Decrypt(ReadFileDt); File.Delete(inpath); File.Delete(outpath); var ReqData = SecondDecryptData.Split(','); if (ReqData.Count() == 9) // jatin 07112017 // jatin 08112017 { int LicTableID = int.Parse(ReqData[0].Replace("start13-", "")); var CustGUID = ReqData[1]; var FromDate = ReqData[2]; var ToDate = ReqData[3]; var CustName = ReqData[4]; // var regDate = ReqData[4]; var siteConnections = ReqData[5]; var McName = ReqData[6]; var MacAddr = ReqData[7]; var ActivationGUID = ReqData[8].Replace("-end13", ""); DateTime _dateVal = DateTime.Parse(epoch2string(int.Parse(ToDate))); if (ActivationGUID == SuccessGUID) { if (McName == MachineName && MacAddr == MAcAddress && DateTime.Now <= _dateVal) // jatin 08112017 { IsStartBroker = true; } else { IsStartBroker = false; _logger.Info("Error while validating license, Please contact 2020imaging"); InsertBrokerOperationLog.AddProcessLog("Error while validating license, Please contact 2020imaging");//jatin } } else { IsStartBroker = false; _logger.Info("Error while validating license, Please contact 2020imaging"); InsertBrokerOperationLog.AddProcessLog("Error while validating license, Please contact 2020imaging");//jatin } } else { IsStartBroker = false; _logger.Info("Error while validating license, Please contact 2020imaging"); InsertBrokerOperationLog.AddProcessLog("Error while validating license, Please contact 2020imaging");//jatin } } catch (Exception ex) { _logger.Info("Exception while validating license" + ex.Message); InsertBrokerOperationLog.AddProcessLog("Exception while validating license" + ex.Message);//jatin } } else { IsStartBroker = false; _logger.Info("Error while validating license, Please contact 2020imaging"); InsertBrokerOperationLog.AddProcessLog("Error while validating license, Please contact 2020imaging");//jatin } }// else { IsStartBroker = false; _logger.Info("Licence file not found"); InsertBrokerOperationLog.AddProcessLog("Licence file not found");//jatin } } else { IsStartBroker = false; _logger.Info("Licence Directory:" + RootDir + " :Not found"); InsertBrokerOperationLog.AddProcessLog("Licence Directory:" + RootDir + " :Not found");//jatin } } else { IsStartBroker = true; } if (IsStartBroker == true) { if (CheckCertificate() == false) { _logger.Info("BrokerWatchDogService OnStart() : " + "Kindly install valid certificate from 2020Imaging!"); Environment.Exit(1); } System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); SSLValidator.OverrideValidation(); //it is for https //trupti250216 IUnityContainer container = new UnityContainer(); container.RegisterInstance <IUnityContainer>(container); container = Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(container); //BrokerService.Container.RegisterInstance<IStationsService>(new StationsServiceImpl()); GatewayService.Initialise(); //var AlertCreationServ = AlertsCreationService.Initialise(stationService, bizTalkHelper); //IEnumerable<DeviceDto> DeviceCollection = controllerService.GetDevicesCollection(authCode); //controllerService.GetDevicesCollectionMob(authCode); //CreateXamlFile(DeviceCollection); //for updating camera status var _IcameraStatus = CameraStatusService.Initialise(); //_IcameraStatus.StartCameraStatusTimer(); base.OnStart(args); } } catch (Exception e) { _logger.Info("BrokerService OnStart() Exception:" + e.Message); ExceptionHandler(e); } }