[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

LicenseProvider Problem

Posted on 2006-04-06
11
Medium Priority
?
470 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:Pigtor
  • 5
  • 5
10 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 16540004
Here is a possibility:

http://www.dotnet247.com/247reference/msgs/53/268999.aspx

I'm able to reproduce this issue, seems the LicenseContext was not set
correctly in copy & paste operation, I'll forward this issue to the product
group to let them know.

In the mean time, I think you may try way to workaround this issue:
1. If you put the license validation code in the constructor of the user
control, remove the License Validation code from the constructor
2. Define a customized LicenseContext class derive from DesigntimeLicenseContext class like below:

<code>
Public Class MyDesignTimeLicenseContext
  Inherits System.ComponentModel.Design.DesigntimeLicenseContext

    Private provider As IDesignerHost
    Public Sub New(ByVal host As IDesignerHost)
        provider = host
    End Sub
    Public Overrides Function GetService(ByVal type As Type) As Object
        Return provider.GetService(type)
    End Function
End Class
</code>

2. Override OnLoad event for you user control , insert the code snippet like below:
<code>
If DesignMode Then
    Dim host As IDesignerHost = CType(Me.GetService(GetType(IDesignerHost), IDesignerHost)
    LicenseManager.CurrentContext = New MyDesignTimeLicenseContext(host)
    _license = LicenseManager.Validate(GetType(MyUserControl), Me)
    LicenseManager.CurrentContext = Nothing
Else
   _license = LicenseManager.Validate(GetType(MyUserControl), Me)
End If
</code>

Bob
0
 
LVL 3

Author Comment

by:Pigtor
ID: 16545502
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16552030
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
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 3

Author Comment

by:Pigtor
ID: 16552838
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?



0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16552878
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
0
 
LVL 3

Author Comment

by:Pigtor
ID: 16552972
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


0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16619615
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
0
 
LVL 3

Author Comment

by:Pigtor
ID: 16621686
Thanks anyway Bob.
I know there is something to do about, but I will try to find out.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16654216
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
0
 
LVL 3

Author Comment

by:Pigtor
ID: 16816917
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.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question