private void btnActivateRoadCare_Click(object sender, EventArgs e) { // Verify license code CryptoLicense license = new CryptoLicense(); license.ValidationKey = tbVKey.Text.TrimEnd('\r', '\n'); license.LicenseCode = tbLCode.Text.TrimEnd('\r', '\n'); // The license will be loaded from/saved to the registry license.StorageMode = LicenseStorageMode.ToRegistry; // Validate license... if (license.Status != LicenseStatus.Valid) { if (license.Status == LicenseStatus.SignatureInvalid) { MessageBox.Show("Invalid license. Please check your entries and try again."); } else { MessageBox.Show("Invalid license: " + license.Status.ToString()); } } else { licCode = license.LicenseCode; license.Save(); // write to RoadCare.LoginNP.txt UpdateInfoFile(); this.Close(); Application.Restart(); } }
} //readLicenseFile public void readLicenseFile(String strFileName) { // Loads from license file all necessary information if (File.Exists(strFileName)) // License file exists - read from file { setLicenseFromFile(strFileName); } else // License file doesn't exist - auto generated license { if (!m_isAllowBuiltInLicense) { return; } m_objLicence = new CryptoLicense(m_cnstLicCode, cProperties.ProjectKey); m_objLicence.StorageMode = LicenseStorageMode.None; } cLicenseParams.CompID = m_objLicence.GetLocalMachineCodeAsString(); cLicenseParams.setUserData(m_objLicence.UserData); cLicenseParams.DaysLeft = m_objLicence.RemainingUsageDays; cLicenseParams.DateExpires = m_objLicence.DateExpires; //cProperties.isWithQA = cLicenseParams.AllowQA; cProperties.NumBondOpts = cLicenseParams.BondOptNum; cProperties.NumOptimizations = cLicenseParams.OptimizationNum; //cProperties.isWithBondOpt = cLicenseParams.AllowBondOpt; //cProperties.isIsraelOnly = cLicenseParams.isIsraelOnly; setAllowedExchanges(cLicenseParams.Exchanges); }//loadFromFile
public MainForm(CryptoLicense lic) { license = lic; InitializeComponent(); CreateFirstsControls(); Init(); }
/// <summary> /// create a new License for the given license key and public key. /// </summary> /// <param name="key">the key</param> /// <param name="publicKey">the public key</param> public License(string key, string publicKey) { //for some strange reason EA wraps the key in a "{" and "}" so we need to remove them first key = key.Replace("{",string.Empty).Replace("}",string.Empty); this.key = key; //create the wrapped license wrappedLicense = new CryptoLicense(key, publicKey); bool validateFloating = false; //if the license is not valid then it might be a floating license. //in that case we strip the first part until the "-" and try again. int startActualKey = key.IndexOf("-") +1; if (wrappedLicense.Status != LicenseStatus.Valid && startActualKey > 0) { key = key.Substring(startActualKey); wrappedLicense = new CryptoLicense(key, publicKey); validateFloating = true; } //get user data if (wrappedLicense.Status == LicenseStatus.Valid) { this.client = wrappedLicense.GetUserDataFieldValue("Client", "|"); string isFloating = wrappedLicense.GetUserDataFieldValue("Isfloating","|"); bool isFloatingBool; if(bool.TryParse(isFloating,out isFloatingBool)) { this.floating = isFloatingBool; } //set validation status; if (validateFloating == this.floating) { this.isValid = true; } } }
public static void DeactivateLic(String strLicenseFile, String strProjectKey, String strEMail) { CryptoLicense licence; if (File.Exists(strLicenseFile)) { System.Text.ASCIIEncoding ansiEN = new System.Text.ASCIIEncoding(); StreamReader streamReader = new StreamReader(strLicenseFile, ansiEN); string lc = streamReader.ReadToEnd(); licence = new CryptoLicense(lc, strProjectKey); licence.StorageMode = LicenseStorageMode.None; streamReader.Close(); if (licence.Status != LicenseStatus.Valid) { return; } } else { return; } string deactivatedKey = licence.DeactivateLocally(); //string fName = cProperties.DataFolder + "\\" + Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) + ".deactivated"; string fName = strLicenseFile.Replace(".lic", ".deactivated"); SendMail("Deactivation license", "Deactivation key:\r\n" + deactivatedKey, strEMail); using (StreamWriter outfile = new StreamWriter(fName)) { outfile.Write(deactivatedKey); outfile.Close(); } }//DeactivateLic
private static string GetMachineCode() { // machine code CryptoLicense license = new CryptoLicense(); return(license.GetLocalMachineCodeAsString()); }
public static CryptoLicense CreateLicense() { CryptoLicense ret = new CryptoLicense(); ret.ValidationKey = ProductLicense.Constants.validationKey; return(ret); }
private void btnActivate_Click(object sender, EventArgs e) { if (tbVKey.Text == "" || tbLCode.Text == "" || tbLURL.Text == "") { MessageBox.Show("All fields need to be filled."); return; } // Verify license code CryptoLicense license = new CryptoLicense(); license.ValidationKey = tbVKey.Text.TrimEnd('\r', '\n'); license.LicenseCode = tbLCode.Text.TrimEnd('\r', '\n'); license.LicenseServiceURL = tbLURL.Text.TrimEnd('\r', '\n'); // The license will be loaded from/saved to the registry license.StorageMode = LicenseStorageMode.ToRegistry; license.UseHashedMachineCode = false; // Validate license... if (license.Status != LicenseStatus.Valid) { if (license.Status == LicenseStatus.SignatureInvalid) { MessageBox.Show("Invalid license. Please check your entries and try again."); } else if (license.Status == LicenseStatus.ActivationFailed) { if (license.GetCurrentActivationCount() == license.MaxActivations) { MessageBox.Show("License Server has reached maximum usage. Please contact your administrator."); } else { MessageBox.Show("License activation failed. Please contact your administrator."); } } else { MessageBox.Show("Invalid license: " + license.Status.ToString()); } } else { licCode = license.LicenseCode; license.Save(); // write to RoadCare.LoginNP.txt UpdateInfoFile(); DumpFloatingLicense(license); this.Close(); Application.Restart(); } }
public override void AfterConstruction() { base.AfterConstruction(); CryptoLicense license = new CryptoLicense(); // Place here your initialization code. Code = license.GetLocalMachineCodeAsString(); }
}//loadFromFile private void setLicenseFromFile(String fName) { // Sets the license from the license file System.Text.ASCIIEncoding ansiEN = new System.Text.ASCIIEncoding(); StreamReader streamReader = new StreamReader(fName, ansiEN); string lc = streamReader.ReadToEnd(); m_objLicence = new CryptoLicense(lc, cProperties.ProjectKey); m_objLicence.StorageMode = LicenseStorageMode.None; m_objLicence.Load(); streamReader.Close(); }//setLicenseFromFile
CryptoLicense CreateLicense() { CryptoLicense ret = new CryptoLicense(); //Uses the validation key of the "samples.netlicproj" license project file from the "Samples" directory // Get the validation key using Ctrl+K in the Generator UI. ret.ValidationKey = "AMAAMACAan6T73Ctw/rY+L9u9uwHqu7uns3owx7c1/oqgVhKLo+dFEG34875h3IWCcNU8e0DAAEAAQ=="; // *** IMPORTANT: Set the LicenseServiceURL property below to the URL of your license service // See video tutorial at http://www.ssware.com/cryptolicensing/demo/license_service_net.htm to learn // how to create the license service ret.LicenseServiceURL = ""; // your license service URL here! return(ret); }
CryptoLicense CreateLicense() { CryptoLicense ret = new CryptoLicense(); //Uses the validation key of the "samples.netlicproj" license project file from the "Samples" directory // Get the validation key using Ctrl+K in the Generator UI. ret.ValidationKey = "AMAAMACTpBpgKZVChC9PEsB9elxMi/wlCgoiEoAqMXMZR4EuOkUe+cwwTm2hnaNREzEQhjsDAAEAAQ=="; // *** IMPORTANT: Set the LicenseServiceURL property below to the URL of your license service // See video tutorial at http://www.ssware.com/cryptolicensing/demo/license_service_net.htm to learn // how to create the license service ret.LicenseServiceURL = ""; // your license service URL here! return(ret); }
private void btnOK_Click(object sender, EventArgs e) { if (!File.Exists(txtProductLicense.Text)) { MessageBox.Show("Please select an existing file.", msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // // Validate the product license // CryptoLicense license = ProductLicense.Methods.CreateLicense(); license.StorageMode = LicenseStorageMode.ToFile; license.FileStoragePath = txtProductLicense.Text; // Load the license from file if (license.Load()) { if (license.Status != LicenseStatus.Valid) { MessageBox.Show("ConfigOS Foundry license validation failed.\nThe application will be closed.\n" + license.GetAllStatusExceptionsAsString() + "\nPlease select a correct license file and restart the application.", msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); license.Dispose(); Process.GetCurrentProcess().Kill(); } else { } } else { MessageBox.Show("ConfigOS Foundry license not found.\nThe application will be closed.", msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); license.Dispose(); Process.GetCurrentProcess().Kill(); } // // // Copy the existing Foundrykey to the application folder try { File.Copy(txtProductLicense.Text, prouctLicensePath, true); } catch (Exception err) { MessageBox.Show("The ConfigOS Foundry license was not successfully copied to the ConfigOS Foundry application folder.\nThe application will be closed." + err.Message, msgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); Process.GetCurrentProcess().Kill(); } this.Close(); }
static void Main() { const string appName = "StreamCompanion"; bool createdNew; mutex = new Mutex(true, appName, out createdNew); if (!createdNew) { ResourceManager rm = new ResourceManager("StreamCompanion.MainForm", Assembly.GetExecutingAssembly()); String str = rm.GetString("singleinstancewarning", CultureInfo.CurrentCulture); MessageBox.Show(str); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); /* * Standard 10 jours * FgSAgPTVvzKYoNUBCgABARApMzaTcUoNV4kDZrbPcjE70G4oGUX1U4ljWINIUtu+SbsZ0kSI64rdjuLp1vWX5eI= * * Pro 10 jours * FgSAgLWk20OYoNUBCgABAhBqeKEkm6BPTGk11ca4MFesDswsTSvIYQtLyjaSsCoAMKim2PBYk3nP4w8o4k60bCc= * * Pro no limits * FgCAgDJmwVOYoNUBAQIQJahUJdgWCfCD1J/6V2pZSmqIHDC0jIUQaTOP6ipG5f7P/1mHkyMvXDq1V61XzjmC */ string validationKey = "AMAAMACDq7YAhOTWIkO+7tmgmGfnwVoi7zJeoEFDqefYYGYtjoOqI4u4q6EAsFlza7leiicDAAEAAQ=="; CryptoLicense license = new CryptoLicense("FgSAgPTVvzKYoNUBCgABARApMzaTcUoNV4kDZrbPcjE70G4oGUX1U4ljWINIUtu+SbsZ0kSI64rdjuLp1vWX5eI=", validationKey); if (license.Status != LicenseStatus.Valid) { MessageBox.Show("License validation failed"); } else { // Continue normal execution... Application.Run(new MainForm(license)); } }
public static bool CheckSession() { var DeviceId = new DeviceIdBuilder() .AddMachineName() .AddMacAddress() .AddProcessorId() .AddMotherboardSerialNumber() .ToString(); string licenseCode; using (var db = new BrgyMgmtEntities()) { licenseCode = db.ApplicationSettings.Find(1).ApplicationSettingsValue; } CryptoLicense license = new CryptoLicense(licenseCode, Resources.SessionString); //return license.GetUserDataFieldValue("MachineCode", "#") == DeviceId; return(true); }
private void A() { var A = new CryptoLicense { StorageMode = LicenseStorageMode.ToRegistry }; A.ValidationKey = "AAAGgAGk/ESIIO4iJmXxVD/yH4xiLHGJIczm6SCvCAW157h/ew7tiYv/WJW0ug9nic4mf6y5GRywt0rBrFBL80Rb5otI+3AM79U669OUUIcdgP0tqaNSMUbAbLqXn6E/jispyo+R1LyUeKhNgk30iNJnto3C9LP6ASrQNA7jDWSQLWyrw94ztXc2vXSzzzpaRD0Jb3zWEqI9YY7QapnHMa/v0XI7pvK6aq46zgeZUP90yDbiHZjL7GU7R0qJOz8p3zI+6XPPKBohdfin9DcZ6QPJr9utB39wIJU6Mdx4i0acabWCGo1QeAmdUJ8Hvsc2EZ5Dpw0fFt2VfET4upf48aVpsx810oFJb4W70Y7+li5IO8Th9vcREF7OGaB1UasOppI5LCSEdgkv48r9PGldmkE58nAKjEBSp3MNVvhONMZrMPmozU/8YXttYEfmOxA7+5AaDLzJyJV5S38XC+4/0r7jOnezUggFGqjJ4gJIRXFHVMCcc8cRDQojYWzmKYloNF+2FlUDAAEAAQ=="; if (!A.Load()) { A.LicenseCode = "FgIkgTXjr2eZvNMBHgABbu29HnCHi267VJes6C+npz2IlKXxf3y6jv5STVfbfl6rU0s5pSByRT4ZclC9HYDwFg9TkLeIbowTpMNu+EFBVTILkovs7LfCIizYUZsfriR0sArMQCPzk5gP2dOdCK3Z+AyuovflkfissyJ+KAjDBYshohQ4yZdHIjPUhxA+TLc6mXv+GQTyrfFK/M1AFbJzj1km0UoeMhjRZ9SI2kh3bv5/QI8o18h9Fysa3aFRcVlGIi1ADHZGbcQK8XFzbicIyh1IVPoSRNtMzE3GeOQdzPL6YybM4+YQNIC+/yodUXbGUr9ldkMqTK7UoYtgTrTOgqJTOD/rPQrRQe4q5A40ZMSXtGu06tiZl+rfGzwlt9Aaalx8DGkV7Aixy2MGDNIxkVxIsVdmSP/BXLs9Qp8lPWpAGHG0nYZZr8iGNa9tpZ27lypQFrJdyrlYhL72vhcNlDSleR7Zn3AvyGJIvkKmzXwu/0f5bW/DAnhY7N49TmsR8LEjl7VHUallQ5ONI7iZ"; A.Save(); } if (!A.ShowEvaluationInfoDialog("Satış", "https://www.facebook.com/profile.php?id=100002547964778")) { Shutdown(); } A.Dispose(); }
private void frmLicense_Load(object sender, EventArgs e) { lblDateTime.Text = DateTime.Now.ToLongDateString();//GetNistTime().ToLongDateString(); license = new CryptoLicense(ValidationKey); txtMachineCode.Text = license.GetLocalMachineCodeAsString(); txtWinName.Text = Environment.MachineName; //txtWinVer.Text = Environment.OSVersion.ToString(); txtWinVer.Text = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString(); if (CheckForInternetConnection()) { lblInternetStatus.Text = "متصل"; lblInternetStatus.ForeColor = Color.Green; } else { lblInternetStatus.Text = "قطع"; lblInternetStatus.ForeColor = Color.DarkRed; } }
private void button3_Click(object sender, EventArgs e) { bool bLicOk = false; if (string.IsNullOrEmpty(textBoxLic.Text)) { MessageBox.Show(ResStrings.str_Enter_a_License, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } CryptoLicense testLic = new CryptoLicense(); testLic.ValidationKey = _validationKey; testLic.StorageMode = LicenseStorageMode.ToRegistry; testLic.LicenseCode = textBoxLic.Text; if (testLic.HasUserData) { Hashtable dataFields = testLic.ParseUserData("#"); string licenseMachineId = dataFields["MachineID"] as string; string machineId = labelMachineID.Text; bLicOk = machineId.Equals(licenseMachineId); } if (bLicOk) { testLic.Save(); lic.Load(); UpdateLicence(); MessageBox.Show(ResStrings.str_License_Info_Saved, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { textBoxLic.Text = string.Empty; MessageBox.Show(ResStrings.str_Not_a_valid_license_for_this_machine, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning); } testLic.Dispose(); }
private void OnCheckKey() { try { //Show wait screen ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Show(); // Create temp cryptoLicense object CryptoLicense _temp = Activator.CreateInstance(cryptoLicense.GetType()) as CryptoLicense; _temp.StorageMode = cryptoLicense.StorageMode; _temp.ValidationKey = cryptoLicense.ValidationKey; _temp.LicenseServiceURL = cryptoLicense.LicenseServiceURL; _temp.HostAssembly = cryptoLicense.HostAssembly; _temp.LicenseServiceSettingsFilePath = cryptoLicense.LicenseServiceSettingsFilePath; _temp.RegistryStoragePath = cryptoLicense.RegistryStoragePath; _temp.FileStoragePath = cryptoLicense.FileStoragePath; //Check if internet connection to cryptoLicenseService is working if (_temp.PingLicenseService() != null) { Xceed.Wpf.Toolkit.MessageBox.Show("Leider ist der Lizenzserver nicht erreichbar.\nUm Ihre Lizenz zu aktivieren, wird eine funktionierende Internetverbindung benötigt.", "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); return; } // See if its a serial SerialValidationResult result = _temp.GetLicenseFromSerial(this.LicenseInput_Key, string.Empty); if (result == SerialValidationResult.Failed) { // Its a serial, but is invalid string str = "Serial Überprüfung fehlgeschlagen: "; Exception ex = _temp.GetStatusException(LicenseStatus.SerialCodeInvalid); if (ex != null) // Additional info available for the status { str += ex.Message; } else { str += "<no additional information>"; } Xceed.Wpf.Toolkit.MessageBox.Show("Es ist ein Fehler aufgetreten: " + str, "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); return; } // Not a serial, set .LicenseCode property if (result == SerialValidationResult.NotASerial) { _temp.LicenseCode = this.LicenseInput_Key; } // Validate cryptoLicense if (_temp.Status == LicenseStatus.Valid) { // Valid , dispose old cryptoLicense, replace with 'temp' cryptoLicense cryptoLicense.Dispose(); } //Close wait screen ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Close(); //Show result if (_temp.Status != LicenseStatus.Valid) { string additional = "Error code: " + _temp.Status.ToString(); Exception ex = _temp.GetStatusException(_temp.Status); if (ex != null) { additional += ". Error message: " + ex.Message; } Xceed.Wpf.Toolkit.MessageBox.Show("Die eingegebene Lizenz war leider ungültig. Bitte geben Sie einen gültigen Lizenzkey ein und versuchen es erneut.\n" + additional, "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); return; } else { cryptoLicense.Save(); this.IsLicenseValid = true; this.ParseLicenseInfosForThanks(); this.CurrentUserControl = new Views.LicenseThanksUserControl(); } } catch (Exception ex) { SRS.Utilities.Logger.Instance.WriteError(System.Reflection.MethodBase.GetCurrentMethod(), ex); } finally { ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Close(); } }
public MngLicense(CryptoLicense lic, string validationKey) { InitializeComponent(); this.lic = lic; _validationKey = validationKey; }
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 Licensing() { license = new CryptoLicense(); // Get by Pressing Ctrl+K in Crypto License Generator license.ValidationKey = "AMAAMADYLN6qRVjvUEWSzEw0UL1lN8bnWzRVTeB0YCgvKtr8mYotNNvZhpqRF0Ij/cKUN1MDAAEAAQ=="; }
private bool DumpFloatingLicense(CryptoLicense license) { license.Dispose(); license = null; return(true); }
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); } }
public bool CryptoLicensing(bool IsNewLic = false) { if (IsNewLic) { try { int days = manifestWS.ValidateDays(Properties.Settings.Default.LineCode); //Console.WriteLine("Days:"+days.ToString()); if (days > 0) { if (Properties.Settings.Default.OfflineCount != 0) { Properties.Settings.Default.OfflineCount = 0; Properties.Settings.Default.Save(); } return(true); } else { return(false); } } catch { Properties.Settings.Default.OfflineCount += 1; Properties.Settings.Default.Save(); if (Properties.Settings.Default.OfflineCount < 5) { return(true); } else { return(false); } } } else { try { license = new CryptoLicense { ValidationKey = ValidationKey, StorageMode = LicenseStorageMode.ToRegistry }; if (!license.Load()) { return(false); } if (license.Status == LicenseStatus.Valid) { //if (license.HasUserData) //{ // string aaa = license.ParseUserData("#")["linecode"].ToString(); // MessageBox.Show(aaa); //} //Read information from lock every time execute program Properties.Settings.Default.LineCode = license.UserData.Split('#')[0].Split('=')[1].ToString(); Properties.Settings.Default.Company = license.UserData.Split('#')[1].Split('=')[1].ToString(); //Properties.Settings.Default.Save(); return(true); } else { license.Remove(); return(false); } } catch (Exception) { return(false); throw; } finally { license.Dispose(); } } }