PLUSManagedGui: Initializing the Component

After adding PLUSManagedGui to your application, the next step is to initialize the component. If the component is not initialized correctly, any attempt to use PLUSManagedGui while your application is running will result in an error message being displayed.

Important

Throughout this section of the manual, the SampleLicense class is referenced. This class and its supporting classes are re-used from the sample applications.

C#
private bool m_LastLicenseValidationResult = false;
private SampleLicense m_License;

public MainForm()
{
InitializeComponent();
m_License = new SampleLicense(licensingGui1);
licensingGui1.ApplicationLicense = (License)m_License;
}
VB.NET
Private m_LastLicenseValidationResult As Boolean = False
Private m_License As SampleLicense

Public Sub New()
InitializeComponent()
m_License = New SampleLicense(licensingGui1)
licensingGui1.ApplicationLicense = m_License
End Sub

In the example above, the SampleLicense class constructor receives and stores the reference to the PLUSManagedGui component.  This allows your license implementation logic to leverage some of the features in PLUSManagedGui. For example, this will allow your license implementation class to automatically obtain proxy authentication credentials from a user when required for web service calls.

The next noteworthy part of the above code example is that the ApplicationLicense property is initialized and points to your license implementation object. This step is required by PLUSManagedGui, and an error will be displayed if it is omitted.

License File Path

In order to access your license file, you will need to make your code aware of the location of the license file. The example code below shows how you can add a property to your form which assumes the license file is located in the same directory as your application (or your .EXE file).

C#
internal static string LicenseFilePath
{
get { return Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "LicenseFile.xml"); }
}
VB.NET
Friend Shared ReadOnly Property LicenseFilePath() As String
Get
Return Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "LicenseFile.xml")
End Get
End Property

Of course, when you select a final path for your application's license files, you will need to be considerate of permissions during deployment or installation of your application.

Initializing the License

Once the objects have been initialized per the instructions above, the next step is to initialize the license by loading and validating it as shown below.

C#
m_LastLicenseValidationResult = m_License.LoadFile(LicenseFilePath);
if (m_LastLicenseValidationResult)
m_LastLicenseValidationResult = m_License.Validate();
VB.NET
m_LastLicenseValidationResult = m_License.LoadFile(LicenseFilePath)
If (m_LastLicenseValidationResult) Then
m_LastLicenseValidationResult = m_License.Validate()
End If

This code can be called as the last step in your form's constructor, or it may be called while your splash screen is loading (if your application is configured to periodically communicate with SOLO Server).