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 

LicenseInstallForm

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



Joined: 26 Apr 2005
Posts: 6

PostPosted: Tue Apr 26, 2005 4:21 pm    Post subject: LicenseInstallForm Reply with quote

I have created Demo application in which on the Windows Form i placed several classes from my product. When i start demo application, LicenseInstallForm is shown several times (depending on number of protected classes on the Form).

Is there any solution to this problem? I want the LicenseInstallForm to be shown only one time no matther how many classes are placed on the Form.
Back to top
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Apr 26, 2005 10:15 pm    Post subject: Reply with quote

If you have multiple classes and you only want the licensing message to appear once then you need to put the licensing code in a single shared method (eg CheckLicense) which you then call from each of the class constructors. The shared method should use a shared member variable to hold the license – so it can check if the license has already been obtained.

You can either place the shared method and member variable in one of your three existing classes (if one of them is the main class for your product then this might make sense) or you can create a separate class/module whose job is just to check the licensing.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Andrej



Joined: 26 Apr 2005
Posts: 6

PostPosted: Wed Apr 27, 2005 8:19 am    Post subject: LicenseInstallForm Reply with quote

Hi,

Thank you for the Tip. The problem is resolved and everything goes fine.
Back to top
View user's profile Send private message Visit poster's website
codenut



Joined: 13 Apr 2005
Posts: 12
Location: Ontario Canade

PostPosted: Sat Apr 30, 2005 7:33 pm    Post subject: Reply with quote

Infralution wrote:
You can either place the shared method and member variable in one of your three existing classes (if one of them is the main class for your product then this might make sense) or you can create a separate class/module whose job is just to check the licensing.


Is there anywy we could get a sample of how this would work as I am having problems getting the licensing to work with a control. The DLL contains three seperate classes and no "forms". I have got it to the point where the license will work in design time but when you run the test app the "Using un-registered" dialog still shows.

Also when you create a control with licensing does the end user developer have to include the "license" file as part of their distribution ?? I wouldn't think so but would like some clarification on this.
_________________
Steven
WinExtra
http://www.winextra.com
news://news.winextra.com
Back to top
View user's profile Send private message Visit poster's website
Andrej



Joined: 26 Apr 2005
Posts: 6

PostPosted: Sun May 01, 2005 10:46 am    Post subject: LicenseInstallForm Reply with quote

1. You have to make a new class (example: LicensingClass) in which you need to have:
- static member variable for holding license
- static member variable (bool) for testing whether the LicenseInstallForm is already shown to

prevent multiple appearance of this Form
- static method with license testing

From each class that you want to protect you would have to include in constructor a call to the static

method. In this way the LicenseInstallForm will shown only once in DesingTime and once in RunTime,

independently of how many classes you place on the Form.

public class LicensingClass
{
........

static License _license = null;
static bool formShown = false;

public static bool CheckLicense(Control ctrl)
{
if (_license == null)
{
EncryptedLicenseProvider.SetParameters(_licenseParameters);
if (!LicenseManager.IsValid(typeof(ctrl), this, out _license))
{
if (!formShown)
{
formShown = true;
LicenseInstallForm form = new LicenseInstallForm();
form.ShowDialog("MyControl", "www.mycompany.com", typeof(ctrl));
}

if (_license == null)
return false;
}
}

return true;
}

.....
}

2. The end user don't need to include the license fill as part of their distribution. This is already

taken when the classes are placed on the Form. In the licenses.licx file is created information for

licensed classes and this file is already embeded in the project.
Back to top
View user's profile Send private message Visit poster's website
codenut



Joined: 13 Apr 2005
Posts: 12
Location: Ontario Canade

PostPosted: Sun May 01, 2005 3:50 pm    Post subject: Re: LicenseInstallForm Reply with quote

Andrej wrote:
1. You have to make a new class (example: LicensingClass) in which you need to have


When I try this following the example (in vb.net) I get the following errors:
- Type ctrl is not defined
- Me is valid only within as instance method

This is the beginning of the function
==============================
Public Shared Function DoCheck(ByVal ctrl As Control) As Boolean

If _license Is Nothing Then
EncryptedLicenseProvider.SetParameters(_licenseParameters)
If Not LicenseManager.IsValid(GetType(ctrl), Me, _license) Then

End If
End If
End Function
===============================

Andrej wrote:

2. The end user don't need to include the license fill as part of their distribution. This is already

taken when the classes are placed on the Form. In the licenses.licx file is created information for

licensed classes and this file is already embeded in the project.


that's what I thought - thanks Very Happy
_________________
Steven
WinExtra
http://www.winextra.com
news://news.winextra.com
Back to top
View user's profile Send private message Visit poster's website
Andrej



Joined: 26 Apr 2005
Posts: 6

PostPosted: Mon May 02, 2005 9:31 am    Post subject: Reply with quote

