Imports DigitalData.Modules.Logging

Public Class LicensesLegacy
    Private _licenses() As LicenseLegacy
    Private _WDLizenz As String
    Private _Logger As Logger

    ' ++++++++++++++++++++++++++++++++++++++++++++++ Methoden ++++++++++++++++++++++++++++++++++++++++++++++

    ''' <summary>
    ''' Konstruktor für die Lizenzen-Sammlung
    ''' </summary>
    ''' <param name="licenseStringArray">In Array übertragene Lizenzinformationen</param>
    Sub New(LogConfig As LogConfig, ByVal licenseStringArray(,) As String)
        Try
            _Logger = LogConfig.GetLogger()

            If licenseStringArray IsNot Nothing Then
                Dim license1() As String = licenseStringArray(0, 1).Split("#")

                If license1.Length > 1 Then
                    Me.machine = license1(1)
                Else
                    Me.machine = "all"
                End If
                Me.Company = license1(0) 'licenseStringArray(0, 1)
                Dim i As Integer
                For i = 1 To licenseStringArray.GetLength(0) - 2   ' minus 2, weil GetLength nicht null-basiert ist und das erste Element Firma ist
                    Dim anzprof As String = licenseStringArray(i, 3)
                    If anzprof.ToLower = "unlimited" Then
                        anzprof = 99
                    End If
                    Me.Add(licenseStringArray(i, 0), licenseStringArray(i, 1), licenseStringArray(i, 2), anzprof)
                Next
            End If
        Catch ex As Exception
            _Logger.Error(ex)
        End Try
    End Sub


    ''' <summary>
    ''' Fügt der Lizenz-Sammlung eine Lizenz hinzu
    ''' </summary>
    ''' <param name="modulename">Name des Moduls, für das eine Lizenz angelegt werden soll</param>
    ''' <param name="expires">Datum der Gültigkeit der Lizenz</param>
    Public Sub Add(ByVal modulename As String, ByVal expires As Date, ByVal type As String, ByVal anzprof As String)

        If _licenses IsNot Nothing Then
            ReDim Preserve _licenses(_licenses.Length)
        Else
            ReDim Preserve _licenses(0)
        End If

        _licenses(_licenses.Length - 1) = New LicenseLegacy(modulename, expires, type, anzprof)
    End Sub


    ''' <summary>
    ''' Liefert eine Lizenz an Hand des Modulnamens
    ''' </summary>
    ''' <param name="modulename">Name des zu suchenden Moduls</param>
    ''' <returns>liefert ein Lizenzobjekt</returns>
    Public Function GetLicense(ByVal modulename As String) As LicenseLegacy
        If _licenses IsNot Nothing Then
            For Each license As LicenseLegacy In _licenses
                If license.Modulename = modulename Then
                    Return license
                End If
            Next
        End If

        Return Nothing
    End Function

    ' ++++++++++++++++++++++++++++++++++++++++++++++ Properties ++++++++++++++++++++++++++++++++++++++++++++++

    ''' <summary>
    ''' liefert eine Sammlung von Lizenzobjekten 
    ''' </summary>
    Public ReadOnly Property Licenses() As LicenseLegacy()
        Get
            Return _licenses
        End Get
    End Property


    ''' <summary>
    ''' liefert eine Lizenz an Hand des Modulnamens
    ''' </summary>
    ''' <param name="modulename">Name des zu suchenden Moduls</param>
    Public ReadOnly Property License(ByVal modulename As String) As LicenseLegacy
        Get
            Return GetLicense(modulename)
        End Get
    End Property


    ''' <summary>
    ''' Liefert oder setzt den Firmennamen des Lizenzeigentümers
    ''' </summary>
    Public Property Company() As String
    Public Property machine() As String
End Class
