Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging

Public Class GlobalState
    Private ReadOnly _LogConfig As LogConfig
    Private ReadOnly _Logger As Logger
    Private ReadOnly _MSSQL_IDB As MSSQLServer
    Private ReadOnly _MSSQL_ECM As MSSQLServer

    Public Property ObjectStores As New List(Of ObjectStore)

    Public Property TableStore As New DataSet

    Public Sub New(LogConfig As LogConfig, MSSQL_IDB As MSSQLServer, MSSQL_ECM As MSSQLServer)
        _LogConfig = LogConfig
        _Logger = LogConfig.GetLogger()
        _MSSQL_IDB = MSSQL_IDB
        _MSSQL_ECM = MSSQL_ECM
    End Sub

    Public Sub LoadObjectStores()
        _Logger.Debug("Loading Object Stores")
        Try
            Dim oSQL As String = "SELECT * FROM VWIDB_OBJECTSTORE"
            Dim oDatatable As DataTable = _MSSQL_IDB.GetDatatable(oSQL)

            ObjectStores.Clear()

            _Logger.Debug("Found {0} Object Stores", oDatatable.Rows)

            For Each oRow As DataRow In oDatatable.Rows
                Dim oStore As New ObjectStore() With {
                    .Id = oRow.Item("OST_ID"),
                    .IsArchive = oRow.Item("OS_IS_ARCHIVE"),
                    .Path = oRow.Item("IDB_PRAEFIX"),
                    .Title = oRow.Item("OS_TITLE")
                }
                _Logger.Debug("New Object Store [{0}]", oStore.Title)
                ObjectStores.Add(oStore)
            Next
        Catch ex As Exception
            _Logger.Error(ex)
        End Try
    End Sub

    Class ObjectStore
        Public Id As Long
        Public Title As String
        Public IsArchive As Boolean
        Public Path As String
    End Class
End Class
