private void Testlicense_Click(object sender, RoutedEventArgs e) { /* * 1. clear validation listbox. * 2. define a new stream and select and read the license. * 3. read the values from the license. * 4. validate the license (expiration date and signature). */ ListBoxValidation.Items.Clear(); var ofdlicense = new OpenFileDialog(); ////Dim LicStreamReader As StreamReader Stream myStream = null; ////OfDLicense.InitialDirectory = "c:\" ofdlicense.Filter = "License (*.lic)|*.lic"; ofdlicense.FilterIndex = 1; ofdlicense.InitialDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var result = ofdlicense.ShowDialog(); if (!result.HasValue || !result.Value) { return; } try { myStream = ofdlicense.OpenFile(); if (myStream.Length <= 0) { return; } ulicense = License.Load(myStream); string username = "******" + ulicense.Customer.Name; string email = "Email: " + ulicense.Customer.Email; string quantity = "Quantity: " + ulicense.Quantity.ToString(CultureInfo.InvariantCulture); string HID = "HardwareID: " + ulicense.AdditionalAttributes.Get("HID"); string licenseType = ulicense.Type.ToString(); var str = ValidateLicense(ulicense); var lbi = new ListBoxItem { Content = str }; ListBoxValidation.Items.Add(username); ListBoxValidation.Items.Add(email); ListBoxValidation.Items.Add(quantity); ListBoxValidation.Items.Add(HID); ListBoxValidation.Items.Add(licenseType); ListBoxValidation.Items.Add(lbi); } catch (Exception ex) { MessageBox.Show("Cannot read file from disk. Original error: " + ex.Message); } finally { //// Check this again, since we need to make sure we didn't throw an exception on open. if (myStream != null) { myStream.Close(); } } }
/// <summary> /// The button open license click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ButtonOpenLicClick(object sender, RoutedEventArgs e) { /* * 1. clear validation listbox. * 2. define a new stream and select and read the license. * 3. read the values from the license. * 4. validate the license (expiration date and signature). */ ListBoxValidation.Items.Clear(); var ofdlicense = new OpenFileDialog(); ////Dim LicStreamReader As StreamReader Stream myStream = null; ////OfDLicense.InitialDirectory = "c:\" ofdlicense.Filter = "License (*.lic)|*.lic"; ofdlicense.FilterIndex = 1; ofdlicense.InitialDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var result = ofdlicense.ShowDialog(); if (!result.HasValue || !result.Value) { return; } try { myStream = ofdlicense.OpenFile(); if (myStream.Length <= 0) { return; } this.ulicense = License.Load(myStream); this.TextBoxCustomerRo.Text = this.ulicense.Customer.Name; this.TextBoxEMailRo.Text = this.ulicense.Customer.Email; this.TextBoxUsersRo.Text = this.ulicense.Quantity.ToString(CultureInfo.InvariantCulture); this.TextBoxAttributeNameRo.Text = "Software"; this.TextBoxAttributeValueRo.Text = this.ulicense.AdditionalAttributes.Get(this.TextBoxAttributeNameRo.Text); this.CheckBoxSalesRo.IsChecked = this.ulicense.ProductFeatures.Get("Sales") == "True"; this.CheckBoxBillingRo.IsChecked = this.ulicense.ProductFeatures.Get("Billing") == "True"; this.TextBoxLicenseType.Text = this.ulicense.Type.ToString(); var str = this.ValidateLicense(this.ulicense); var lbi = new ListBoxItem { Content = str }; this.ListBoxValidation.Items.Add(lbi); } catch (Exception ex) { MessageBox.Show("Cannot read file from disk. Original error: " + ex.Message); } finally { //// Check this again, since we need to make sure we didn't throw an exception on open. if (myStream != null) { myStream.Close(); } } }