View previous topic :: View next topic |
Author |
Message |
Pointeman
Joined: 07 Sep 2010 Posts: 56
|
Posted: Fri Sep 17, 2010 9:49 pm Post subject: Force Authentication Web Service Check? |
|
|
Q. How do I force a periodic license check by contacting the Authentication Web Service? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Sep 18, 2010 4:22 am Post subject: |
|
|
Your application can call the AuthenticatedLicenseProvider.IsAuthenticated method to check with the server that a license is still authenticated. So could do this every 5th time your application starts - or whatever you want. _________________ Infralution Support |
|
Back to top |
|
|
Pointeman
Joined: 07 Sep 2010 Posts: 56
|
Posted: Sat Sep 18, 2010 5:54 am Post subject: |
|
|
Okay, I'm lost here, help...
AuthenticationService authSvr = new AuthenticationService();
bool isValid = authSvr.IsAuthenticated(LICENSE_PARAMETERS, "", ""); |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Sep 18, 2010 10:59 am Post subject: |
|
|
No - not AuthenticationService.IsAuthenticated but AuthenticatedLicenseProvider.IsAuthenticated. This lets you just pass the license you had previously loaded. _________________ Infralution Support |
|
Back to top |
|
|
Pointeman
Joined: 07 Sep 2010 Posts: 56
|
Posted: Sat Sep 18, 2010 6:48 pm Post subject: |
|
|
Yea, here is the code we have so far. It doesn't throw error or open the messagebox either. We would like to know how to incorporate the following code with your AuthenticateApp_CS example. Maybe they conflict when used together?
Code: | [Auth Server Check]
AuthenticatedLicenseProvider authSvr = new AuthenticatedLicenseProvider();
bool isValid = authSvr.IsAuthenticated(_license);
System.Windows.Forms.MessageBox.Show("Auth Server License Check=" + isValid.ToString());
[AuthenticateApp_CS example]
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
// check if there is a valid license for the application
//
AuthenticatedLicenseProvider provider = new AuthenticatedLicenseProvider();
_license = provider.GetLicense(LICENSE_PARAMETERS, _licenseFile, true);
// 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) return; // exit the app
if (dialogResult == EvaluationDialogResult.Continue) break; // exit the loop
if (dialogResult == EvaluationDialogResult.InstallLicense)
{
AuthenticatedLicenseInstallForm licenseForm = new AuthenticatedLicenseInstallForm();
_license = licenseForm.ShowDialog(_licenseFile, null);
}
}
Application.Run(new MainForm());
} |
|
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Sep 20, 2010 12:23 am Post subject: |
|
|
Here is some code that checks that the license is authenticated every fifth time the software is run. To do this it uses the EvaluationMonitor.UsageCount property.
Code: | AuthenticatedLicenseProvider provider = new AuthenticatedLicenseProvider();
_license = provider.GetLicense(LICENSE_PARAMETERS, _licenseFile, true);
EvaluationMonitor evaluationMonitor = new RegistryEvaluationMonitor("MyEvaluationPassword");
if (_license != null && evaluationMonitor.UsageCount % 5 == 0)
{
try
{
if (!provider.IsAuthenticated(_license))
{
MessageBox.Show("License no longer authenticated");
provider.UninstallLicense(_licenseFile);
_license = null;
}
}
catch (Exception e)
{
// you have to decide what to do if you can't connect via the
// internet to the server
}
}
// 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(evaluationMonitor, Application.ProductName);
EvaluationDialogResult dialogResult = evaluationDialog.ShowDialog();
if (dialogResult == EvaluationDialogResult.Exit) return; // exit the app
if (dialogResult == EvaluationDialogResult.Continue) break; // exit the loop
if (dialogResult == EvaluationDialogResult.InstallLicense)
{
AuthenticatedLicenseInstallForm licenseForm = new AuthenticatedLicenseInstallForm();
_license = licenseForm.ShowDialog(_licenseFile, null);
}
}
Application.Run(new MainForm()); |
The difficulty is deciding what to do if you can't connect to the Authentication Server (which results in an exception). If you simply prevent them from running then that means that they can't run the software without an internet connection - which will probably result in some very frustrated customers. That's why we don't do this by default. _________________ Infralution Support |
|
Back to top |
|
|
Pointeman
Joined: 07 Sep 2010 Posts: 56
|
Posted: Wed Dec 29, 2010 9:26 pm Post subject: AuthenticatedLicenseProvider Done Differently... |
|
|
I have re-coded the 'AuthenticatedLicenseProvider' differently below. I run the Eval Monitor first...
Q. Will 'evaluationMonitor.UsageCount' continue to count even though a good license is installed?
1. My concern is product refunds where the end-user is still using the software license.
2. There are also those who have legitimate license, but are disconnected from the Internet or our web service is down.
This way the program is 'crippled', but not entirely de-licensed. See what you think...
EvaluationMonitor evaluationMonitor = new RegistryEvaluationMonitor("MyEvaluationPassword");
if (_license == null)
{
EvaluationDialog evaluationDialog = new EvaluationDialog(evaluationMonitor, Application.ProductName);
EvaluationDialogResult dialogResult = evaluationDialog.ShowDialog();
if (dialogResult == EvaluationDialogResult.Exit) return;
if (dialogResult == EvaluationDialogResult.Continue) break;
if (dialogResult == EvaluationDialogResult.InstallLicense)
{
AuthenticatedLicenseInstallForm licenseForm = new AuthenticatedLicenseInstallForm();
_license = licenseForm.ShowDialog(_licenseFile, null);
}
}
if (_license != null) //License file good
{
if(evaluationMonitor.UsageCount % 5 == 0)
{
AuthenticatedLicenseProvider provider = new AuthenticatedLicenseProvider();
_license = provider.GetLicense(LICENSE_PARAMETERS, _licenseFile, true);
try
{
if (!provider.IsAuthenticated(_license))
{
MessageBox.Show("License Error; Program Closing...");
Application.ExitThread();
}
}
catch (Exception)
{
}
} |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Dec 29, 2010 11:11 pm Post subject: |
|
|
Some things don't make sense there - perhaps you haven't posted all the code. Are you calling provider.GetLicense() before this code? If you aren't then _license will always be null when the code is executed so you would always display the EvaluationMonitor.
Also further down where you do call GetLicense there is no real need to - because this code is only executed if _license != null.
The evaluationMonitor is completely separate from the LicenseProvider - so it will continue to work even though a license is installed if you call it.
I'm not clear on what your modifications really achieve. If you just what to go back to evaluation mode when you are unable to contact the authentication service then you could use the original code I posted but in the exception handler put the following:
Code: | catch (Exception e)
{
_license = null;
MessageBox.Show("Can't contact authentication server");
} |
Note that this solution will mean that your program will potentially load slowly every fifth time it is run. An alternative would be to start a separate thread (if there is a valid license) which does this check in the background. If the check fails then you can terminate the program or revert to evaluation mode. This check could then be done every time the program is run (since it wouldn't really slow your app loading). _________________ Infralution Support |
|
Back to top |
|
|
Pointeman
Joined: 07 Sep 2010 Posts: 56
|
Posted: Thu Dec 30, 2010 2:11 pm Post subject: |
|
|
Good Point. I moved the following code because I thought it was crashing the program on boot-up.
AuthenticatedLicenseInstallForm licenseForm = new AuthenticatedLicenseInstallForm();
_license = licenseForm.ShowDialog(_licenseFile, null); |
|
Back to top |
|
|
|