Sorry, my mistake.

public class LicensingClass
{
........

static License _license = null;
static bool formShown = false;

public static bool CheckLicense(Control ctrl)
{
if (_license == null)
{
EncryptedLicenseProvider.SetParameters(_licenseParameters);
if (!LicenseManager.IsValid(ctrl.GetType(), ctrl, out _license))
{
if (!formShown)
{
formShown = true;
LicenseInstallForm form = new LicenseInstallForm();
form.ShowDialog("MyControl", "www.mycompany.com",

ctrl.GetType());
}

if (_license == null)
return false;
}
}

return true;
}

.....
}

The parametar ctrl is control class that you want to protect. Example if in your project have two control classes that you want to protect then you need to do these steps:

1. Construct the LicensingClass as stated above
2. Construct a control named SampleClass1
3. In the constructor as a first line enter following

if (!LicensingClass.CheckLicense(this))
MessageBox.Show("The Control has not valid license");

Depending on the result you may enter Exceptions or Messages or additional checking.

4. Repeat steps 2 to 4 for the second control
Back to top
View user's profile Send private message Visit poster's website
codenut



Joined: 13 Apr 2005
Posts: 12
Location: Ontario Canade

PostPosted: Tue May 03, 2005 8:39 pm    Post subject: Reply with quote

Andrej wrote:

The parametar ctrl is control class that you want to protect. Example if in your project have two control classes that you want to protect then you need to do these steps:

1. Construct the LicensingClass as stated above
2. Construct a control named SampleClass1
3. In the constructor as a first line enter following


this is giving me grey hair Very Happy but for some reason I just can't seemt to get this to work

This is my LicenseChecker.vb:
===================================
<LicenseProvider(GetType(EncryptedLicenseProvider))> _
Public Class LicenseChecker
public Const _licenseParameters As String = _
<snip>"

Public Shared _license As License = Nothing
Public Shared formShown As Boolean = False

Public Shared Function DoCheck(ByVal ctrl As Control) As Boolean
Try
If _license Is Nothing Then
MsgBox("Nothing")
EncryptedLicenseProvider.SetParameters(_licenseParameters)
If Not LicenseManager.IsValid(ctrl.GetType(), ctrl, _license) Then
MsgBox("Not Valid")
If Not formShown Then
Dim form As New LicenseInstallForm
_license = form.ShowDialog("WinExtra Clocks Control", "www.winextra.com", ctrl.GetType())
formShown = True
End If
If _license Is Nothing Then
MsgBox("License is nothing")
Return False
End If
End If
Else
Return True
End If
Catch ex As Exception
MsgBox(ex.Message & vbNewLine & ex.StackTrace.ToString)
End Try

End Function
===============================

This is the "common" class you suggested adding as it would be the "neutral" license checking class

CheckerClass.vb
==================================

Public Class CheckerClass
Inherits Panel
Public Sub New()
If Not LicenseChecker.DoCheck(Me) Then
MsgBox("hmmm")
End If
End Sub
End Class
===================================

And it is called in the actual control class
============================
Public Sub New()
MyBase.New()
Dim c As CheckerClass = New CheckerClass
end sub
=============================

Now the first MsgBox in Docheck gets fired and the MsgBox in ChackerClass gets fired but the other two in in DoCheck never fire

Now there is a very good chance that I am just not understanding this process correctly but any help would be appreciated
_________________
Steven
WinExtra
http://www.winextra.com
news://news.winextra.com


Last edited by codenut on Tue May 03, 2005 11:06 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue May 03, 2005 10:59 pm    Post subject: Reply with quote

Looks like your DoCheck function is missing a return statement when LicenseManager.IsValid returns true. VB will return false by default if there is no return statement in a code path - which in this case is not correct.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
codenut



Joined: 13 Apr 2005
Posts: 12
Location: Ontario Canade

PostPosted: Tue May 03, 2005 11:08 pm    Post subject: Reply with quote

Infralution wrote:
Looks like your DoCheck function is missing a return statement when LicenseManager.IsValid returns true. VB will return false by default if there is no return statement in a code path - which in this case is not correct.


maybe .. but the problem I am having is that the LicenseForm isn't displaying

and sory about the non-wrapping .. Smile I fixed it
_________________
Steven
WinExtra
http://www.winextra.com
news://news.winextra.com
Back to top
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed May 04, 2005 2:54 am    Post subject: Reply with quote

Well that would be because LicenseManager.IsValid is returning true ie you do have a valid license installed. Try deleting the ".lic" file (typically in the bin directory containing your control). Depending on how you referenced the control dll there may be more than one ".lic" file floating around.

You can also debug the code to see what is happening by starting another instance of Visual Studio and attaching to the instance of Studio that is displaying your control/components in the designer.
_________________
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