|
Infralution Support Support groups for Infralution products
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Posted: Wed May 10, 2006 9:25 am Post subject: Licensing controls in VB.NET |
|
|
Good morning
We are developing a library of controls.
We translated to VB.NET and followed instructions from "Can I license all the controls in a library with one key?", but does not seems to work properly.
Colud you please explain in detail this approach and/or provide a complete sample (with the use of ControlLicenseProvider class)?
Sorry if this questions seems to be repetitive. We read all forum and FAQ without results
Thank you |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed May 10, 2006 11:27 pm Post subject: |
|
|
When you say "but does not seems to work properly" what exactly do you mean? Are you getting errors - or are there other issues? _________________ Infralution Support |
|
Back to top |
|
|
Guest
|
Posted: Thu May 11, 2006 6:49 am Post subject: |
|
|
Hello, thank you for replying.
This line is not accepted:
Code: |
license = form.ShowDialog(controlType);
|
...so, I translated to:
Code: |
license = form.ShowDialog("MyProduct", "MyWeb", controlType)
|
After a better examination of the code and some corrections, now it seems to work.
However, I have some questions...
This is the translated code:
Code: |
<LicenseProvider(GetType(EncryptedLicenseProvider))> _
Public Class SuperPanel
Inherits BaseContainer
Public Sub New()
MyBase.New()
InitializeComponent()
Licensing.ControlLicenseProvider.CheckLicense(GetType(SuperPanel), Me)
End Sub
|
Code: |
Friend Class ControlLicenseProvider
Inherits EncryptedLicenseProvider
Private Sub New()
End Sub
Const LICENSE_PARAMETERS As String = "..."
Private Shared mExpired As Boolean = False
Private Shared mLicenseChecked As Boolean = False
Private Shared mDesignContext As LicenseContext
Public Shared Sub CheckLicense(ByVal controlType As Type, ByVal control As Object)
Dim license As License = Nothing
If LicenseManager.CurrentContext.UsageMode = LicenseUsageMode.Designtime Then
EncryptedLicenseProvider.SetParameters(LICENSE_PARAMETERS)
If Not LicenseManager.IsValid(controlType, control, license) Then
If Not (mDesignContext Is LicenseManager.CurrentContext) Then
Dim form As New LicenseInstallForm
license = form.ShowDialog("MyProduct", "MyWeb", controlType)
If license Is Nothing Then
Dim monitor As New EvaluationMonitor("MyEvalPassword")
If monitor.DaysInUse > 30 OrElse monitor.Invalid Then
mExpired = True
End If
End If
mDesignContext = LicenseManager.CurrentContext
End If
End If
Else
If Not mLicenseChecked Then
EncryptedLicenseProvider.SetParameters(LICENSE_PARAMETERS)
If Not LicenseManager.IsValid(controlType, control, license) Then
MessageBox.Show("Evaluation Version", "This application was created using an unlicensed version of MyControls")
End If
End If
End If
If mExpired Then
Throw New LicenseException(controlType, control, "Your evaluation license is no longer valid")
End If
mLicenseChecked = True
End Sub
Protected Overrides Function GetLicenseFilePath(ByVal context As LicenseContext, ByVal type As Type) As String
Dim dir As String = GetLicenseDirectory(context, type)
Return dir & "\MyComponentsLibrary.lic"
End Function 'GetLicenseFilePath
End Class
|
Q1: Is the translated VB.NET code correct?
Q2: Since CheckLicense doe not returns any value, what is the best way to tell to the SuperPanel constructor that it is licensed/not licensed and continue/abort execution?
Q3: I've found a file named MyNamespace.SuperPanelLicense.lic in the control's obj\debug folder. Who set that name? Why it is not named MyComponentsLibrary.lic? Why it is in the control's obj folder and not in obj folder of the testing project?
Thank you very much. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu May 11, 2006 8:27 am Post subject: |
|
|
Quote: | Q1: Is the translated VB.NET code correct? |
A bit difficult to tell by just inspection - but it looks OK provided you do remember to actually put in your real LICENSE_PARAMETERS.
Quote: | Q2: Since CheckLicense doe not returns any value, what is the best way to tell to the SuperPanel constructor that it is licensed/not licensed and continue/abort execution? |
This code throws a LicenseException if the control is not licensed and the evaluation period has been exceeded - which is probably the best way to handle this for controls.
Quote: | Q3: I've found a file named MyNamespace.SuperPanelLicense.lic in the control's obj\debug folder. Who set that name? Why it is not named MyComponentsLibrary.lic? Why it is in the control's obj folder and not in obj folder of the testing project? |
Your control class still has a LicenseProvider attribute that refers to the original EncryptedLicenseProvider class you need to change this to:
Code: | <LicenseProvider(GetType(ControlLicenseProvider))> _ |
_________________ Infralution Support |
|
Back to top |
|
|
Guest
|
Posted: Thu May 11, 2006 2:55 pm Post subject: |
|
|
I don't know what I'm doing wrong, but LicenseManager.IsValis always returns False after entering a VALID Key.
This is the code:
Code: |
<LicenseProvider(GetType(ControlLicenseProvider))> _
Public Class SuperPanel
Inherits ContainerControl
Public Sub New()
MyBase.New()
Licensing.ControlLicenseProvider.CheckLicense(GetType(SuperPanel), Me)
End Sub
End Class
|
Code: |
Friend Class ControlLicenseProvider
Inherits EncryptedLicenseProvider
Const LICENSE_PARAMETERS As String = "<LicenseParameters>..."
Private Shared mExpired As Boolean = False
Private Shared mLicenseChecked As Boolean = False
Private Shared mDesignContext As LicenseContext
Friend Shared Sub CheckLicense(ByVal controlType As Type, ByVal control As Object)
Dim license As License = Nothing
If LicenseManager.CurrentContext.UsageMode = LicenseUsageMode.Designtime Then
EncryptedLicenseProvider.SetParameters(LICENSE_PARAMETERS)
If Not LicenseManager.IsValid(controlType, control, license) Then
If Not (mDesignContext Is LicenseManager.CurrentContext) Then
Dim form As New LicenseInstallForm
license = form.ShowDialog("MyProduct", controlType)
If license Is Nothing Then
Dim monitor As New EvaluationMonitor("MyEvalPassword")
If monitor.DaysInUse > 30 OrElse monitor.Invalid Then
mExpired = True
End If
End If
mDesignContext = LicenseManager.CurrentContext
End If
End If
Else
If Not mLicenseChecked Then
EncryptedLicenseProvider.SetParameters(LICENSE_PARAMETERS)
If Not LicenseManager.IsValid(controlType, control, license) Then
MessageBox.Show("Evaluation Version", "This application was created using an unlicensed version of MyControls")
End If
End If
End If
If mExpired Then
Throw New LicenseException(controlType, control, "Your evaluation license is no longer valid")
End If
mLicenseChecked = True
End Sub
Protected Overrides Function GetLicenseFilePath(ByVal context As LicenseContext, ByVal type As Type) As String
Dim dir As String = GetLicenseDirectory(context, type)
Return dir & "\MyComponentsLibrary.lic"
End Function
End Class
|
After entering a valid Key:
- I found MyNamespace.SuperPanel.lic in obj\Debug folder of control project
- I found Testing.exe.licenses in obj\Debug folder of test project
- I found licenses.licx in obj\Debug folder of test project
I've NOT found the specified MyComponentsLibrary.lic.
What's wrong? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu May 11, 2006 10:42 pm Post subject: |
|
|
The problem is that the LicenseInstallForm does not know that you are using a specialized version of an EncryptedLicenseProvider - so it is still using the default EncryptedLicenseProvider class - and so is installing the license in the incorrect location. To fix this simply set the LicenseProvider property of the LicenseInstallForm eg
Code: | Dim form As New LicenseInstallForm
form.LicenseProvider = new ControlLicenseProvider
license = form.ShowDialog("MyProduct", controlType) |
_________________ Infralution Support |
|
Back to top |
|
|
Guest
|
Posted: Fri May 12, 2006 6:17 am Post subject: |
|
|
Now it seems to work properly.
Thank you very much. |
|
Back to top |
|
|
|
|
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
|