jj: license
This commit is contained in:
parent
70ceeeb51a
commit
54af1a770b
@ -72,6 +72,7 @@
|
|||||||
<Import Include="System.Threading.Tasks" />
|
<Import Include="System.Threading.Tasks" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="LicenseCreator.vb" />
|
||||||
<Compile Include="LicenseFile.vb" />
|
<Compile Include="LicenseFile.vb" />
|
||||||
<Compile Include="LicenseSchema.vb">
|
<Compile Include="LicenseSchema.vb">
|
||||||
<DependentUpon>LicenseSchema.xsd</DependentUpon>
|
<DependentUpon>LicenseSchema.xsd</DependentUpon>
|
||||||
|
|||||||
34
Modules.License/LicenseCreator.vb
Normal file
34
Modules.License/LicenseCreator.vb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
Public Class LicenseCreator
|
||||||
|
Public Shared Function NewUser(Type As UserType, Count As Integer, Optional ValidUntil As Date = Nothing) As LicenseModuleUser
|
||||||
|
Dim oValidUntilSpecified = Not IsNothing(ValidUntil)
|
||||||
|
Dim oTest = IsNothing(ValidUntil)
|
||||||
|
|
||||||
|
Return New LicenseModuleUser() With {
|
||||||
|
.Count = Count,
|
||||||
|
.Type = Type,
|
||||||
|
.Test = oTest,
|
||||||
|
.ValidUntil = ValidUntil,
|
||||||
|
.ValidUntilSpecified = oValidUntilSpecified
|
||||||
|
}
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Shared Function NewModule(Name As String, Users As List(Of LicenseModuleUser), Optional ValidUntil As Date = Nothing) As LicenseModule
|
||||||
|
Dim oUsers = Users.ToArray()
|
||||||
|
Dim oValidUntilSpecified = Not IsNothing(ValidUntil)
|
||||||
|
|
||||||
|
Return New LicenseModule() With {
|
||||||
|
.Name = Name,
|
||||||
|
.Users = oUsers,
|
||||||
|
.ValidUntil = ValidUntil,
|
||||||
|
.ValidUntilSpecified = oValidUntilSpecified
|
||||||
|
}
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Shared Function NewLicense(Modules As List(Of LicenseModule)) As LicenseSchema
|
||||||
|
Dim oModules = Modules.ToArray()
|
||||||
|
|
||||||
|
Return New LicenseSchema With {
|
||||||
|
.Modules = oModules
|
||||||
|
}
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
@ -1,4 +1,5 @@
|
|||||||
Imports System.IO
|
Imports System.IO
|
||||||
|
Imports System.Xml
|
||||||
Imports System.Xml.Serialization
|
Imports System.Xml.Serialization
|
||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
@ -18,6 +19,21 @@ Public Class LicenseFile
|
|||||||
Return oSerializer
|
Return oSerializer
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Public Function TestFileValid(Optional FileName As String = LICENSE_FILENAME) As Boolean
|
||||||
|
Try
|
||||||
|
Dim oSerializer = GetSerializer()
|
||||||
|
Dim oFilePath As String = IO.Path.Combine(Path, FileName)
|
||||||
|
|
||||||
|
Using oReader As New StreamReader(oFilePath),
|
||||||
|
oXmlReader = XmlReader.Create(oReader)
|
||||||
|
Return oSerializer.CanDeserialize(oXmlReader)
|
||||||
|
End Using
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Function LoadFile(Optional FileName As String = LICENSE_FILENAME) As LicenseSchema
|
Public Function LoadFile(Optional FileName As String = LICENSE_FILENAME) As LicenseSchema
|
||||||
Try
|
Try
|
||||||
Dim oSerializer = GetSerializer()
|
Dim oSerializer = GetSerializer()
|
||||||
@ -35,13 +51,27 @@ Public Class LicenseFile
|
|||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Sub SaveFile(License As LicenseSchema, Optional FileName As String = LICENSE_FILENAME)
|
Public Function Serialize(License As LicenseSchema) As Byte()
|
||||||
Try
|
Try
|
||||||
Dim oSerializer = GetSerializer()
|
Dim oSerializer = GetSerializer()
|
||||||
|
|
||||||
Using oStream = New FileStream(FileName, FileMode.Create, FileAccess.Write)
|
Using oStream = New MemoryStream()
|
||||||
oSerializer.Serialize(oStream, License)
|
oSerializer.Serialize(oStream, License)
|
||||||
oStream.Flush()
|
Return oStream.ToArray()
|
||||||
|
End Using
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Sub SaveFile(License As LicenseSchema, Optional FileName As String = LICENSE_FILENAME)
|
||||||
|
Try
|
||||||
|
Dim oBytes = Serialize(License)
|
||||||
|
Dim oFilePath As String = IO.Path.Combine(Path, FileName)
|
||||||
|
|
||||||
|
Using oFileStream = New FileStream(oFilePath, FileMode.Create, FileAccess.Write)
|
||||||
|
oFileStream.Write(oBytes, 0, oBytes.Length)
|
||||||
End Using
|
End Using
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
|
|||||||
@ -12,24 +12,26 @@ Option Strict Off
|
|||||||
Option Explicit On
|
Option Explicit On
|
||||||
|
|
||||||
Imports System.Xml.Serialization
|
Imports System.Xml.Serialization
|
||||||
|
Imports System.ComponentModel
|
||||||
|
Imports System.CodeDom.Compiler
|
||||||
|
|
||||||
'
|
'
|
||||||
'This source code was auto-generated by xsd, Version=4.6.1586.0.
|
'This source code was auto-generated by xsd, Version=4.6.1586.0.
|
||||||
'
|
'
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||||
System.SerializableAttribute(), _
|
Serializable(),
|
||||||
System.Diagnostics.DebuggerStepThroughAttribute(), _
|
DebuggerStepThrough(),
|
||||||
System.ComponentModel.DesignerCategoryAttribute("code"), _
|
DesignerCategory("code"),
|
||||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://tempuri.org/LicenseSchema.xsd"),
|
XmlType(AnonymousType:=True, [Namespace]:="http://tempuri.org/LicenseSchema.xsd"),
|
||||||
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://tempuri.org/LicenseSchema.xsd", IsNullable:=False)>
|
XmlRoot([Namespace]:="http://tempuri.org/LicenseSchema.xsd", IsNullable:=False, ElementName:="License")>
|
||||||
Partial Public Class LicenseSchema
|
Partial Public Class LicenseSchema
|
||||||
|
|
||||||
Private modulesField() As LicenseModule
|
Private modulesField() As LicenseModule
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlArrayItemAttribute("Module", IsNullable:=False)>
|
<XmlArrayItemAttribute("Module", IsNullable:=False)>
|
||||||
Public Property Modules() As LicenseModule()
|
Public Property Modules() As LicenseModule()
|
||||||
Get
|
Get
|
||||||
Return Me.modulesField
|
Return Me.modulesField
|
||||||
@ -41,11 +43,11 @@ Partial Public Class LicenseSchema
|
|||||||
End Class
|
End Class
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||||
System.SerializableAttribute(), _
|
Serializable(),
|
||||||
System.Diagnostics.DebuggerStepThroughAttribute(), _
|
DebuggerStepThrough(),
|
||||||
System.ComponentModel.DesignerCategoryAttribute("code"), _
|
DesignerCategory("code"),
|
||||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")> _
|
XmlType(AnonymousType:=True, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")>
|
||||||
Partial Public Class LicenseModule
|
Partial Public Class LicenseModule
|
||||||
|
|
||||||
Private usersField() As LicenseModuleUser
|
Private usersField() As LicenseModuleUser
|
||||||
@ -57,56 +59,56 @@ Partial Public Class LicenseModule
|
|||||||
Private validUntilFieldSpecified As Boolean
|
Private validUntilFieldSpecified As Boolean
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlArrayItemAttribute("User", IsNullable:=false)> _
|
<XmlArrayItem("User", IsNullable:=False)>
|
||||||
Public Property Users() As LicenseModuleUser()
|
Public Property Users() As LicenseModuleUser()
|
||||||
Get
|
Get
|
||||||
Return Me.usersField
|
Return Me.usersField
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.usersField = value
|
Me.usersField = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlAttributeAttribute()> _
|
<XmlAttribute()>
|
||||||
Public Property Name() As String
|
Public Property Name() As String
|
||||||
Get
|
Get
|
||||||
Return Me.nameField
|
Return Me.nameField
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.nameField = value
|
Me.nameField = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="date")> _
|
<XmlAttribute(DataType:="date")>
|
||||||
Public Property ValidUntil() As Date
|
Public Property ValidUntil() As Date
|
||||||
Get
|
Get
|
||||||
Return Me.validUntilField
|
Return Me.validUntilField
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.validUntilField = value
|
Me.validUntilField = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlIgnoreAttribute()> _
|
<XmlIgnoreAttribute()>
|
||||||
Public Property ValidUntilSpecified() As Boolean
|
Public Property ValidUntilSpecified() As Boolean
|
||||||
Get
|
Get
|
||||||
Return Me.validUntilFieldSpecified
|
Return Me.validUntilFieldSpecified
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.validUntilFieldSpecified = value
|
Me.validUntilFieldSpecified = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||||
System.SerializableAttribute(), _
|
Serializable(),
|
||||||
System.Diagnostics.DebuggerStepThroughAttribute(), _
|
DebuggerStepThrough(),
|
||||||
System.ComponentModel.DesignerCategoryAttribute("code"), _
|
DesignerCategory("code"),
|
||||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")> _
|
XmlType(AnonymousType:=True, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")>
|
||||||
Partial Public Class LicenseModuleUser
|
Partial Public Class LicenseModuleUser
|
||||||
|
|
||||||
Private typeField As UserType
|
Private typeField As UserType
|
||||||
@ -121,70 +123,70 @@ Partial Public Class LicenseModuleUser
|
|||||||
|
|
||||||
Public Sub New()
|
Public Sub New()
|
||||||
MyBase.New
|
MyBase.New
|
||||||
Me.testField = true
|
Me.testField = True
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlAttributeAttribute()> _
|
<XmlAttribute()>
|
||||||
Public Property Type() As UserType
|
Public Property Type() As UserType
|
||||||
Get
|
Get
|
||||||
Return Me.typeField
|
Return Me.typeField
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.typeField = value
|
Me.typeField = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="integer")> _
|
<XmlAttribute(DataType:="integer")>
|
||||||
Public Property Count() As String
|
Public Property Count() As String
|
||||||
Get
|
Get
|
||||||
Return Me.countField
|
Return Me.countField
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.countField = value
|
Me.countField = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlAttributeAttribute(), _
|
<XmlAttribute(),
|
||||||
System.ComponentModel.DefaultValueAttribute(true)> _
|
DefaultValue(True)>
|
||||||
Public Property Test() As Boolean
|
Public Property Test() As Boolean
|
||||||
Get
|
Get
|
||||||
Return Me.testField
|
Return Me.testField
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.testField = value
|
Me.testField = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="date")> _
|
<XmlAttribute(DataType:="date")>
|
||||||
Public Property ValidUntil() As Date
|
Public Property ValidUntil() As Date
|
||||||
Get
|
Get
|
||||||
Return Me.validUntilField
|
Return Me.validUntilField
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.validUntilField = value
|
Me.validUntilField = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.Xml.Serialization.XmlIgnoreAttribute()> _
|
<XmlIgnore()>
|
||||||
Public Property ValidUntilSpecified() As Boolean
|
Public Property ValidUntilSpecified() As Boolean
|
||||||
Get
|
Get
|
||||||
Return Me.validUntilFieldSpecified
|
Return Me.validUntilFieldSpecified
|
||||||
End Get
|
End Get
|
||||||
Set
|
Set
|
||||||
Me.validUntilFieldSpecified = value
|
Me.validUntilFieldSpecified = Value
|
||||||
End Set
|
End Set
|
||||||
End Property
|
End Property
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||||
System.SerializableAttribute(), _
|
Serializable(),
|
||||||
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/LicenseSchema.xsd")> _
|
XmlType([Namespace]:="http://tempuri.org/LicenseSchema.xsd")>
|
||||||
Public Enum UserType
|
Public Enum UserType
|
||||||
|
|
||||||
'''<remarks/>
|
'''<remarks/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user