DeployLX Software Protection System

LicenseServer..::..Validate Method (ServerRequestContext, Boolean)

Performs remote validation for a LicenseServerLimit.

Syntax

Protected Overridable Function Validate ( _
	context As ServerRequestContext, _
	autoValidate As Boolean _
) As Boolean
protected virtual bool Validate(
	ServerRequestContext context,
	bool autoValidate
)

Parameters

context
Reference to a ServerRequestContext for the current request.
autoValidate
Indicates if the request was generated automatically because AutoValidate is true.

Return Value

Returns true if the validation was successful, otherwise false.

Remarks

Caution This method should never be called directly. Instead add a LicenseServerLimit to a SecureLicense.

The default implementation simply determines if the LicenseServerLimit that initiated the request has the IsPeriodic property set to true. If the license is a periodic license and the license is valid, the license is renewed for the specified renewal period.

In more complex scenarios you could perform custom logic to determine if the license is still valid such as storing a value in a database that indicates if a specific serial number should be disabled. This is the behavior of the implementation generated by the wizard.

Note If you make changes to the original license that should be sent back to the client you must call NotifyModification(Limit) to ensure those changes are sent.

Values of the Properties Collection

VariableDescription
MachineProfile The client machine's profile hash. Same as passed in the machineProfileHash parameter.
MachineProfile.Absolute The client machine's profile hash. The actual profile of the machine if the MachineProfile entry was overridden.
LicensedType The full name of the Type being validated including namespace.
LicensedAssemblyThe full name of the assembly being validated.
LicensedAssemblyNameThe display (or short) name of the assembly being validated. Does not include the version or culture information.
LicensedAssemblyVersionThe version of the assembly being validated.
IsServiceRequestIndicates if the validating process is a Windows service or an ASP.NET XML Web Service.
IsWebRequestIndicates if the validating process is an ASP.NET application (but not an ASP.NET XML Web Service).
IsManagerRequestIndicates if the request originated from the DeployLX Manager and not from the client machine.
* Additional values may be included by the limit that initiated the request. Check the documentation of the limit to see if any other values can be included with the server request.

Examples

This sample demonstrates a very basic implementation of a license server's Validate method. For complete information on license servers see the License Servers in DeployLX Licensing topic.

Visual Basic
<%@ WebService Language="VB"  Class="MyLicenseServer" %>
Imports System
Imports System.IO
Imports System.Collections
Imports DeployLX.Licensing.v5
Imports DeployLX.Licensing.Management.v5

<System.Web.Services.WebService(Namespace:="http://www.xheo.com/licensing/v3_0")> _
Public Class MyLicenseServer
    Inherits DeployLX.Licensing.Management.v5.LicenseServer

...

    Protected Overrides Function Validate(ByVal context As ServerRequestContext) As Boolean
        If (Not MyBase.Validate(context)) Then
            Return False
        End If

        Select Case context.LicensedAssemblyName
            Case "DeployLX.Licensing.Management.v5"
                ' Check if the serial number has been disabled.
                If FileContains("DisabledSerials.dat", context.SerialNumber) Then
                    Return False
                End If
            Case "DeployLX.Licensing.v5"
                Return True
        End Select

        Return True
    End Function

...

    Private Shared Sub AddToFile(ByVal path As String, ByVal serialNumber As String)
        If FileContains(path, serialNumber) Then
            Return
        End If

        Using writer As New StreamWriter(path, True)
            writer.WriteLine(serialNumber)
        End Using
    End Sub

    Private Shared Function FileContains(ByVal path As String, ByVal serialNumber As String) As Boolean
        Using reader As New StreamReader(path)

            Dim line As String = reader.ReadLine()
            If line.Contains(serialNumber) Then
                Return True
            End If
        End Using

        Return False
    End Function
End Class
C#
<%@ WebService Language="C#"  Class="MyLicenseServer" %>
using System;
using System.IO;
using System.Collections;
using DeployLX.Licensing.v5;
using DeployLX.Licensing.Management.v5;

[System.Web.Services.WebService( Namespace="http://www.xheo.com/licensing/v3_0" ) ]
public class MyLicenseServer : DeployLX.Licensing.Management.v5.LicenseServer
{

...

    protected override bool Validate( ServerRequestContext context )
    {
        if( !base.Validate( context ) )
            return false;

        switch( context.LicensedAssemblyName )
        {
            case "DeployLX.Licensing.Management.v5":
                // Check if the serial number has been disabled.
                if( FileContains( "DisabledSerials.dat", context.SerialNumber ) )
                    return false;
                break;
            case "DeployLX.Licensing.v5":
                return true;
        }

        return true;
    }

...

    private static void AddToFile( string path, string serialNumber )
    {
        if( FileContains( path, serialNumber ) )
            return;

        using( StreamWriter writer = new StreamWriter( path, true ) )
            writer.WriteLine( serialNumber );
    }

    private static bool FileContains( string path, string serialNumber )
    {
        using( StreamReader reader = new StreamReader( path ) )
        {

            string line = reader.ReadLine();
            if( line.Contains( serialNumber ) )
                return true;
        }

        return false;
    }
}

Assembly:  DeployLX.Licensing.Management.v5 (in DeployLX.Licensing.Management.v5.dll)

See Also