void UpdateLicence() { //ThreadPool.QueueUserWorkItem(new WaitCallback(treatMachineID), null); TreatMachineId(); labelLicenceStatus.Text = lic.Status.ToString(); switch (lic.Status) { case LicenseStatus.DateRollbackDetected: case LicenseStatus.Expired: case LicenseStatus.EvaluationExpired: labelLicenceStatus.ForeColor = Color.Red; buttonCont.Enabled = false; break; case LicenseStatus.Valid: if (lic.IsEvaluationLicense()) { labelLicenceStatus.Text = ResStrings.str_Evaluation_Period; labelLicenceStatus.ForeColor = Color.DarkOrange; if (lic.RemainingExecutions < 100) { labelRun.Visible = true; labelRun.Text = string.Format(ResStrings.str_runs_remaining, lic.RemainingExecutions, lic.MaxExecutions); progressBarRun.Visible = true; progressBarRun.Maximum = lic.MaxExecutions; progressBarRun.Value = lic.RemainingExecutions; } labelDays.Visible = true; labelDays.Text = string.Format(ResStrings.str_days_remaining, lic.RemainingUsageDays, lic.MaxUsageDays); progressBarDays.Visible = true; progressBarDays.Maximum = lic.MaxUsageDays; progressBarDays.Value = lic.RemainingUsageDays; buttonCont.Enabled = true; buttonCont.Text = ResStrings.str_Continue_Evaluation; } else { labelLicenceStatus.ForeColor = Color.Green; buttonCont.Enabled = true; buttonCont.Text = ResStrings.str_Continue; } break; } if (lic.HasUserData) { string userName = null; string company = null; try { Hashtable dataFields = lic.ParseUserData("#"); company = dataFields["Company"] as string; userName = dataFields["Name"] as string; } catch { } labelCompany.Text = company; labelUser.Text = userName; } if (lic.HasDateExpires) { TimeSpan remain = lic.DateExpires.Subtract(DateTime.Now); labelExpirationDate.Text = lic.DateExpires.ToShortDateString(); labelDaysLeft.Text = remain.Days.ToString(CultureInfo.InvariantCulture); if (remain.Days < 15) { labelExpirationDate.ForeColor = Color.DarkOrange; labelDaysLeft.ForeColor = Color.DarkOrange; } if (remain.Days < 5) { labelExpirationDate.ForeColor = Color.Red; labelDaysLeft.ForeColor = Color.Red; } } }
public bool EvaluateLicense() { /* * This code demonstrates typically evaluation license scenario. The idea is as follows.... * First you check if a full license is present (using CryptoLicense.Load method). * If .Load returns false, you switch to a hardcoded evaluation license code (using .LicenseCode property). * Then, you validate using .Status property. * * Even if user uninstalls, all the usage data associated which each license code remains in the * registry and if user reinstalls, the evaluation continues from where it left off. */ var licenseValid = false; CryptoLicense license = CreateLicense(); // The license will be loaded from/saved to the registry license.StorageMode = LicenseStorageMode.ToRegistry; // To avoid conflicts with other scenarios from this sample, the default load/save registry key is changed license.RegistryStoragePath = license.RegistryStoragePath + "EvalLicense"; // The remove method can be useful during development and testing - it deletes a previously saved license. //license.Remove(); // Another useful method during development and testing is .ResetEvaluationInfo() // Load the license from the registry bool loadDialog = !license.Load() || license.Status != LicenseStatus.Valid; if (loadDialog) { string dialogMessage = !license.Load()?"Licensing missing, enter the license key": license.Status != LicenseStatus.Valid?"Licensing expired, enter a new license key": "Licensing missing, enter the license key"; // When app runs for first time, the load will fail, so specify an evaluation code.... // This license code was generated from the Generator UI with a "Limit Usage Days To" setting of 30 days. LicenseForm licenseForm = new LicenseForm(); licenseForm.labelMessage.Text = dialogMessage; if (licenseForm.ShowDialog() == DialogResult.OK) { string licenseKey = licenseForm.textBoxLicense.Text; license.LicenseCode = licenseKey; // Save it so that it will get loaded the next time app runs if (license.Status != LicenseStatus.Valid) { licenseValid = false; } else { license.Save(); licenseValid = true; } } else { Environment.Exit(0); } } if (license.Status != LicenseStatus.Valid) { licenseValid = false; } else { licenseValid = true; } return(licenseValid); // ShowEvaluationInfoDialog shows the dialog only if the license specifies evaluation limits if (license.ShowEvaluationInfoDialog("GrabCaster", "http://www.grabcaster.io") == false) { // license has expired, new license entered is also expired // or user choose the 'Exit Program' option licenseValid = false; // In your app, you may wish to exit app when eval license has expired Application.Exit(); } else { // The current license is valid or the new license entered is valid // or the user choose the 'Continue Evaluation' option // If the user enters a new valid license code, it replaces the existing code // and is automatically saved to the currently specified // storage medium (registry in this sample) using the CryptoLicense.Save method. // The new license code is thus available the next time your software runs. // We still need to check whether the license is an evaluation license if (license.IsEvaluationLicense() == true) { // reduce functionality in evaluation version if so desired licenseValid = true; } } license.Dispose(); // Be sure to call Dispose during app exit or when done using the CryptoLicense object return(licenseValid); }
public LicenseViewModel(UserControl _userControl, CryptoLicense _cryptoLicense) { currentUserControl = _userControl; cryptoLicense = _cryptoLicense; //Check cryptoLicense status if (!cryptoLicense.ValidateSignature()) { this.LicenseStatusText = string.Format("Die Lizenz ist ungültig!\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt.", cryptoLicense.Status); } else if (cryptoLicense.IsLicenseDisabledInService()) { this.LicenseStatusText = "Diese Lizenz wurde deaktiviert!\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt."; } else if (cryptoLicense.IsEvaluationExpired() || DateTime.Now > cryptoLicense.DateExpires) { this.LicenseStatusText = "Der Testzeitraum ist leider abgelaufen!\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt."; } else if (cryptoLicense.IsEvaluationLicense()) { this.IsLicenseValid = true; this.LicenseStatusText = "Vielen Dank, dass Sie diese Software testen!"; if (cryptoLicense.HasDateExpires) { TimeSpan ts = (cryptoLicense.DateExpires.Date - DateTime.Now.Date); int remaining = ts.Days; if (remaining < 0) { remaining = 0; } int max = (cryptoLicense.DateExpires.Date - cryptoLicense.DateGenerated.Date).Days; if (max < 0) { max = 0; } this.EvaluationProgressMax = max; this.EvaluationProgressValue = remaining; this.EvaluationProgressText = string.Format("Die Lizenz läuft am {0} aus! {1} Tage verbleibend", cryptoLicense.DateExpires.ToString("dd-MMM-yyyy"), remaining); } if (cryptoLicense.HasMaxUsageDays) { int remaining = cryptoLicense.MaxUsageDays - cryptoLicense.CurrentUsageDays; if (remaining < 0) { remaining = 0; } else { remaining++; } this.EvaluationProgressMax = cryptoLicense.MaxUsageDays; this.EvaluationProgressValue = remaining; this.EvaluationProgressText = string.Format("{0} von {1} Tagen verbleibend", remaining, cryptoLicense.MaxUsageDays); } if (cryptoLicense.HasMaxUniqueUsageDays) { int remaining = cryptoLicense.MaxUniqueUsageDays - cryptoLicense.CurrentUniqueUsageDays; if (remaining < 0) { remaining = 0; } else if (remaining < cryptoLicense.MaxUniqueUsageDays) { remaining++; } this.EvaluationProgressMax = cryptoLicense.MaxUsageDays; this.EvaluationProgressValue = remaining; this.EvaluationProgressText = string.Format("{0} von {1} kompletten Nutzungstagen verbleibend", remaining, cryptoLicense.MaxUniqueUsageDays); } if (cryptoLicense.HasMaxExecutions) { int remaining = cryptoLicense.MaxExecutions - cryptoLicense.CurrentExecutions; if (remaining < 0) { remaining = 0; } else if (remaining < cryptoLicense.MaxExecutions) { remaining++; } this.EvaluationProgressMax = cryptoLicense.MaxExecutions; this.EvaluationProgressValue = remaining; this.EvaluationProgressText = string.Format("{0} von {1} Programmstarts verbleibend", remaining, cryptoLicense.MaxExecutions); } } else { this.LicenseStatusText = string.Format("Die Lizenz ist ungültig: {0}\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt.", cryptoLicense.Status); } }