Portal password request - in progress.
This commit is contained in:
+11
-5
@@ -8,7 +8,9 @@ using System.Text;
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmSessionConfig
|
||||
// BusinessMgr Application Configuration.
|
||||
//=======================================================================
|
||||
public class SbmAppConfig
|
||||
{
|
||||
//---------------------------------------------------------------
|
||||
// Data members.
|
||||
@@ -16,7 +18,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmSessionConfig(String context, ConfigurationSection configSection, SbmSessionConfig defaultConfig)
|
||||
public SbmAppConfig(String context, ConfigurationSection configSection, SbmAppConfig defaultConfig)
|
||||
{
|
||||
Context = context;
|
||||
populateDefaults(defaultConfig);
|
||||
@@ -24,7 +26,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
private void populateDefaults(SbmSessionConfig defaultConfig)
|
||||
private void populateDefaults(SbmAppConfig defaultConfig)
|
||||
{
|
||||
if (defaultConfig == null) return;
|
||||
Security.Password.MinLength = defaultConfig.Security.Password.MinLength;
|
||||
@@ -87,8 +89,10 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
Logging.RootFolder = StringUtil.OnEmpty(logging["RootFolder"], Logging.RootFolder);
|
||||
}
|
||||
// Database.
|
||||
extractDatabaseConfig(BusMgrDatabase, configSection.GetSection("CoreDatabase"));
|
||||
// Databases.
|
||||
extractDatabaseConfig(ControlDatabase, configSection.GetSection("ControlDatabase"));
|
||||
extractDatabaseConfig(BusMgrDatabase, configSection.GetSection("BusMgrDatabase"));
|
||||
extractDatabaseConfig(TemplateDatabase, configSection.GetSection("TemplateDatabase"));
|
||||
// Variants.
|
||||
foreach (ConfigurationSection variantSection in configSection.GetSection("Variants").GetChildren())
|
||||
{
|
||||
@@ -179,7 +183,9 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
public String User { get; internal set; }
|
||||
public String Password { get; internal set; }
|
||||
}
|
||||
public DatabaseConfig ControlDatabase { get; } = new DatabaseConfig();
|
||||
public DatabaseConfig BusMgrDatabase { get; } = new DatabaseConfig();
|
||||
public DatabaseConfig TemplateDatabase { get; } = new DatabaseConfig();
|
||||
// Documents.
|
||||
public class DocumentsConfig
|
||||
{
|
||||
@@ -5,7 +5,6 @@ using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Diary;
|
||||
using Sarand.Net.Standard.Base.Interfaces;
|
||||
using Sarand.Net.Standard.Base.IO;
|
||||
@@ -16,7 +15,6 @@ using Sarand.Net.Standard.Base.ReferenceData;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.UpdateLog;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -36,24 +34,23 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
// Protected construction.
|
||||
protected SbmApplication_Web() : base(new PropertySet())
|
||||
{
|
||||
WebApp = this;
|
||||
SbmGlobals_Web.Application = this;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public override SbmSystem System { get { return System_Web; } }
|
||||
public SbmSystem_Web System_Web { get; protected set; }
|
||||
public static SbmApplication_Web WebApp { get; private set; }
|
||||
// Application instance.
|
||||
public override Sbm.InstanceType InstanceType { get { return instanceType; } }
|
||||
public override String EnvironmentName { get { return environmentName; } }
|
||||
public bool Development { get; protected set; }
|
||||
public String LoggingRootFolder { get; protected set; } = "";
|
||||
// Application components.
|
||||
public abstract SbmAppConfig AppConfig { get; }
|
||||
public abstract String SessionCookieName { get; }
|
||||
public virtual SbmSessionContext SessionContext { get; protected set; }
|
||||
public abstract SbmSessionConfig SessionConfig { get; }
|
||||
public override IDatabaseInfo CreateBusMgrDbInfo(SbmSessionContext sessionContext) { return new DbDataItem.DatabaseInfo(GetBusMgrDatabase(sessionContext)); }
|
||||
public abstract List<ushort> GetSessionContextIdxs();
|
||||
public abstract SbmSessionContext GetSessionContext(ushort index);
|
||||
// Configuration.
|
||||
public IConfiguration Configuration { get; protected set; }
|
||||
public IConfiguration SbmConfiguration { get; protected set; }
|
||||
@@ -66,14 +63,15 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
List<StringPair> applicationParams = new List<StringPair>();
|
||||
applicationParams.Add("Host", SbmSystem.ComputerName);
|
||||
applicationParams.Add("Version", Sbm.Version.GetFullVersion());
|
||||
applicationParams.Add("Instance", InstanceType.ToString() + (!StringUtil.IsEmpty(SessionConfig.Instance) ? " [" + SessionConfig.Instance + "]" : ""));
|
||||
applicationParams.Add("Instance", InstanceType.ToString() + (!StringUtil.IsEmpty(AppConfig.Instance) ? " [" + AppConfig.Instance + "]" : ""));
|
||||
applicationParams.Add("Configuration", SbmSystem.DebugMode ? "Debug" : "Release");
|
||||
applicationParams.Add("Environment", EnvironmentName);
|
||||
applicationParams.Add("Database", SessionConfig.BusMgrDatabase.Location);
|
||||
applicationParams.Add("Control database", AppConfig.ControlDatabase.Location);
|
||||
applicationParams.Add("BusMgr database", AppConfig.BusMgrDatabase.Location);
|
||||
applicationParams.Add("Application root", SbmSystem.ApplicationFolder);
|
||||
if (!StringUtil.IsEmpty(SessionConfig.Documents.RootFolder))
|
||||
applicationParams.Add("Documents root", SessionConfig.Documents.RootFolder);
|
||||
applicationParams.Add("Email context", SessionConfig.Email.Context + (!StringUtil.IsEmpty(EmailConfig.SMTP.Server) ? " [" + EmailConfig.SMTP.Server + "]" : ""));
|
||||
if (!StringUtil.IsEmpty(AppConfig.Documents.RootFolder))
|
||||
applicationParams.Add("Documents root", AppConfig.Documents.RootFolder);
|
||||
applicationParams.Add("Email context", AppConfig.Email.Context + (!StringUtil.IsEmpty(EmailConfig.SMTP.Server) ? " [" + EmailConfig.SMTP.Server + "]" : ""));
|
||||
SaLogger.Info(fn + " Application start." + applicationParams.Select(item => StringUtil.PadRight(item.Item1 + ":", 20, ' ') + item.Item2).Concat("", "\n\t"), true);
|
||||
}
|
||||
|
||||
@@ -107,7 +105,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
}
|
||||
public override SaSecurityConsole CreateSecurityConsole(SbmUserContext userContext)
|
||||
{
|
||||
return null;
|
||||
return new SbmSecurityConsole_Web(userContext, GetBusMgrDatabase(userContext.SessionContext));
|
||||
}
|
||||
public override SaCodeTypeConsole CreateCodeTypeConsole(SbmUserContext userContext)
|
||||
{
|
||||
@@ -135,7 +133,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
}
|
||||
public override SaUpdateLogConsole CreateUpdateLogConsole(SbmUserContext userContext)
|
||||
{
|
||||
return null;
|
||||
return new SbmUpdateLogConsole_Web(userContext, GetBusMgrDatabase(userContext.SessionContext));
|
||||
}
|
||||
public override SbmEmailConsole CreateEmailConsole(SbmUserContext userContext)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Diary;
|
||||
using Sarand.Net.Standard.Base.Interfaces;
|
||||
using Sarand.Net.Standard.Base.ItemData;
|
||||
using Sarand.Net.Standard.Base.ItemDocs;
|
||||
using Sarand.Net.Standard.Base.ItemOptions;
|
||||
using Sarand.Net.Standard.Base.ReferenceData;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.UpdateLog;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
public static class SbmGlobals_Web
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// System.
|
||||
public static SbmSystem_Web System { get; set; } = null;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Application.
|
||||
public static SbmApplication_Web Application { get; set; } = null;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Dbas.Consoles;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmSecurityConsole_Web : SbmSecurityConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmSecurityConsole_Web(SbmUserContext userContext, ISacsDatabase database) : base(userContext, database)
|
||||
{
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
protected override ShowUserLoginFormFunction ShowUserLoginFormFn => throw new NotImplementedException();
|
||||
protected override ShowManageSecurityDialogFunction ShowManageSecurityDialogFn => throw new NotImplementedException();
|
||||
public override bool OnSecurityGroupModified(SysId userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override bool OnUserModified(SysId userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
protected override bool OnLogin(SysId userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
protected override void OnLogout()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Dbas.Consoles;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmUpdateLogConsole_Web : SbmUpdateLogConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmUpdateLogConsole_Web(SbmUserContext userContext, ISacsDatabase database) : base(userContext, database)
|
||||
{
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
protected override ShowUpdateLogDialogFunction ShowUpdateLogDialogFn => throw new NotImplementedException();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -67,9 +67,9 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public bool DebugMode { get; } = SacsSystem.DebugMode;
|
||||
protected SbmApplication_Web App { get { return SbmApplication_Web.WebApp; } }
|
||||
public SbmSessionConfig SessionConfig { get { return App.SessionConfig; } }
|
||||
public SbmSessionContext SessionContext { get { return App.SessionContext; } }
|
||||
protected SbmApplication_Web App { get { return SbmGlobals_Web.Application; } }
|
||||
public SbmAppConfig AppConfig { get { return App.AppConfig; } }
|
||||
public SbmSessionContext SessionContext { get { return UserContext?.SessionContext ?? null; } }
|
||||
public SbmUserContext UserContext { get { return SessionData.UserContext; } }
|
||||
protected SbmLocaliser Localiser { get; }
|
||||
/// <summary>
|
||||
@@ -177,10 +177,10 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
if (StoreSessionData)
|
||||
{
|
||||
String sessionDataJson = JsonConvert.SerializeObject(SessionData);
|
||||
HttpContext.Session.Set(SessionStorage.SessionKey_SessionConfig, SessionStorage.sessionDataEncoding.GetBytes(sessionDataJson));
|
||||
HttpContext.Session.Set(SessionStorage.SessionKey_SessionData, SessionStorage.sessionDataEncoding.GetBytes(sessionDataJson));
|
||||
}
|
||||
}
|
||||
else HttpContext.Session.Remove(SessionStorage.SessionKey_SessionConfig);
|
||||
else HttpContext.Session.Remove(SessionStorage.SessionKey_SessionData);
|
||||
|
||||
// Response headers.
|
||||
if (baseModel != null && baseModel.ProhibitCache)
|
||||
@@ -306,7 +306,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
public class SessionStorage
|
||||
{
|
||||
public SbmSessionData_Web SessionData { get; set; }
|
||||
public static String SessionKey_SessionConfig { get; } = "SbmSessionData";
|
||||
public static String SessionKey_SessionData { get; } = "SbmSessionData";
|
||||
public static Encoding sessionDataEncoding { get; } = Encoding.UTF8;
|
||||
//JSON Serialisation.
|
||||
public class SbmSessionDataContractResolver : DefaultContractResolver
|
||||
@@ -347,7 +347,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
if (sessionStorage.SessionData == null)
|
||||
{
|
||||
byte[] sessionDataBytes = null;
|
||||
HttpContext.Session.TryGetValue(SessionStorage.SessionKey_SessionConfig, out sessionDataBytes);
|
||||
HttpContext.Session.TryGetValue(SessionStorage.SessionKey_SessionData, out sessionDataBytes);
|
||||
if (sessionDataBytes != null)
|
||||
{
|
||||
String sessionDataJson = SessionStorage.sessionDataEncoding.GetString(sessionDataBytes);
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Helpers
|
||||
{
|
||||
//=======================================================================
|
||||
public static class SbmAppConfigHelper
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
public static Dictionary<String, SbmAppConfig> ExtractAppConfigs(IConfigurationSection appConfigsSection)
|
||||
{
|
||||
// NB The set of configurations will only allow one per context.
|
||||
// Only the last configuration found for each context will be stored (NB usually only one of each apart from 'Defaults').
|
||||
Dictionary<String, SbmAppConfig> appConfigs = new Dictionary<String, SbmAppConfig>();
|
||||
|
||||
// Start the list with a default 'Defaults' configuration - values set to application defaults (defined in Sbm).
|
||||
// NB This can be overridden in each level of configuration.
|
||||
// Settings from the 'Defaults' configuration provide values where they are missing from other configurations.
|
||||
// NB Coverage may not be 100% - just where it's proven needed.
|
||||
SbmAppConfig defaultsAppConfig = new SbmAppConfig(Sbm.Config.Context_Defaults, null, null);
|
||||
appConfigs.Add(defaultsAppConfig.Context, defaultsAppConfig);
|
||||
|
||||
// Load session configurations.
|
||||
foreach (ConfigurationSection appConfigSection in appConfigsSection.GetChildren())
|
||||
{
|
||||
if (StringUtil.IsEmpty(appConfigSection.Key)) continue;
|
||||
|
||||
// Extract the configuration, supplying current 'Defaults' to supply missing values, and add to the list.
|
||||
SbmAppConfig appConfig = new SbmAppConfig(appConfigSection.Key, appConfigSection, defaultsAppConfig);
|
||||
appConfigs.Remove(appConfigSection.Key);
|
||||
appConfigs.Add(appConfigSection.Key, appConfig);
|
||||
|
||||
// Replace the 'Defaults' configuration if this one matches the context.
|
||||
if (appConfig.Context.EqualsCI(Sbm.Config.Context_Defaults))
|
||||
defaultsAppConfig = appConfig;
|
||||
}
|
||||
return appConfigs;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
public static class AppConfigList
|
||||
{
|
||||
public static SbmAppConfig getConfigForApplication(this List<SbmAppConfig> appConfigs)
|
||||
{
|
||||
SbmAppConfig defaultsAppConfig = new SbmAppConfig("", null, null);
|
||||
SbmApplication app = SbmGlobals_Web.Application;
|
||||
if (app != null)
|
||||
{
|
||||
foreach (SbmAppConfig appConfig in appConfigs)
|
||||
{
|
||||
if (appConfig.Environments.ContainsCI(app.EnvironmentName))
|
||||
return appConfig;
|
||||
if (appConfig.Context.EqualsCI(Sbm.Config.Context_Defaults))
|
||||
defaultsAppConfig = appConfig;
|
||||
}
|
||||
}
|
||||
return defaultsAppConfig;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -75,13 +75,13 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Helpers
|
||||
//=======================================================================
|
||||
public static class EmailConfigList
|
||||
{
|
||||
public static SbmEmailConfig getConfigForSession(this List<SbmEmailConfig> emailConfigs, SbmSessionConfig sessionConfig)
|
||||
public static SbmEmailConfig getConfigForSession(this List<SbmEmailConfig> emailConfigs, SbmAppConfig appConfig)
|
||||
{
|
||||
if (sessionConfig != null && !StringUtil.IsEmpty(sessionConfig.Email.Context))
|
||||
if (appConfig != null && !StringUtil.IsEmpty(appConfig.Email.Context))
|
||||
{
|
||||
foreach (SbmEmailConfig emailConfig in emailConfigs)
|
||||
{
|
||||
if (emailConfig.Context.EqualsCI(sessionConfig.Email.Context))
|
||||
if (emailConfig.Context.EqualsCI(appConfig.Email.Context))
|
||||
return emailConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Helpers
|
||||
{
|
||||
//=======================================================================
|
||||
public static class SbmSessionConfigHelper
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
public static Dictionary<String, SbmSessionConfig> ExtractSessionConfigs(IConfigurationSection sessionConfigsSection)
|
||||
{
|
||||
// NB The set of configurations will only allow one per context.
|
||||
// Only the last configuration found for each context will be stored (NB usually only one of each apart from 'Defaults').
|
||||
Dictionary<String, SbmSessionConfig> sessionConfigs = new Dictionary<String, SbmSessionConfig>();
|
||||
|
||||
// Start the list with a default 'Defaults' configuration - values set to application defaults (defined in Sbm).
|
||||
// NB This can be overridden in each level of configuration.
|
||||
// Settings from the 'Defaults' configuration provide values where they are missing from other configurations.
|
||||
// NB Coverage may not be 100% - just where it's proven needed.
|
||||
SbmSessionConfig defaultsSessionConfig = new SbmSessionConfig(Sbm.Config.Context_Defaults, null, null);
|
||||
sessionConfigs.Add(defaultsSessionConfig.Context, defaultsSessionConfig);
|
||||
|
||||
// Load session configurations.
|
||||
foreach (ConfigurationSection sessionConfigSection in sessionConfigsSection.GetChildren())
|
||||
{
|
||||
if (StringUtil.IsEmpty(sessionConfigSection.Key)) continue;
|
||||
|
||||
// Extract the configuration, supplying current 'Defaults' to supply missing values, and add to the list.
|
||||
SbmSessionConfig sessionConfig = new SbmSessionConfig(sessionConfigSection.Key, sessionConfigSection, defaultsSessionConfig);
|
||||
sessionConfigs.Remove(sessionConfigSection.Key);
|
||||
sessionConfigs.Add(sessionConfigSection.Key, sessionConfig);
|
||||
|
||||
// Replace the 'Defaults' configuration if this one matches the context.
|
||||
if (sessionConfig.Context.EqualsCI(Sbm.Config.Context_Defaults))
|
||||
defaultsSessionConfig = sessionConfig;
|
||||
}
|
||||
return sessionConfigs;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
public static class SessionConfigList
|
||||
{
|
||||
public static SbmSessionConfig getConfigForApplication(this List<SbmSessionConfig> sessionConfigs)
|
||||
{
|
||||
SbmSessionConfig defaultsSessionConfig = new SbmSessionConfig("", null, null);
|
||||
SbmApplication app = SbmGlobals.Application;
|
||||
if (app != null)
|
||||
{
|
||||
foreach (SbmSessionConfig sessionConfig in sessionConfigs)
|
||||
{
|
||||
if (sessionConfig.Environments.ContainsCI(app.EnvironmentName))
|
||||
return sessionConfig;
|
||||
if (sessionConfig.Context.EqualsCI(Sbm.Config.Context_Defaults))
|
||||
defaultsSessionConfig = sessionConfig;
|
||||
}
|
||||
}
|
||||
return defaultsSessionConfig;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Helpers
|
||||
{
|
||||
//=======================================================================
|
||||
// Session Context utility functions.
|
||||
//=======================================================================
|
||||
public static class SbmSessionContextHelper_Web
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private static String className = typeof(SbmSessionContextHelper_Web).Name;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session Contexts.
|
||||
//-------------------------------------------------------------------
|
||||
public static SbmSessionContext GetSessionContext (ushort idx)
|
||||
{
|
||||
SbmApplication_Web app = SbmGlobals_Web.Application;
|
||||
return app.GetSessionContext(idx);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session Contexts for User Email Address
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Identify the session context that corresponds with the BusinessMgr
|
||||
/// database for the specified user by email address.
|
||||
/// </summary>
|
||||
public static List<ushort> GetSessionContextIdxsForUsersBusMgrDatabase(String emailAddress)
|
||||
{
|
||||
String fn = className + ".GetSessionContextIdxForUsersBusMgrDatabase";
|
||||
String alias_SecurityItem = "SecItm";
|
||||
String alias_Affiliate = "Affil";
|
||||
List<ushort> sessionContextIdxs = new List<ushort>();
|
||||
if (StringUtil.IsEmpty(emailAddress)) return sessionContextIdxs;
|
||||
|
||||
// Get the session context indices defined by the application.
|
||||
SbmApplication_Web app = SbmGlobals_Web.Application;
|
||||
foreach (ushort sessionContextIdx in app.GetSessionContextIdxs())
|
||||
{
|
||||
// Retrieve the session context.
|
||||
SbmSessionContext sessionContext = app.GetSessionContext(sessionContextIdx);
|
||||
if (sessionContext == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve SessionContext for idx: " + sessionContextIdx);
|
||||
continue;
|
||||
}
|
||||
// Retrieve the BusinessMgr database.
|
||||
ISacsDatabase db = app.GetBusMgrDatabase(sessionContext);
|
||||
if (db == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve SessionContext for idx: " + sessionContextIdx);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Query to check for Security Item matching the email with associated Affiliate.
|
||||
// NB This is done independently for each database in case there are different
|
||||
// DBMSs involved with different value formatting or syntax rules.
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SaSecurityDbDfn.GetTableName(SaSecurityDbDfn.TableIdx.SaSecItem), alias_SecurityItem);
|
||||
qry.Columns.Add(SaSecurityDbDfn.GetColumnNameQual(SaSecurityDbDfn.ColumnIdx.SaSecItem_Id, alias_SecurityItem));
|
||||
qry.Filters.Add(SaSecurityDbDfn.GetColumnNameQual(SaSecurityDbDfn.ColumnIdx.SaSecItem_EmailAddress, alias_SecurityItem) + "='" + DbQuery.FormatForCondition(emailAddress) + "'");
|
||||
// Join to the Affiliate table.
|
||||
DbQueryJoin joinAffiliate = new DbQueryJoin(DbJoinType.FullOuter);
|
||||
joinAffiliate.Table = new StringPair(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Affiliate), alias_Affiliate);
|
||||
joinAffiliate.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Affiliate_UserId, alias_Affiliate) + "=" + SaSecurityDbDfn.GetColumnNameQual(SaSecurityDbDfn.ColumnIdx.SaSecItem_Id, alias_SecurityItem));
|
||||
|
||||
// Execute query.
|
||||
using (DbResultSet resultSet = DbResultSet_DataReader.ExecuteQuery(db, qry.BuildQuery()))
|
||||
{
|
||||
if (resultSet != null && resultSet.NextRecord())
|
||||
sessionContextIdxs.Add(sessionContextIdx);
|
||||
}
|
||||
}
|
||||
return sessionContextIdxs;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -41,13 +41,13 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Models
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Application properties.
|
||||
private SbmApplication_Web App { get { return SbmApplication_Web.WebApp; } }
|
||||
protected SbmSessionConfig SessionConfig { get { return App.SessionConfig; } }
|
||||
private SbmApplication_Web App { get { return SbmGlobals_Web.Application; } }
|
||||
protected SbmAppConfig AppConfig { get { return App.AppConfig; } }
|
||||
protected SbmSystem_Web System { get { return App.System_Web; } }
|
||||
public String SessionCookieName { get { return App.SessionCookieName; } }
|
||||
public SbmSessionData SessionData { get { return SessionData_Web; } }
|
||||
public SbmSessionData_Web SessionData_Web { get; set; }
|
||||
public SbmSessionContext SessionContext { get { return SessionData?.SessionContext ?? App.SessionContext; } }
|
||||
public SbmSessionContext SessionContext { get { return SessionData?.SessionContext ?? null; } }
|
||||
public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SbmSystem.ComputerName); } }
|
||||
public bool DebugMode { get { return SbmSystem.DebugMode; } }
|
||||
public SbmLocaliser Localiser { get; }
|
||||
@@ -57,37 +57,38 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Models
|
||||
public bool OK { get { return !HasMessages(); } }
|
||||
public virtual bool ProhibitCache { get; set; } = true;
|
||||
public String PageCaption { get; set; }
|
||||
public String InstanceVersion { get { return !StringUtil.IsEmpty(App.SessionConfig.Instance) ? App.SessionConfig.Instance + " v" + Sbm.Version.GetFullVersion() : "v" + Sbm.Version.GetAppVersion(); } }
|
||||
public String InstanceVersion { get { return !StringUtil.IsEmpty(App.AppConfig.Instance) ? App.AppConfig.Instance + " v" + Sbm.Version.GetFullVersion() : "v" + Sbm.Version.GetAppVersion(); } }
|
||||
public bool IncludeGoogleAnalytics { get; set; } = false;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Business components.
|
||||
// NB Keep these accessors protected to avoid them being called by teh model binding logic before the session data is ready.
|
||||
protected SbmInternals Internals { get { if (internals == null) internals = new SbmInternals(SessionData_Web.UserContext); return internals; } }
|
||||
// Managers.
|
||||
public SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||
public SbmAssetMgr AssetMgr { get { return Internals.AssetMgr; } }
|
||||
public SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
|
||||
public SbmPriceMgr PriceMgr { get { return Internals.PriceMgr; } }
|
||||
public SbmTransactionMgr TransactionMgr { get { return Internals.TransactionMgr; } }
|
||||
public SbmStockMgr StockMgr { get { return Internals.StockMgr; } }
|
||||
public SbmProcessMgr ProcessMgr { get { return Internals.ProcessMgr; } }
|
||||
public SbmDataItemMgr DataItemMgr { get { return Internals.DataItemMgr; } }
|
||||
protected SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||
protected SbmAssetMgr AssetMgr { get { return Internals.AssetMgr; } }
|
||||
protected SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
|
||||
protected SbmPriceMgr PriceMgr { get { return Internals.PriceMgr; } }
|
||||
protected SbmTransactionMgr TransactionMgr { get { return Internals.TransactionMgr; } }
|
||||
protected SbmStockMgr StockMgr { get { return Internals.StockMgr; } }
|
||||
protected SbmProcessMgr ProcessMgr { get { return Internals.ProcessMgr; } }
|
||||
protected SbmDataItemMgr DataItemMgr { get { return Internals.DataItemMgr; } }
|
||||
// Consoles.
|
||||
public SbmConfigConsole ConfigConsole { get { return Internals.ConfigConsole; } }
|
||||
public SaDiaryConsole DiaryConsole { get { return Internals.DiaryConsole; } }
|
||||
public SaSecurityConsole SecurityConsole { get { return Internals.SecurityConsole; } }
|
||||
public SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } }
|
||||
public SaReferenceDataConsole ReferenceDataConsole { get { return Internals.ReferenceDataConsole; } }
|
||||
public SaUpdateLogConsole UpdateLogConsole { get { return Internals.UpdateLogConsole; } }
|
||||
public SaInterfaceConsole InterfaceConsole { get { return Internals.InterfaceConsole; } }
|
||||
public SaItemDocConsole ItemDocConsole { get { return Internals.ItemDocConsole; } }
|
||||
public SaItemOptionConsole ItemOptionConsole { get { return Internals.ItemOptionConsole; } }
|
||||
public SaItemDataConsole ItemDataConsole { get { return Internals.ItemDataConsole; } }
|
||||
protected SbmConfigConsole ConfigConsole { get { return Internals.ConfigConsole; } }
|
||||
protected SaDiaryConsole DiaryConsole { get { return Internals.DiaryConsole; } }
|
||||
protected SaSecurityConsole SecurityConsole { get { return Internals.SecurityConsole; } }
|
||||
protected SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } }
|
||||
protected SaReferenceDataConsole ReferenceDataConsole { get { return Internals.ReferenceDataConsole; } }
|
||||
protected SaUpdateLogConsole UpdateLogConsole { get { return Internals.UpdateLogConsole; } }
|
||||
protected SaInterfaceConsole InterfaceConsole { get { return Internals.InterfaceConsole; } }
|
||||
protected SaItemDocConsole ItemDocConsole { get { return Internals.ItemDocConsole; } }
|
||||
protected SaItemOptionConsole ItemOptionConsole { get { return Internals.ItemOptionConsole; } }
|
||||
protected SaItemDataConsole ItemDataConsole { get { return Internals.ItemDataConsole; } }
|
||||
// Configurations.
|
||||
public SbmStockControlConfig StockControlConfig { get { return Internals.StockControlConfig; } }
|
||||
public SbmRequirementCostingConfig RequirementCostingConfig { get { return Internals.RequirementCostingConfig; } }
|
||||
protected SbmStockControlConfig StockControlConfig { get { return Internals.StockControlConfig; } }
|
||||
protected SbmRequirementCostingConfig RequirementCostingConfig { get { return Internals.RequirementCostingConfig; } }
|
||||
// System codes.
|
||||
public List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode) { return Internals.GetCodesOfType(systemCode); }
|
||||
protected List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode) { return Internals.GetCodesOfType(systemCode); }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security.
|
||||
@@ -183,29 +184,32 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Models
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form data.
|
||||
// NB Use methods rathe rthan accessors for properties that depend on session data
|
||||
// to avoid the model binding logic invoking a getter before it's ready for use.
|
||||
|
||||
/// <summary>List of Address Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> AddressTypeCodesForSelect
|
||||
public IEnumerable<SelectListItem> GetAddressTypeCodesForSelect()
|
||||
{
|
||||
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.AddressType), "Code", "Desc"); }
|
||||
return new SelectList(GetCodesOfType(Sbm.SystemCode.AddressType), "Code", "Desc");
|
||||
}
|
||||
|
||||
/// <summary>List of Affiliate Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> AffiliateTypeCodesForSelect
|
||||
public IEnumerable<SelectListItem> GetAffiliateTypeCodesForSelect()
|
||||
{
|
||||
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.AffiliateType), "Code", "Desc"); }
|
||||
return new SelectList(GetCodesOfType(Sbm.SystemCode.AffiliateType), "Code", "Desc");
|
||||
}
|
||||
|
||||
/// <summary>List of Association Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> AssociationTypeCodesForSelect
|
||||
public IEnumerable<SelectListItem> GetAssociationTypeCodesForSelect()
|
||||
{
|
||||
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.AssociationType), "Code", "Desc"); }
|
||||
return new SelectList(GetCodesOfType(Sbm.SystemCode.AssociationType), "Code", "Desc");
|
||||
}
|
||||
|
||||
/// <summary>List of Commodity Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> CommodityTypeCodesForSelect
|
||||
public IEnumerable<SelectListItem> GetCommodityTypeCodesForSelect()
|
||||
{
|
||||
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.CommodityType), "Code", "Desc"); }
|
||||
|
||||
return new SelectList(GetCodesOfType(Sbm.SystemCode.CommodityType), "Code", "Desc");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user