Protected Sub OnCollectionChanged ( _ sender As Object, _ property As String, _ e As CollectionEventArgs _ )
protected void OnCollectionChanged( Object sender, string property, CollectionEventArgs e )
Imports Microsoft.VisualBasic
Imports System
Imports DeployLX.Licensing.v5
Namespace VBProtectedDll
Public Class EnvironmentCheckLimit
Inherits Limit
Public Sub New()
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Checks that an environment variable has been set to a specific value."
End Get
End Property
Public Overrides ReadOnly Property Name() As String
Get
Return "Environment Check"
End Get
End Property
Public Property VariableName() As String
Get
Return _variableName
End Get
Set
AssertNotReadOnly()
If _variableName <> Value Then
_variableName = Value
OnChanged("VariableName")
End If
End Set
End Property
Private _variableName As String
Public Property VariableValue() As String
Get
Return _variableValue
End Get
Set
AssertNotReadOnly()
If _variableValue <> Value Then
_variableValue = Value
OnChanged("VariableValue")
End If
End Set
End Property
Private _variableValue As String
Public Overrides Function Validate(ByVal context As SecureLicenseContext) As ValidationResult
If (Not IsVariableSet(context, True)) Then
Return ValidationResult.Invalid
End If
Return MyBase.Validate(context)
End Function
Public Overrides Function Granted(ByVal context As SecureLicenseContext) As ValidationResult
If (Not IsVariableSet(context, True)) Then
Return ValidationResult.Invalid
End If
Return MyBase.Granted(context)
End Function
Public Overrides Function Peek(ByVal context As SecureLicenseContext) As PeekResult
If (Not IsVariableSet(context, False)) Then
Return PeekResult.Invalid
End If
Return MyBase.Peek(context)
End Function
Protected Overrides Function WriteToXml(ByVal writer As System.Xml.XmlWriter, ByVal signing As LicenseSaveType) As Boolean
If _variableName Is Nothing Then
Return False
End If
If _variableValue Is Nothing Then
Return False
End If
writer.WriteAttributeString("variableName", _variableName)
writer.WriteAttributeString("variableValue", _variableValue)
' Any child limits will automatically be written to the XML.
Return True
End Function
Protected Overrides Function ReadFromXml(ByVal reader As System.Xml.XmlReader) As Boolean
_variableName = reader.GetAttribute("variableName")
_variableValue = reader.GetAttribute("variableValue")
Return ReadChildLimits(reader)
End Function
Protected Function IsVariableSet(ByVal context As SecureLicenseContext, ByVal reportError As Boolean) As Boolean
Try
Dim value As String = Environment.GetEnvironmentVariable(_variableName)
If value Is Nothing OrElse value <> _variableValue Then
If reportError Then
context.ReportError("Environment variable ({0}) missing or not set.", Me, Nothing, ErrorSeverity.Normal, _variableName)
End If
Return False
End If
Return True
Catch ex As Exception
If reportError Then
context.ReportError("Could not check environment.", Me, ex, ErrorSeverity.High)
End If
Return False
End Try
End Function
End Class
End Namespace
using System;
using DeployLX.Licensing.v5;
namespace CSharpProtectedDll
{
public class EnvironmentCheckLimit : Limit
{
public EnvironmentCheckLimit()
{
}
public override string Description
{
get { return "Checks that an environment variable has been set to a specific value."; }
}
public override string Name
{
get { return "Environment Check"; }
}
public string VariableName
{
get { return _variableName; }
set {
AssertNotReadOnly();
if( _variableName != value )
{
_variableName = value;
OnChanged( "VariableName" );
}
}
}
private string _variableName;
public string VariableValue
{
get { return _variableValue; }
set {
AssertNotReadOnly();
if( _variableValue != value )
{
_variableValue = value;
OnChanged( "VariableValue" );
}
}
}
private string _variableValue;
public override ValidationResult Validate( SecureLicenseContext context )
{
if( !IsVariableSet( context, true ) )
return ValidationResult.Invalid;
return base.Validate( context );
}
public override ValidationResult Granted( SecureLicenseContext context )
{
if( !IsVariableSet( context, true ) )
return ValidationResult.Invalid;
return base.Granted( context );
}
public override PeekResult Peek( SecureLicenseContext context )
{
if( !IsVariableSet( context, false ) )
return PeekResult.Invalid;
return base.Peek( context );
}
protected override bool WriteToXml( System.Xml.XmlWriter writer, LicenseSaveType signing )
{
if( _variableName == null )
return false;
if( _variableValue == null )
return false;
writer.WriteAttributeString( "variableName", _variableName );
writer.WriteAttributeString( "variableValue", _variableValue );
// Any child limits will automatically be written to the XML.
return true;
}
protected override bool ReadFromXml( System.Xml.XmlReader reader )
{
_variableName = reader.GetAttribute( "variableName" );
_variableValue = reader.GetAttribute( "variableValue" );
return ReadChildLimits( reader );
}
protected bool IsVariableSet( SecureLicenseContext context, bool reportError )
{
try
{
string value = Environment.GetEnvironmentVariable( _variableName );
if( value == null || value != _variableValue )
{
if( reportError )
context.ReportError( "Environment variable ({0}) missing or not set.", this, null, ErrorSeverity.Normal, _variableName );
return false;
}
return true;
}
catch( Exception ex )
{
if( reportError )
context.ReportError( "Could not check environment.", this, ex, ErrorSeverity.High );
return false;
}
}
}
}
Assembly: DeployLX.Licensing.v5 (in DeployLX.Licensing.v5.dll)