Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Licensing a class

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Licensing Support
View previous topic :: View next topic  
Author Message
PunkOnWheels



Joined: 07 Apr 2010
Posts: 2

PostPosted: Mon May 10, 2010 9:56 am    Post subject: Licensing a class Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon May 10, 2010 11:25 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Licensing Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group