71 lines
3.0 KiB
C#
71 lines
3.0 KiB
C#
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;
|
|
}
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|