Link to home
Start Free TrialLog in
Avatar of Pigtor
PigtorFlag for Mexico

asked on

LicenseProvider Problem

Hello Experts,
I'm developing a user control in VB.NET 2003, using a LicenseProvider Class to validate the license code.
Everything works fine when I drag and drop the control from the Toolbox Window to the Designer Form.
But the problem is copy and paste.  When I copy and paste the control, the designer doesn't paste anything.
What is wrong? and how can I solve this problem?


-------------------------------------------------------------------------------------------------------------

'The class that handles the license validation
Friend Class MyLicenser
     Inherits System.ComponentModel.LicenseProvider
     ...
   
   Public Overrides Function GetLicense(ByVal context As System.ComponentModel.LicenseContext, ByVal [type] As System.Type, ByVal instance As Object, ByVal allowExceptions As Boolean) As System.ComponentModel.License
     ....
    'Returns true when the code is validated
   End Function

End Class

---------------------------------------------------------------------------------------------------------------------

'The user control implements the LicenseProviderAttribute attribute:
<LicenseProviderAttribute(GetType(MyLicenser))> Public NotInheritable Class MyUserControl
      ....
     Private _license As License = Nothing
     Public Sub New()
          _license = LicenseManager.Validate(GetType(MyUserControl), Me)
          'An exception is thrown is the code is incorrect.
     End Sub
End Class

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pigtor

ASKER

Thanks Bob, but I have already see that link and I agree with Brock opinion:
"The constructor will always be called and we are guaranteed that the licensing code will get
called. Users could override the On* event and not call the base version and get a free control."

I have tested the OnLoad Event and works fine, but when I create a new UserControl and override the OnLoad event, the control doesn't validate anything.

Do you know any other way to fix this behavior?

I was thinking about implementing a ControlDesigner class.
Using a control designer I can customize the menu that is displayed when the user right clicks the control in the designer, but I don't know how to control the keyboard (CTRL+C, CTRL+V) and the menu Copy and Paste.

'The user control implements the Designer Attribute
<Designer(GetType(MyControlDesigner)), LicenseProviderAttribute(GetType(MyLicenser))> _
Public NotInheritable Class MyUserControl
'....
End Class

'The Designer determines the behavior of the control in design time.
Friend Class MyControlDesigner
     Inherits System.Windows.Forms.Design.ControlDesigner

    Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
         Get
              '.....
         End Get
    End Property
End Class



Thanks

Victor
I don't think that you need to implement a special designer to do that.  I have a 3rd party control as a reference that lets you copy/paste controls without apparently having a control designer, but only a LicenseProvider.  It sounds like a problem with the GetLicense function, but I am not sure what that could be.  

Are you making a call like this in GetLicense?

    text2 = context.GetSavedLicenseKey(type, Nothing)

Bob
Avatar of Pigtor

ASKER

No Bob,  I use a LicenseKey Property that the user can change before creating the control.
The GetLicense method reads that property to determine if the key is correct or incorrect.

Public NotInheritable Class Licenser
           Private Shared mvarKey As String = String.Empty
           Public Shared Property LicenseKey() As String
                    Get
                         Return mvarKey
                    End Get
                    Set(ByVal Value As String)
                         mvarKey = Value
                    End Set
          End Property
End Class

For example:
Dim obj as MyControl
obj.Licenser.LicenseKey="123"
obj = New MyControl

What do you recommend?



I think that I am starting to see the problem.  When you copy/paste, you are instantiating a control, without setting the LicenseKey, and so the control doesn't validate.  I would think that you would need to do some fancy footwork to get the LicenseKey property from the control when pasting and instantiating a new control.

Bob
Avatar of Pigtor

ASKER

What do you mean with fancy footwork, do you mean writing to disk the key or something like that?
What is the difference between draging the control from the Toolbox, and copy-paste?  One works and the other not, and both doesn't validate.

Victor


Since confession is good for the soul, then I should probably confess that I haven't done that much with the LicenseProvider (just dabbling), so I really have no idea what I mean.  I was hoping that I could find an answer and learn something and help you at the same time.

Bob
Avatar of Pigtor

ASKER

Thanks anyway Bob.
I know there is something to do about, but I will try to find out.
1) Do you have a LicenseManager instance?

2) I found a pretty good article for licensing:

http://windowsforms.net/articles/Licensing.aspx

3) We need to find a way to debugging the licensing portion (if it's possible).

Bob
Avatar of Pigtor

ASKER

That was not the answer I was looking for, because I already don't know how to do It,  but I appreciate your help Bob.