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 

Control licensing in Evaluation mode

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



Joined: 10 Jan 2019
Posts: 23

PostPosted: Wed Jan 23, 2019 10:39 am    Post subject: Control licensing in Evaluation mode Reply with quote

While trying out some Authenticated Licensing scenarios I came across the situation where a trial user of my control (in Evaluation mode) can develop and distribute apps where in the apps run without any nags since the embedded runtime license checks out fine. Is there any way to know that the embedded runtime license was generated in Evaluation mode?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jan 23, 2019 10:38 pm    Post subject: Reply with quote

You need to set the current license context to a DesigntimeLicenseContext and then check whether the license is valid. If you have associated the AuthenticatedLicenseProvider with your component type (using the LicenseProviderAttribute) then you can do this with the following code:

Code:
LicenseManager.CurrentContext = new DesigntimeLicenseContext();
 bool isDesignTimeLicensed = LicenseManager.IsValid(typeof(MyComonentType));


This will check for a license key and ensure that only design time keys will be valid.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
santosh



Joined: 10 Jan 2019
Posts: 23

PostPosted: Thu Jan 24, 2019 3:41 am    Post subject: Reply with quote

After the suggested change this works fine for the case where an evaluation mode design time grants a runtime license - I see a prompt saying the app was developed using an unlicensed version of the control.

However now when the app is built on an authorized machine (valid license installed) the app runs fine on the same machine but is throwing the prompt saying the app was developed using an unlicensed version of the control when it's run on a different machine. I suspect it's looking for the .lic file even for runtime check.

Below is the code I am using in the control ctor:



Code:

public TestILSControl()
{
      InitializeComponent();

      // Is the control being displayed in the designer?
      //
      if (LicenseManager.CurrentContext.UsageMode == LicenseUsageMode.Designtime)
      {
            // at design time we must check the license every time or else our license may not
            // get compiled into the application resources
            //
            if (!LicenseManager.IsLicensed(typeof(TestILSControl)))
            {
                  // only show the evaluation dialog if we haven't already done so for this form
                  //
                  if (LicenseManager.CurrentContext != _lastDesignContext)
                  {
                        // Display the evaluation dialog until the user installs a license or
                        // selects Exit or Continue
                        //
                        AuthenticatedLicense license = null;
                        while (license == null)
                        {
                              EvaluationMonitor evaluationMonitor = new RegistryEvaluationMonitor("MyControlEvaluationPassword");
                              EvaluationDialog evaluationDialog = new EvaluationDialog();
                              EvaluationDialogResult dialogResult = evaluationDialog.ShowDialog(evaluationMonitor, PRODUCT_NAME);
                              if (dialogResult == EvaluationDialogResult.Exit)
                              {
                                    throw new LicenseException(typeof(TestILSControl), this, "Control not Licensed");
                              }
                              if (dialogResult == EvaluationDialogResult.Continue)
                              {
                                    break; // exit the loop
                              }
                              if (dialogResult == EvaluationDialogResult.InstallLicense)
                              {
                                    var licenseForm = new AuthenticatedLicenseInstallForm();
                                    license = licenseForm.ShowDialog(new TestILSControlLicenseProvider(), license, PRODUCT_NAME);
                              }
                        }
                        _lastDesignContext = LicenseManager.CurrentContext;
                  }
            }
      }
      else
      {
            // at runtime only check the license if we haven't already done so
            //
            if (!_licenseChecked)
            {
                  // show a nag screen if the control is not licensed
                  //
                  LicenseManager.CurrentContext = new DesigntimeLicenseContext();
                  if (!LicenseManager.IsLicensed(typeof(TestILSControl)))
                  {
                        MessageBox.Show("This application was created using an unlicensed version of " + PRODUCT_NAME, "Unlicensed Control");
                  }
            }
      }
      _licenseChecked = true;
}
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jan 25, 2019 3:16 am    Post subject: Reply with quote

This type of issue typically means that the license has not been compiled into the resources of the application that is using the DLL. You can check this using ILSpy to look at the application resources. You should be able to see resource called "MyApplication.exe.licenses" (where MyApplication is the name of your application). You can save this file and open it using a binary editor to see if it contains your license key. See the following thread for detail about how to manually add a component license if required (this is for one of our products but the process should be the same)

http://www.infralution.com/phpBB2/viewtopic.php?t=1581&highlight=licx
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
santosh



Joined: 10 Jan 2019
Posts: 23

PostPosted: Fri Jan 25, 2019 5:37 am    Post subject: Reply with quote

I tried this scenario again from scratch and the results are still the same. As stated earlier the evaluation mode works as expected (nag popup is shown when the app is built using my control in evaluation mode) after making the suggested change (setting LicenseManager.CurrentContext to DesigntimeLicenseContext).

However making this change is breaking the case where the app is developed using a properly licensed control. Now the app runs fine on the same developer machine but shows the nag popup when run on another machine. If I remove that suggested line then the nag is not shown anymore (however it is also not shown for evaluation mode license which was the original issue). I have checked that licenses.licx file exists in the app project and I have also verified that the generated EXE contains the embedded resource <app>.exe.licenses file using ILSpy.

Please correct me if I am wrong but as per my understanding we are forcing the control to check for a design-time license by changing the context in runtime.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jan 25, 2019 6:46 am    Post subject: Reply with quote

Sorry I think I misread your original question. Why does a user in evaluation mode have a license in the first place to be able to generate a runtime license from? This is really the problem.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
santosh



Joined: 10 Jan 2019
Posts: 23

PostPosted: Fri Jan 25, 2019 6:50 am    Post subject: Reply with quote

Infralution wrote:
Sorry I think I misread your original question. Why does a user in evaluation mode have a license in the first place to be able to generate a runtime license from? This is really the problem.


I want to be able to allow trial usage of our controls so that developers can create apps with them for evaluation. However such apps should show a nag popup - for this we need to know at runtime that the encrypted license was generated in evaluation mode (at design time).
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jan 25, 2019 6:59 am    Post subject: Reply with quote

Normally you allow developers to run without a license (in evaluation mode) for a fixed period of time. Since they don't have license no runtime key will be generated and installed in the application resources. At runtime if there is no license key installed then you should display a nag screen that says "This application was developed using an Evaluation Version of MyProduct"
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
santosh



Joined: 10 Jan 2019
Posts: 23

PostPosted: Fri Jan 25, 2019 7:09 am    Post subject: Reply with quote

Yes, that is my understanding as well but what I found is that the app generated using evaluation seems to be passing the runtime license check. The following code in the control ctor is not showing the nag screen:

Code:

// at runtime only check the license if we haven't already done so
//
if (!_licenseChecked)
{
   // show a nag screen if the control is not licensed
   //
   if (!LicenseManager.IsLicensed(typeof(TestILSControl)))
   {
      MessageBox.Show("This application was created using an unlicensed version of " + PRODUCT_NAME, "Unlicensed Control");
   }
}


Not sure why this was happening. I did notice that when I tried this the evaluation dialog showed up at design time when the app was being built so the code was being invoked by the license compiler. I will try this scenario again and verify the behavior.
Back to top
View user's profile Send private message
santosh



Joined: 10 Jan 2019
Posts: 23

PostPosted: Fri Jan 25, 2019 11:53 am    Post subject: Reply with quote

I am happy to report that the evaluation scenario is working as expected. I am really not sure what happened earlier. I was trying a couple of things (deleting the .lic file to simulate a deauthentication, etc.). and something probably got messed up. Sorry for the trouble!
Back to top
View user's profile Send private message
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