72 lines
3.0 KiB
C#
72 lines
3.0 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
|
|
namespace Saxonite.Net.Core.Web.Base.Helpers
|
|
{
|
|
//=======================================================================
|
|
public static class SaxSessionConfigHelper
|
|
{
|
|
//-------------------------------------------------------------------
|
|
public static Dictionary<String, SaxSessionConfig> 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, SaxSessionConfig> sessionConfigs = new Dictionary<String, SaxSessionConfig>();
|
|
|
|
// Start the list with a default 'Defaults' configuration - values set to application defaults (defined in Sax).
|
|
// 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.
|
|
SaxSessionConfig defaultsSessionConfig = new SaxSessionConfig(Sax.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.
|
|
SaxSessionConfig sessionConfig = new SaxSessionConfig(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(Sax.Config.Context_Defaults))
|
|
defaultsSessionConfig = sessionConfig;
|
|
}
|
|
return sessionConfigs;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
public static class SessionConfigList
|
|
{
|
|
public static SaxSessionConfig getConfigForApplication(this List<SaxSessionConfig> sessionConfigs)
|
|
{
|
|
SaxSessionConfig defaultsSessionConfig = new SaxSessionConfig("", null, null);
|
|
SaxApplication_Base app = SaxGlobals.App;
|
|
if (app != null)
|
|
{
|
|
foreach (SaxSessionConfig sessionConfig in sessionConfigs)
|
|
{
|
|
if (sessionConfig.Environments.ContainsCI(app.EnvironmentName))
|
|
return sessionConfig;
|
|
if (sessionConfig.Context.EqualsCI(Sax.Config.Context_Defaults))
|
|
defaultsSessionConfig = sessionConfig;
|
|
}
|
|
}
|
|
return defaultsSessionConfig;
|
|
}
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|