jj: license
This commit is contained in:
parent
70ceeeb51a
commit
54af1a770b
@ -72,6 +72,7 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LicenseCreator.vb" />
|
||||
<Compile Include="LicenseFile.vb" />
|
||||
<Compile Include="LicenseSchema.vb">
|
||||
<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.Xml
|
||||
Imports System.Xml.Serialization
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
@ -18,6 +19,21 @@ Public Class LicenseFile
|
||||
Return oSerializer
|
||||
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
|
||||
Try
|
||||
Dim oSerializer = GetSerializer()
|
||||
@ -35,13 +51,27 @@ Public Class LicenseFile
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Sub SaveFile(License As LicenseSchema, Optional FileName As String = LICENSE_FILENAME)
|
||||
Public Function Serialize(License As LicenseSchema) As Byte()
|
||||
Try
|
||||
Dim oSerializer = GetSerializer()
|
||||
|
||||
Using oStream = New FileStream(FileName, FileMode.Create, FileAccess.Write)
|
||||
Using oStream = New MemoryStream()
|
||||
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
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
|
||||
@ -12,24 +12,26 @@ Option Strict Off
|
||||
Option Explicit On
|
||||
|
||||
Imports System.Xml.Serialization
|
||||
Imports System.ComponentModel
|
||||
Imports System.CodeDom.Compiler
|
||||
|
||||
'
|
||||
'This source code was auto-generated by xsd, Version=4.6.1586.0.
|
||||
'
|
||||
|
||||
'''<remarks/>
|
||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
||||
System.SerializableAttribute(), _
|
||||
System.Diagnostics.DebuggerStepThroughAttribute(), _
|
||||
System.ComponentModel.DesignerCategoryAttribute("code"), _
|
||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://tempuri.org/LicenseSchema.xsd"),
|
||||
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://tempuri.org/LicenseSchema.xsd", IsNullable:=False)>
|
||||
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||
Serializable(),
|
||||
DebuggerStepThrough(),
|
||||
DesignerCategory("code"),
|
||||
XmlType(AnonymousType:=True, [Namespace]:="http://tempuri.org/LicenseSchema.xsd"),
|
||||
XmlRoot([Namespace]:="http://tempuri.org/LicenseSchema.xsd", IsNullable:=False, ElementName:="License")>
|
||||
Partial Public Class LicenseSchema
|
||||
|
||||
Private modulesField() As LicenseModule
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlArrayItemAttribute("Module", IsNullable:=False)>
|
||||
<XmlArrayItemAttribute("Module", IsNullable:=False)>
|
||||
Public Property Modules() As LicenseModule()
|
||||
Get
|
||||
Return Me.modulesField
|
||||
@ -41,161 +43,161 @@ Partial Public Class LicenseSchema
|
||||
End Class
|
||||
|
||||
'''<remarks/>
|
||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
||||
System.SerializableAttribute(), _
|
||||
System.Diagnostics.DebuggerStepThroughAttribute(), _
|
||||
System.ComponentModel.DesignerCategoryAttribute("code"), _
|
||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")> _
|
||||
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||
Serializable(),
|
||||
DebuggerStepThrough(),
|
||||
DesignerCategory("code"),
|
||||
XmlType(AnonymousType:=True, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")>
|
||||
Partial Public Class LicenseModule
|
||||
|
||||
|
||||
Private usersField() As LicenseModuleUser
|
||||
|
||||
|
||||
Private nameField As String
|
||||
|
||||
|
||||
Private validUntilField As Date
|
||||
|
||||
|
||||
Private validUntilFieldSpecified As Boolean
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlArrayItemAttribute("User", IsNullable:=false)> _
|
||||
<XmlArrayItem("User", IsNullable:=False)>
|
||||
Public Property Users() As LicenseModuleUser()
|
||||
Get
|
||||
Return Me.usersField
|
||||
End Get
|
||||
Set
|
||||
Me.usersField = value
|
||||
Me.usersField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlAttributeAttribute()> _
|
||||
<XmlAttribute()>
|
||||
Public Property Name() As String
|
||||
Get
|
||||
Return Me.nameField
|
||||
End Get
|
||||
Set
|
||||
Me.nameField = value
|
||||
Me.nameField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="date")> _
|
||||
<XmlAttribute(DataType:="date")>
|
||||
Public Property ValidUntil() As Date
|
||||
Get
|
||||
Return Me.validUntilField
|
||||
End Get
|
||||
Set
|
||||
Me.validUntilField = value
|
||||
Me.validUntilField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlIgnoreAttribute()> _
|
||||
<XmlIgnoreAttribute()>
|
||||
Public Property ValidUntilSpecified() As Boolean
|
||||
Get
|
||||
Return Me.validUntilFieldSpecified
|
||||
End Get
|
||||
Set
|
||||
Me.validUntilFieldSpecified = value
|
||||
Me.validUntilFieldSpecified = Value
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
|
||||
'''<remarks/>
|
||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
||||
System.SerializableAttribute(), _
|
||||
System.Diagnostics.DebuggerStepThroughAttribute(), _
|
||||
System.ComponentModel.DesignerCategoryAttribute("code"), _
|
||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")> _
|
||||
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||
Serializable(),
|
||||
DebuggerStepThrough(),
|
||||
DesignerCategory("code"),
|
||||
XmlType(AnonymousType:=True, [Namespace]:="http://tempuri.org/LicenseSchema.xsd")>
|
||||
Partial Public Class LicenseModuleUser
|
||||
|
||||
|
||||
Private typeField As UserType
|
||||
|
||||
|
||||
Private countField As String
|
||||
|
||||
|
||||
Private testField As Boolean
|
||||
|
||||
|
||||
Private validUntilField As Date
|
||||
|
||||
|
||||
Private validUntilFieldSpecified As Boolean
|
||||
|
||||
|
||||
Public Sub New()
|
||||
MyBase.New
|
||||
Me.testField = true
|
||||
Me.testField = True
|
||||
End Sub
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlAttributeAttribute()> _
|
||||
<XmlAttribute()>
|
||||
Public Property Type() As UserType
|
||||
Get
|
||||
Return Me.typeField
|
||||
End Get
|
||||
Set
|
||||
Me.typeField = value
|
||||
Me.typeField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="integer")> _
|
||||
<XmlAttribute(DataType:="integer")>
|
||||
Public Property Count() As String
|
||||
Get
|
||||
Return Me.countField
|
||||
End Get
|
||||
Set
|
||||
Me.countField = value
|
||||
Me.countField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlAttributeAttribute(), _
|
||||
System.ComponentModel.DefaultValueAttribute(true)> _
|
||||
<XmlAttribute(),
|
||||
DefaultValue(True)>
|
||||
Public Property Test() As Boolean
|
||||
Get
|
||||
Return Me.testField
|
||||
End Get
|
||||
Set
|
||||
Me.testField = value
|
||||
Me.testField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="date")> _
|
||||
<XmlAttribute(DataType:="date")>
|
||||
Public Property ValidUntil() As Date
|
||||
Get
|
||||
Return Me.validUntilField
|
||||
End Get
|
||||
Set
|
||||
Me.validUntilField = value
|
||||
Me.validUntilField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlIgnoreAttribute()> _
|
||||
<XmlIgnore()>
|
||||
Public Property ValidUntilSpecified() As Boolean
|
||||
Get
|
||||
Return Me.validUntilFieldSpecified
|
||||
End Get
|
||||
Set
|
||||
Me.validUntilFieldSpecified = value
|
||||
Me.validUntilFieldSpecified = Value
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
|
||||
'''<remarks/>
|
||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1586.0"), _
|
||||
System.SerializableAttribute(), _
|
||||
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/LicenseSchema.xsd")> _
|
||||
<GeneratedCode("xsd", "4.6.1586.0"),
|
||||
Serializable(),
|
||||
XmlType([Namespace]:="http://tempuri.org/LicenseSchema.xsd")>
|
||||
Public Enum UserType
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
PowerUser
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
[ReadOnly]
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
[WriteOnly]
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
ReadWrite
|
||||
End Enum
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user