private void GetLastLicense() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { e.Result = DatabaseService.GetLastLicense(); }; worker.RunWorkerCompleted += (sender, e) => { lastLicense = (Models.Entity.License)e.Result; }; worker.RunWorkerAsync(); }
private void OnRegistration() { if (!String.IsNullOrEmpty(RegistrationNumber) && !String.IsNullOrWhiteSpace(RegistrationNumber)) { int licensePeriod; if (DoRegistration(out licensePeriod)) { Models.Entity.License NewLicense = new Models.Entity.License() { ID = Guid.NewGuid(), Count = ++numberOfLicenses, SerialNumber = SerialNumber, AuthorizationKey = AuthorizationKey, RegistrationNumber = RegistrationNumber, Period = licensePeriod, Start = DateTime.Today, End = DateTime.Today.Add(new TimeSpan(licensePeriod, 0, 0, 0)), LastSession = DateTime.Now, Summary = summary }; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { e.Result = DatabaseService.AddOrUpdate(e.Argument as Models.Entity.License); }; worker.RunWorkerCompleted += (sender, e) => { int dd = (int)e.Result; }; worker.RunWorkerAsync(NewLicense); string LicenseDir = @"\MPJ Control\License"; string documentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (!Directory.Exists(documentPath + LicenseDir)) { Directory.CreateDirectory(documentPath + LicenseDir); } string licenseFile = String.Format(@"{0}\License.lph", documentPath + LicenseDir); if (!Directory.Exists(LicenseDir)) { Directory.CreateDirectory(LicenseDir); } File.Create(licenseFile).Close(); string toFile = "Serial Number:\n\t" + SerialNumber + "\n" + "Authorization Key:\n\t" + AuthorizationKey + "\n" + "Registration Number:\n\t" + RegistrationNumber + "\n" + "Period:\n\t" + licensePeriod + "\n" + "Start:\n\t" + DateTime.Today + "\n" + "Last Session:\n\t" + DateTime.Now + "\n" + "End:\n\t" + DateTime.Today.Add(new TimeSpan(licensePeriod, 0, 0, 0)) + "\n\n" + "Summary PC:\n" + summary; File.WriteAllText(licenseFile, toFile); if (OnSwitchView != null) { OnSwitchView(); } } else { ShowMessageAsync("License Error", "Registration Failed!\nTry again or contact your distribution maintainer for update!", MessageDialogStyle.Affirmative); } } else { ShowMessageAsync("License Error", "The RegistrationNumber is required!", MessageDialogStyle.Affirmative); } }
private Models.Entity.License GenerateNewLicense(int licensePeriod) { Assembly assembly = Assembly.GetExecutingAssembly(); var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0]; string appGuid = attribute.Value; string serialNumber = FingerPrint.GetMAC().Replace(':', '-'); string summary = FingerPrint.GetSummary() + "\nMAC\t" + serialNumber + "\nGUID\t" + appGuid; int numberOfLicenses = Licenses.Count; string authorizationKey = FingerPrint.GetHash(appGuid + numberOfLicenses.ToString()); string registrationNumber = FingerPrint.GetHash(serialNumber + authorizationKey + licensePeriod.ToString()); Models.Entity.License NewLicense = new Models.Entity.License() { ID = Guid.NewGuid(), Count = ++numberOfLicenses, SerialNumber = serialNumber, AuthorizationKey = authorizationKey, RegistrationNumber = registrationNumber, Period = licensePeriod, Start = DateTime.Today, End = DateTime.Today.Add(new TimeSpan(licensePeriod, 0, 0, 0)), LastSession = DateTime.Now, Summary = summary }; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { e.Result = DatabaseService.AddOrUpdate(e.Argument as Models.Entity.License); }; worker.RunWorkerCompleted += (sender, e) => { int dd = (int)e.Result; DataDB.RefreshLicenses(); }; worker.RunWorkerAsync(NewLicense); string LicenseDir = @"\PHRDR\License"; string documentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (!Directory.Exists(documentPath + LicenseDir)) { Directory.CreateDirectory(documentPath + LicenseDir); } string licenseFile = String.Format(@"{0}\License.lph", documentPath + LicenseDir); File.Create(licenseFile).Close(); string toFile = "Serial Number:\n\t" + serialNumber + "\n" + "Authorization Key:\n\t" + authorizationKey + "\n" + "Registration Number:\n\t" + registrationNumber + "\n" + "Period:\n\t" + licensePeriod + "\n" + "Start:\n\t" + DateTime.Today + "\n" + "Last Session:\n\t" + DateTime.Now + "\n" + "End:\n\t" + DateTime.Today.Add(new TimeSpan(licensePeriod, 0, 0, 0)) + "\n\n" + "Summary PC:\n" + summary; File.WriteAllText(licenseFile, toFile); return(NewLicense); }