void browseButton_Click(object sender, EventArgs e)
{
using (var openDialog = new OpenFileDialog())
{
openDialog.InitializeLifetimeService();
openDialog.Filter = "License files (*.xml)|*.xml|All files (*.*)|*.*";
openDialog.Title = "Select License file";
var dialogResult = StaThreadRunner.ShowDialogInSTA(openDialog.ShowDialog);
if (dialogResult == DialogResult.OK)
{
var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(openDialog.FileName);
try
{
LicenseVerifier.Verify(licenseText);
var license = LicenseDeserializer.Deserialize(licenseText);
if (LicenseExpirationChecker.HasLicenseExpired(license))
{
var message = "The license you provided has expired, select another file.";
Logger.Warn(message);
MessageBox.Show(this, message, "License expired", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
ResultingLicenseText = licenseText;
Close();
}
catch (Exception exception)
{
var message = $"An error occurred when parsing the license.\r\nMessage: {exception.Message}\r\nThe exception details have been appended to the log.";
Logger.Warn("Error parsing license", exception);
MessageBox.Show(this, message, "Error parsing license", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}