private bool CheckLicense() { //Initialize variables with default values MagentixLicense _lic = null; byte[] _certPubicKeyData; string _msg = string.Empty; LicenseStatus _status = LicenseStatus.UNDEFINED; //Read public key from assembly Assembly _assembly = Assembly.GetExecutingAssembly(); using (MemoryStream _mem = new MemoryStream()) { Stream stream = _assembly.GetManifestResourceStream("Magentix.Presentation.LicenseVerify.cer"); stream.CopyTo(_mem); _certPubicKeyData = _mem.ToArray(); } //Check if the XML license file exists if (File.Exists("license.lic")) { _lic = (MagentixLicense)LicenseHandler.ParseLicenseFromBASE64String( typeof(MagentixLicense), File.ReadAllText("license.lic"), _certPubicKeyData, out _status, out _msg); if (_lic.TrialVersion == true && _lic.TrialDate < DateTime.Now) { MessageBox.Show("Your trial version is expired. Please buy full version.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return(false); } } else { _status = LicenseStatus.INVALID; _msg = "Your copy of this application is not activated"; } switch (_status) { case LicenseStatus.VALID: return(true); default: return(false); } }
private void btnActivate_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(txtActivationCode.Text)) { MessageBox.Show("Please input license", "MagentixPOS", MessageBoxButton.OK, MessageBoxImage.Warning); return; } //Check the activation string LicenseStatus _licStatus = LicenseStatus.UNDEFINED; string _msg = string.Empty; byte[] CertificatePublicKeyData; Assembly _assembly = Assembly.GetExecutingAssembly(); using (MemoryStream _mem = new MemoryStream()) { Stream stream = _assembly.GetManifestResourceStream("Magentix.Presentation.LicenseVerify.cer"); stream.CopyTo(_mem); CertificatePublicKeyData = _mem.ToArray(); } MagentixLicense _lic = (MagentixLicense)LicenseHandler.ParseLicenseFromBASE64String(typeof(MagentixLicense), txtActivationCode.Text.Trim(), CertificatePublicKeyData, out _licStatus, out _msg); switch (_licStatus) { case LicenseStatus.VALID: if (_lic.TrialVersion == true && _lic.TrialDate < DateTime.Now) { MessageBox.Show("This key is expired. Please buy full version key.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); txtActivationCode.Select(0, txtActivationCode.Text.Length); txtActivationCode.Focus(); return; } File.WriteAllText("license.lic", txtActivationCode.Text); this.DialogResult = true; return; case LicenseStatus.CRACKED: case LicenseStatus.INVALID: case LicenseStatus.UNDEFINED: MessageBox.Show("License is INVALID", "MagentixPOS", MessageBoxButton.OK, MessageBoxImage.Error); return; default: return; } }