Beispiel #1
0
        public RegistrationViewModel(IDialogCoordinator instance)
        {
            GetSW_GUID();
            SerialNumber = FingerPrint.GetMAC().Replace(':', '-');
            summary      = FingerPrint.GetSummary() + "\nMAC\t" + SerialNumber + "\nGUID\t" + appGuid;


            dialogCoordinator = instance;

            OkCommand       = new RelayCommand(OnRegistration);
            CancelCommand   = new RelayCommand(OnCancel);
            LoadedCommand   = new RelayCommand(Loaded);
            UnloadedCommand = new RelayCommand(Unloaded);
        }
Beispiel #2
0
 private void CheckLicense(string userPermission)
 {
     UserPermissionLevel = userPermission;
     if (userPermission == "SuperAdmin")
     {
         SwitchToMainView();
     }
     else
     {
         if (lastLicense != null && lastLicense.SerialNumber == FingerPrint.GetMAC().Replace(':', '-'))
         {
             if (lastLicense.Period == 3650 || (DateTime.Today >= lastLicense.Start && DateTime.Today <= lastLicense.End && lastLicense.LastSession <= DateTime.Now))
             {
                 int days = (lastLicense.End.Value - DateTime.Today).Days;
                 if (days <= 14)
                 {
                     ShowMessageAsync("License Warning", "Your license will expire in " + days + " days.\nPlease contact your distribution maintainer for update!", MessageDialogStyle.Affirmative);
                 }
                 lastLicense.LastSession = DateTime.Now;
                 SwitchToMainView();
             }
             else
             {
                 ShowMessageAsync("License Error", "Application can not be loaded, unauthorized date interrupt occurred (" + lastLicense.Period + " days)! " +
                                  "\nPlease contact your distribution maintainer for update the license!", MessageDialogStyle.Affirmative);
                 RunRegistrationProcess(lastLicense.Count);
             }
         }
         else if (lastLicense != null && lastLicense.SerialNumber != FingerPrint.GetMAC().Replace(':', '-'))
         {
             ShowMessageAsync("License Error", "The serial number in the license file does not match your computer’s active serial number" +
                              "\nPlease contact your distribution maintainer for update the license!", MessageDialogStyle.Affirmative);
             RunRegistrationProcess(lastLicense.Count);
         }
         else
         {
             RunRegistrationProcess(0);
         }
     }
 }
Beispiel #3
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);
        }