using Sarand.PatientMgr.Core.App; using Sarand.Core.Base; using Sarand.Core.IO; using Sarand.PatientMgr.Win.Dbas.App; using Sarand.PatientMgr.Win.Forms.App; using Sarand.Win.Dbas.Base; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sarand.PatientMgr.App { //======================================================================= class SaPatientMgrApp : SacsStateItem, IDisposable { //------------------------------------------------------------------- // Data members. private static SaPatientMgrApp app = null; private readonly PropertySet properties; private SpmSessionProfile_Desktop sessionProfile; //------------------------------------------------------------------- // Construction. public SaPatientMgrApp (String initialLogMessage) { app = this; SpmSystem_WinDbas.InitStatics(); // Locate properties file: String propertiesFilePath = FileUtil.LocateFileRelative("SaPatientMgr.cfg", new List { "Bin" }); properties = PropertySet.GetPropertiesFromFile(propertiesFilePath); if (properties != null) { //properties.Dump(); Spm.Site Site = EnumUtil.ParseEnum(properties.GetPropertyValue("Config", "Site"), Spm.Site.Unknown); // Default logger properties. Logger.LogFilenamePrefix = "SPM-DSK"; Logger.LogFolder = properties.GetPropertyValue("Logging", "Folder"); #if DEBUG Logger.ConsoleLevel = SaMessageLevel.Trace; #endif Logger.LogFileLevel = EnumUtil.StartsWith(properties.GetPropertyValue("Logging", "Level"), SaMessageLevel.Info); Logger.Info(initialLogMessage, true); Logger.Info("Logging level: " + Logger.LogFileLevel); // Configure extended logging. List extendedLoggingOptions = StringList.Split(properties.GetPropertyValue("Logging", "ExtendedLogging")); if (!extendedLoggingOptions.IsEmpty()) Logger.Info("Extended logging: " + extendedLoggingOptions.Concat(",")); } else SetErrorState("Properties file not found"); SessionContext = new SpmSessionContext_Desktop(0, Site); InitGlobals(); //SpmGlobals.DbConsole.VerifyDatabaseSchema(); // Login the current windows user. SpmGlobals.Application.GetSecurityConsole(SessionContext).LoginAuthenticatedUser(); } public void Dispose () { app = null; DeinitGlobals(); } //------------------------------------------------------------------- // Properties. public Spm.Site Site { get; } = Spm.Site.Unknown; public SpmSessionContext SessionContext { get; } //------------------------------------------------------------------- // I n s t a n c e //------------------------------------------------------------------- public static SaPatientMgrApp getInstance () { return app; } //------------------------------------------------------------------- // G l o b a l s //------------------------------------------------------------------- private void InitGlobals () { // System. SpmGlobals.System = new SpmSystem_WinDbas(properties); // Database. SacsDatabase database = OpenDatabase(); //SpmGlobals.DbConsole = new LogisticsMgrDbConsoleDbas(); // Global application. SpmGlobals.Application = new SpmApplication_Desktop(properties, SessionContext, database); // Session profile. sessionProfile = new SpmSessionProfile_Desktop(SessionContext); SpmGlobals_Win.SessionProfile = sessionProfile; } private SacsDatabase OpenDatabase () { SacsDatabaseConsole.OdbcConfig config = new SacsDatabaseConsole.OdbcConfig(); config.location = properties.GetPropertyValue("Scheduling", "DataSource"); config.user = properties.GetPropertyValue("Scheduling", "DataUser"); config.pword = properties.GetPropertyValue("Scheduling", "DataPword"); Logger.Trace("PatientMgrApp OpenDatabase Location=" + config.location); SacsDatabase database = SacsDatabaseConsole.OpenOdbcDatabase(config); bool catalogDatabase = true; if (catalogDatabase) { foreach (String tableName in database.GetTableNames()) { database.GetTableDfn(tableName); } } return database; } //------------------------------------------------------------------- private void DeinitGlobals () { if (SpmGlobals_Win.SessionProfile != null) SpmGlobals_Win.SessionProfile.StoreProperties(); SpmGlobals.clear(); } //------------------------------------------------------------------- } //======================================================================= }