Imports System.Data.SqlClient Imports System.Runtime.Serialization Imports DigitalData.Modules.Database Imports DigitalData.Modules.Language 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 Connections As New List(Of DatabaseConnection) Public Property Doctypes As New List(Of Doctype) Public Property ClientConfig As New ClientConfiguration 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 Function GetObjectStore(pName As String) As ObjectStore Return ObjectStores. Where(Function(store) store.Title.ToUpper = pName.ToUpper). FirstOrDefault() End Function Public Function GetConnection(pConnectionId As Long) As DatabaseConnection Return Connections. Where(Function(conn) conn.Id = pConnectionId). FirstOrDefault() End Function Public Function GetCachedTables() As List(Of String) Try Dim oTables As DataTableCollection = TableStore.Tables Dim oList As New List(Of String) For Each oTable As DataTable In oTables oList.Add(oTable.TableName) Next Return oList Catch ex As Exception _Logger.Error(ex) Return New List(Of String) End Try End Function Public Function GetConnectionString(pConnectionId As Long) As String Dim oConnection = GetConnection(pConnectionId) Dim oBuilder As New SqlConnectionStringBuilder With { .DataSource = oConnection.Server, .InitialCatalog = oConnection.Database, .UserID = oConnection.Username, .Password = oConnection.Password } Return MSSQLServer.DecryptConnectionString(oBuilder.ToString) End Function Public Sub LoadDoctypes() _Logger.Info("Loading Doctypes") Try Dim oSQL As String = "SELECT * FROM VWIDB_DOCTYPE_HANDLING" Dim oTable As DataTable = _MSSQL_IDB.GetDatatable(oSQL) _Logger.Info("Found [{0}] Document Types", oTable.Rows.Count) Dim oDocTypes As New List(Of Doctype) For Each oRow As DataRow In oTable.Rows Dim oDoctype As New Doctype With { .Name = oRow.Item("DOCTYPE"), .FileChangedAction = oRow.Item("CHANGED_HANDLING") } _Logger.Info("New Doctype [{0}]", oDoctype.Name) oDocTypes.Add(oDoctype) Next Doctypes = oDocTypes Catch ex As Exception _Logger.Error(ex) End Try End Sub Public Sub LoadObjectStores() _Logger.Info("Loading Object Stores") Try Dim oSQL As String = "SELECT * FROM VWIDB_OBJECT_STORE" Dim oTable As DataTable = _MSSQL_IDB.GetDatatable(oSQL) _Logger.Info("Found [{0}] Object Stores", oTable.Rows.Count) Dim oObjectStores As New List(Of ObjectStore) For Each oRow As DataRow In oTable.Rows Dim oStore As New ObjectStore() With { .Id = oRow.Item("GUID"), .IsArchive = oRow.Item("Archive"), .Path = oRow.Item("REL_PATH"), .Title = oRow.Item("Objectstore") } _Logger.Info("New Object Store [{0}]", oStore.Title) oObjectStores.Add(oStore) Next ObjectStores = oObjectStores Catch ex As Exception _Logger.Error(ex) End Try End Sub Public Sub LoadConnections() _Logger.Info("Loading Database Connections") Try Dim oSQL As String = "SELECT * FROM TBDD_CONNECTION" Dim oTable As DataTable = _MSSQL_ECM.GetDatatable(oSQL) _Logger.Info("Found [{0}] Connections", oTable.Rows.Count) Dim oConnections As New List(Of DatabaseConnection) For Each oRow As DataRow In oTable.Rows Dim oConnection As New DatabaseConnection() With { .Id = oRow.ItemEx(Of Integer)("GUID"), .Active = oRow.ItemEx(Of Boolean)("AKTIV"), .Database = oRow.ItemEx(Of String)("DATENBANK"), .Title = oRow.ItemEx(Of String)("BEZEICHNUNG"), .Password = oRow.ItemEx(Of String)("PASSWORD"), .Provider = oRow.ItemEx(Of String)("SQL_PROVIDER"), .Server = oRow.ItemEx(Of String)("SERVER"), .Username = oRow.ItemEx(Of String)("USERNAME") } _Logger.Info("New Connection [{0}]", oConnection.Title) oConnections.Add(oConnection) Next Connections = oConnections Catch ex As Exception _Logger.Error(ex) End Try End Sub Public Sub LoadClientConfig(pConfig As Config) _Logger.Info("Loading Client Config") _Logger.Debug("ForceDirectDatabaseAccess: {0}", pConfig.ClientConfig.ForceDirectDatabaseAccess) ClientConfig.ForceDirectDatabaseAccess = pConfig.ClientConfig.ForceDirectDatabaseAccess ClientConfig.DocumentTypes = Doctypes ClientConfig.ConnectionStringECM = _MSSQL_ECM.CurrentConnectionString ClientConfig.ConnectionStringIDB = _MSSQL_IDB.CurrentConnectionString End Sub Public Class ObjectStore Public Id As Long Public Title As String Public IsArchive As Boolean Public Path As String End Class Public Class DatabaseConnection Public Id As Long Public Title As String Public Provider As String Public Server As String Public Database As String Public Username As String Public Password As String Public Active As Boolean End Class Public Class ClientConfiguration Public Property ForceDirectDatabaseAccess As Boolean = False Public Property DocumentTypes As New List(Of Doctype) Public Property ConnectionStringECM As String Public Property ConnectionStringIDB As String End Class Public Class Doctype Public Property Name As String Public Property FileChangedAction As String End Class End Class