Add project files.
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.OperationsMgr.Web.Consoles;
|
||||
using Sarand.OperationsMgr.Win.Dbas.App;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class SaOperationsMgrWebApp : SacsStateItem, IDisposable
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
internal class OpnSessionContext_Web : OpnSessionContext
|
||||
{
|
||||
public OpnSessionContext_Web (ushort sesionContextIndex, Opn.Instance instance) :
|
||||
base(sesionContextIndex)
|
||||
{
|
||||
Instance = instance;
|
||||
}
|
||||
}
|
||||
public class SessionContextConfig
|
||||
{
|
||||
public OpnSessionContext SessionContext { get; internal set; }
|
||||
public String Caption { get; internal set; }
|
||||
public SacsDatabase Database { get; internal set; } = null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private static SaOperationsMgrWebApp app;
|
||||
private PropertySet properties;
|
||||
private Dictionary<ushort, SessionContextConfig> sessionContexts = new Dictionary<ushort, SessionContextConfig>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SaOperationsMgrWebApp (IHostingEnvironment env, IConfigurationSection instanceConfig, String initialLogMessage)
|
||||
{
|
||||
app = this;
|
||||
}
|
||||
public void Dispose ()
|
||||
{
|
||||
app = null;
|
||||
DeinitGlobals();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public String ContentRootPath { get; }
|
||||
public String LoggingRootFolder { get; }
|
||||
public bool IsDevelopment { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// I n s t a n c e
|
||||
//-------------------------------------------------------------------
|
||||
public static SaOperationsMgrWebApp GetInstance ()
|
||||
{
|
||||
return app;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// S e s s i o n C o n t e x t C o n f i g u r a t i o n s
|
||||
//-------------------------------------------------------------------
|
||||
public List<ushort> GetSessionContextIndices ()
|
||||
{
|
||||
List<ushort> indices = new List<ushort>();
|
||||
foreach (ushort index in sessionContexts.Keys)
|
||||
indices.Add(index);
|
||||
indices.Sort();
|
||||
return indices;
|
||||
}
|
||||
public SessionContextConfig GetSessionContextConfig (ushort sessionContextIndex)
|
||||
{
|
||||
if (sessionContexts.ContainsKey(sessionContextIndex))
|
||||
return sessionContexts[sessionContextIndex];
|
||||
return null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// G l o b a l s
|
||||
//-------------------------------------------------------------------
|
||||
private void InitGlobals (IConfigurationSection sessionContextsConfig)
|
||||
{
|
||||
GetSessionContextConfigurations(sessionContextsConfig);
|
||||
OpnGlobals.System = new OpnSystem_WinDbas(properties);
|
||||
OpnGlobals.ConsoleHelper = new OpnConsoleHelper_Web();
|
||||
}
|
||||
private void GetSessionContextConfigurations (IConfigurationSection sessionContextsConfig)
|
||||
{
|
||||
// Retrieve Session Context configurations.
|
||||
ushort sessionContextConfigIdx = 0;
|
||||
foreach (IConfigurationSection sessionContextCfg in sessionContextsConfig.GetChildren())
|
||||
{
|
||||
sessionContextConfigIdx++;
|
||||
// Extract instance code.
|
||||
String instanceCode = sessionContextCfg.GetSection("Instance").Value;
|
||||
Opn.Instance instance = OpnSystem.GetInstanceForCode(instanceCode);
|
||||
if ((int)instance < 1)
|
||||
{
|
||||
Logger.Warn("Unrecognised instance code '" + instanceCode + "' in configuration.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Configure Session Context.
|
||||
SessionContextConfig sessionContextConfig = new SessionContextConfig();
|
||||
sessionContextConfig.SessionContext = new OpnSessionContext_Web((ushort)(sessionContextConfigIdx * 100u), instance);
|
||||
sessionContextConfig.Caption = sessionContextCfg.GetSection("Caption").Value;
|
||||
if (StringUtil.IsEmpty(sessionContextConfig.Caption))
|
||||
sessionContextConfig.Caption = OpnSystem.GetInstanceDesc(instance);
|
||||
|
||||
// Retrieve database configuration.
|
||||
IConfigurationSection stockDatabaseCfg = sessionContextCfg.GetSection("StockDatabase");
|
||||
String instanceDbLocation = stockDatabaseCfg.GetSection("Location").Value;
|
||||
Logger.Debug("Instance: " + instanceCode + ". Db location: " + instanceDbLocation);
|
||||
if (StringUtil.IsEmpty(instanceDbLocation))
|
||||
{
|
||||
Logger.Warn("Blank database location for instance '" + instanceCode + "' in configuration.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Configure database connection.
|
||||
SacsDatabaseConsole.OdbcConfig config = new SacsDatabaseConsole.OdbcConfig();
|
||||
config.location = instanceDbLocation;
|
||||
config.user = stockDatabaseCfg.GetSection("User").Value;
|
||||
config.pword = stockDatabaseCfg.GetSection("Pword").Value;
|
||||
sessionContextConfig.Database = SacsDatabaseConsole.OpenOdbcDatabase(config);
|
||||
//OpnGlobals.DbConsole.VerifyDatabaseSchema();
|
||||
|
||||
// Add session context to list.
|
||||
sessionContexts.Add(sessionContextConfig.SessionContext.Index, sessionContextConfig);
|
||||
}
|
||||
}
|
||||
private void DeinitGlobals ()
|
||||
{
|
||||
OpnGlobals.clear();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user