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

Public Class GlobalState
    Private _LogConfig As LogConfig
    Private _Logger As Logger
    Private _MSSQL As MSSQLServer
    Public Property ObjectStores As New List(Of ObjectStore)

    Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer)
        _LogConfig = LogConfig
        _Logger = LogConfig.GetLogger()
        _MSSQL = MSSQL
    End Sub

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

            ObjectStores.Clear()

            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)
            Throw ex
        End Try
    End Sub

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