View previous topic :: View next topic |
Author |
Message |
PunkOnWheels
Joined: 07 Apr 2010 Posts: 2
|
Posted: Mon May 10, 2010 9:56 am Post subject: Licensing a class |
|
|
Hi there.
I just wanted to find out the best way to license a class of static methods so that people cant just take the dll's and use them elsewhere.
I have 5 classes of methods and not all of them have constructors to check licenses, etc. and most have public static methods, so I need to have a way to license a particular class programmatically for an additional level of application security.
Thanks alot |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon May 10, 2010 11:25 pm Post subject: |
|
|
To license a static class you need to provide a method to allow the client application to install the license key. To do this add a static InstallLicenseKey method to your application that calls EncryptedLicenseProvider.ValidateLicenseKey. Your licensed methods then check the license before actually doing anything. The code below shows this approach and also allows for an trial/evaluation period.
Code: | public static class MyClass
{
private static EncryptedLicense _license;
public static void InstallLicenseKey(string licenseKey)
{
const string LICENSE_PARAMETERS =
"<put license parameters here>";
EncryptedLicenseProvider provider = new EncryptedLicenseProvider();
_license = provider.ValidateLicenseKey(LICENSE_PARAMETERS, licenseKey);
if (_license == null)
{
// or you could throw an exception
MessageBox.Show("Invalid License Key");
}
}
// check the license and throw and exception if it is not licensed
//
private static void CheckLicense()
{
// if there is no license then allow for an evaluation
//
if (_license == null)
{
EvaluationMonitor evaluationMonitor = new RegistryEvaluationMonitor("MyClassEvaluationPassword");
if (evaluationMonitor.DaysInUse > 30)
throw new LicenseException(typeof(MyClass), null, "Evaluation License Expired");
}
}
// an example method which checks the license before doing something
//
public static void DoSomething()
{
CheckLicense();
}
} |
_________________ Infralution Support |
|
Back to top |
|
|
|