Beispiel #1
0
        private bool DoRegistration(out int licensePeriod)
        {
            licensePeriod = 0;
            bool state = true;

            string key_60        = FingerPrint.GetHash(SerialNumber + AuthorizationKey + "60");
            string key_365       = FingerPrint.GetHash(SerialNumber + AuthorizationKey + "365");
            string key_unlimited = FingerPrint.GetHash(SerialNumber + AuthorizationKey + "3650");

            if (RegistrationNumber != null && RegistrationNumber == key_60)
            {
                licensePeriod = 60;
            }
            else if (RegistrationNumber != null && RegistrationNumber == key_365)
            {
                licensePeriod = 365;
            }
            else if (RegistrationNumber != null && RegistrationNumber == key_unlimited)
            {
                licensePeriod = 3650;
            }
            else
            {
                state = false;
            }
            return(state);
        }
Beispiel #2
0
        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);
        }