View previous topic :: View next topic |
Author |
Message |
Javier
Joined: 09 Oct 2009 Posts: 215
|
Posted: Sun Oct 18, 2009 12:10 am Post subject: Evaluation dialog in a custom license application |
|
|
I like the concept of the evaluation dialog that shows up at startup, as shown in the simple encrypted license application sample. However, in the custom application sample the evaluation dialog is not used at all. In addition, in the custom sample _licenseFile doesn't exist. Could you please provide some C# code on how to implement the evaluation dialog in a custom license application? Thank you. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Oct 18, 2009 10:13 pm Post subject: |
|
|
Normally if you want to use the EvaluationDialog you would put the code to check the license in the "Main" method for the application (as is done in the simple encrypted license file method). This makes it easier to exit the application if the user chooses the exit option. The custom application isn't structured this way - it has the license checking code in the main form. You could either restructure the code to be similar to the simple license key generator or you could move the licensing logic from the MainForm constructor to the OnLoad method eg
Code: | /// <summary>
/// Form constructor
/// </summary>
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Check the license
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// load the application settings
//
_settings = Settings.Load();
// validate the license key - this returns null if there is no license
//
_license = _licenseProvider.ValidateLicenseKey(LICENSE_PARAMETERS, _settings.LicenseKey);
// if there is no installed license then display the evaluation dialog until
// the user installs a license or selects Exit or Continue
//
while (_license == null)
{
EvaluationMonitor evaluationMonitor = new RegistryEvaluationMonitor("MyEvaluationPassword");
EvaluationDialog evaluationDialog = new EvaluationDialog(evaluationMonitor, Application.ProductName);
EvaluationDialogResult dialogResult = evaluationDialog.ShowDialog();
if (dialogResult == EvaluationDialogResult.Exit)
{
// exit the application
//
Application.Exit();
break;
}
if (dialogResult == EvaluationDialogResult.Continue) break; // exit the loop
if (dialogResult == EvaluationDialogResult.InstallLicense)
{
// install the license
//
_installButton_Click(this, null);
}
}
UpdateLicenseInfo();
} |
This allows the application to exit when the user clicks exit. The custom licensed app sample demostrates saving the license key yourself (in a settings file with other program data) thats why there is no license file.
You need to consider what features you need in your application and then you can use the sample which is closest as a starting point. _________________ Infralution Support |
|
Back to top |
|
|
Javier
Joined: 09 Oct 2009 Posts: 215
|
Posted: Sun Oct 18, 2009 10:45 pm Post subject: |
|
|
What are the pros and cons between the settings file versus the license file? Also, in your reply you mention EvaluationMonitor, however this is not in the sample. Is it necessary? Thank you. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Oct 19, 2009 1:17 am Post subject: |
|
|
Quote: | What are the pros and cons between the settings file versus the license file? |
You might use the settings file approach (from Custom sample) if you want to save other data with the license key - or save the license key in a different location. In the sample the licensee name is saved in the settings file along with the license key. The license key ProductInfo just contains a hash of the licensee name - which is then compared and verified against the name stored in the settings file. If you put the complete licensee name in the ProductInfo then you wouldn't need to do this (and could just use the standard approach) - however your license keys would be longer.
Quote: | Also, in your reply you mention EvaluationMonitor, however this is not in the sample. Is it necessary? |
Oops - the sample I posted is for the next release of ILS in which the interface for the EvaluationDialog has changed slightly. The EvaluationDialog uses the EvaluationMonitor class underneath to get/save the Evaluation data. For the current release this code should look like:
Code: | /// <summary>
/// Form constructor
/// </summary>
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Check the license
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// load the application settings
//
_settings = Settings.Load();
// validate the license key - this returns null if there is no license
//
_license = _licenseProvider.ValidateLicenseKey(LICENSE_PARAMETERS, _settings.LicenseKey);
// if there is no installed license then display the evaluation dialog until
// the user installs a license or selects Exit or Continue
//
while (_license == null)
{
EvaluationDialog evaluationDialog = new EvaluationDialog(Application.ProductName, "MyEvaluationPassword");
EvaluationDialogResult dialogResult = evaluationDialog.ShowDialog();
if (dialogResult == EvaluationDialogResult.Exit)
{
// exit the application
//
Application.Exit();
break;
}
if (dialogResult == EvaluationDialogResult.Continue) break; // exit the loop
if (dialogResult == EvaluationDialogResult.InstallLicense)
{
// install the license
//
_installButton_Click(this, null);
}
}
UpdateLicenseInfo();
} |
_________________ Infralution Support |
|
Back to top |
|
|
|