This commit is contained in:
2021-07-23 14:01:49 +01:00
parent 10907d3aff
commit 0d7be69e1e
109 changed files with 3161 additions and 943 deletions
@@ -9,7 +9,7 @@ using System.Text;
namespace Saxonite.Net.Core.Web.Base.App
{
//=======================================================================
public class SaxSessionConfig
public class SaxAppConfig
{
//---------------------------------------------------------------
// Data members.
@@ -17,7 +17,7 @@ namespace Saxonite.Net.Core.Web.Base.App
//---------------------------------------------------------------
// Construction.
public SaxSessionConfig (String context, ConfigurationSection configSection, SaxSessionConfig defaultConfig)
public SaxAppConfig (String context, ConfigurationSection configSection, SaxAppConfig defaultConfig)
{
Context = context;
populateDefaults(defaultConfig);
@@ -25,7 +25,7 @@ namespace Saxonite.Net.Core.Web.Base.App
}
//---------------------------------------------------------------
private void populateDefaults(SaxSessionConfig defaultConfig)
private void populateDefaults(SaxAppConfig defaultConfig)
{
if (defaultConfig == null) return;
Security.Password.MinLength = defaultConfig.Security.Password.MinLength;
@@ -44,7 +44,7 @@ namespace Saxonite.Net.Core.Web.Base.App
// Application components.
public abstract String SessionCookieName { get; }
public virtual SaxSessionContext SessionContext { get; protected set; }
public abstract SaxSessionConfig SessionConfig { get; }
public abstract SaxAppConfig AppConfig { get; }
public override SaxConsoleHelper ConsoleHelper { get { return ConsoleHelper_Web; } }
public SaxConsoleHelper_Web ConsoleHelper_Web { get; protected set; }
public override IDatabaseInfo CreateCoreDbInfo(SaxSessionContext sessionContext) { return new DbDataItem.DatabaseInfo(GetCoreDatabase(sessionContext)); }
@@ -60,14 +60,14 @@ namespace Saxonite.Net.Core.Web.Base.App
List<StringPair> applicationParams = new List<StringPair>();
applicationParams.Add("Host", SaxSystem.ComputerName);
applicationParams.Add("Version", Sax.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", SaxSystem.DebugMode ? "Debug" : "Release");
applicationParams.Add("Environment", EnvironmentName);
applicationParams.Add("Database", SessionConfig.CoreDatabase.Location);
applicationParams.Add("Database", AppConfig.CoreDatabase.Location);
applicationParams.Add("Application root", SaxSystem.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);
if (StringUtil.IsEmpty(EmailConfig.SMTP.Server) || StringUtil.IsEmpty(EmailConfig.Message.AddressFrom))
SaLogger.Warn(fn + " Incomplete email configuration.", true);
+3 -1
View File
@@ -110,7 +110,9 @@ namespace Saxonite.Net.Core.Web.Base.App
.AddViewLocalization(
LanguageViewLocationExpanderFormat.Suffix,
opts => { opts.ResourcesPath = resourcesPath; })
.AddDataAnnotationsLocalization();
.AddDataAnnotationsLocalization()
// Ignore null values during object serisliation.
.AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; });
// Configure localisation middleware.
config.services.Configure<RequestLocalizationOptions>
@@ -61,7 +61,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
// Properties.
public bool DebugMode { get; } = SacsSystem.DebugMode;
protected SaxApplication_Web App { get { return SaxApplication_Web.WebApp; } }
public SaxSessionConfig SessionConfig { get { return App.SessionConfig; } }
public SaxAppConfig AppConfig { get { return App.AppConfig; } }
public SaxSessionContext SessionContext { get { return App.SessionContext; } }
protected SaxLocaliser Localiser { get; }
/// <summary>
@@ -164,10 +164,10 @@ namespace Saxonite.Net.Core.Web.Base.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)
@@ -293,7 +293,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
public class SessionStorage
{
public SaxSessionData SessionData { get; set; }
public static String SessionKey_SessionConfig { get; } = "SaxSessionData";
public static String SessionKey_SessionData { get; } = "SaxSessionData";
public static Encoding sessionDataEncoding { get; } = Encoding.UTF8;
//JSON Serialisation.
public class SaxSessionDataContractResolver : DefaultContractResolver
@@ -334,7 +334,7 @@ namespace Saxonite.Net.Core.Web.Base.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);
@@ -408,10 +408,37 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
//-------------------------------------------------------------------
public class AjaxResponse_Data : AjaxResponse_Base
{
//---------------------------------------------------------------
// Construction.
protected AjaxResponse_Data(SaxModel_Base model)
{
}
//---------------------------------------------------------------
// Item data.
public class ItemData_Base
{
// Common item properties.
public String Id { get; set; }
public String StatusCode { get; set; }
public String StatusDesc { get; set; }
// Flags for common status values.
// Return true or null so that property is not serialised when false.
public bool? Awaiting { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Awaiting)) ? true : (bool?)null; } }
public bool? Active { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Active)) ? true : (bool?)null; } }
public bool? Inactive { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Inactive)) ? true : (bool?)null; } }
public bool? Deleted { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Deleted)) ? true : (bool?)null; } }
/// <summary>Created on date - YYYYMMDD</summary>
public String CreatedOn { get; set; }
/// <summary>Created on date - formatted per locale</summary>
public String CreatedOnFmt { get; set; }
/// <summary>Updated on date - YYYYMMDD</summary>
public String UpdatedOn { get; set; }
/// <summary>Updated on date - formatted per locale</summary>
public String UpdatedOnFmt { get; set; }
}
//---------------------------------------------------------------
// Form data.
public class FormControlValue
{
@@ -464,6 +491,8 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
}
return false;
}
//---------------------------------------------------------------
// Notification - briefly displays after response received.
public class NotificationData
{
@@ -477,6 +506,8 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
Notification = new NotificationData() { Title = title, Message = message };
return this;
}
//---------------------------------------------------------------
// Paged data.
public class PagingData
{
@@ -502,6 +533,8 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
{
Paging = new PagingData(model);
}
//---------------------------------------------------------------
}
//-------------------------------------------------------------------
@@ -10,60 +10,60 @@ using Sarand.Net.Standard.Base.Utils;
namespace Saxonite.Net.Core.Web.Base.Helpers
{
//=======================================================================
public static class SaxSessionConfigHelper
public static class SaxAppConfigHelper
{
//-------------------------------------------------------------------
public static Dictionary<String, SaxSessionConfig> ExtractSessionConfigs(IConfigurationSection sessionConfigsSection)
public static Dictionary<String, SaxAppConfig> 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, SaxSessionConfig> sessionConfigs = new Dictionary<String, SaxSessionConfig>();
Dictionary<String, SaxAppConfig> appConfigs = new Dictionary<String, SaxAppConfig>();
// 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);
SaxAppConfig defaultsAppConfig = new SaxAppConfig(Sax.Config.Context_Defaults, null, null);
appConfigs.Add(defaultsAppConfig.Context, defaultsAppConfig);
// Load session configurations.
foreach (ConfigurationSection sessionConfigSection in sessionConfigsSection.GetChildren())
foreach (ConfigurationSection appConfigSection in appConfigsSection.GetChildren())
{
if (StringUtil.IsEmpty(sessionConfigSection.Key)) continue;
if (StringUtil.IsEmpty(appConfigSection.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);
SaxAppConfig appConfig = new SaxAppConfig(appConfigSection.Key, appConfigSection, defaultsAppConfig);
appConfigs.Remove(appConfigSection.Key);
appConfigs.Add(appConfigSection.Key, appConfig);
// Replace the 'Defaults' configuration if this one matches the context.
if (sessionConfig.Context.EqualsCI(Sax.Config.Context_Defaults))
defaultsSessionConfig = sessionConfig;
if (appConfig.Context.EqualsCI(Sax.Config.Context_Defaults))
defaultsAppConfig = appConfig;
}
return sessionConfigs;
return appConfigs;
}
//-------------------------------------------------------------------
}
//=======================================================================
public static class SessionConfigList
public static class AppConfigList
{
public static SaxSessionConfig getConfigForApplication(this List<SaxSessionConfig> sessionConfigs)
public static SaxAppConfig getConfigForApplication(this List<SaxAppConfig> appConfigs)
{
SaxSessionConfig defaultsSessionConfig = new SaxSessionConfig("", null, null);
SaxAppConfig defaultsAppConfig = new SaxAppConfig("", null, null);
SaxApplication_Base app = SaxGlobals.App;
if (app != null)
{
foreach (SaxSessionConfig sessionConfig in sessionConfigs)
foreach (SaxAppConfig appConfig in appConfigs)
{
if (sessionConfig.Environments.ContainsCI(app.EnvironmentName))
return sessionConfig;
if (sessionConfig.Context.EqualsCI(Sax.Config.Context_Defaults))
defaultsSessionConfig = sessionConfig;
if (appConfig.Environments.ContainsCI(app.EnvironmentName))
return appConfig;
if (appConfig.Context.EqualsCI(Sax.Config.Context_Defaults))
defaultsAppConfig = appConfig;
}
}
return defaultsSessionConfig;
return defaultsAppConfig;
}
}
@@ -76,13 +76,13 @@ namespace Saxonite.Net.Core.Web.Base.Helpers
//=======================================================================
public static class EmailConfigList
{
public static SaxEmailConfig getConfigForSession(this List<SaxEmailConfig> emailConfigs, SaxSessionConfig sessionConfig)
public static SaxEmailConfig getConfigForSession(this List<SaxEmailConfig> emailConfigs, SaxAppConfig appConfig)
{
if (sessionConfig != null && !StringUtil.IsEmpty(sessionConfig.Email.Context))
if (appConfig != null && !StringUtil.IsEmpty(appConfig.Email.Context))
{
foreach (SaxEmailConfig emailConfig in emailConfigs)
{
if (emailConfig.Context.EqualsCI(sessionConfig.Email.Context))
if (emailConfig.Context.EqualsCI(appConfig.Email.Context))
return emailConfig;
}
}
+2 -2
View File
@@ -35,7 +35,7 @@ namespace Saxonite.Net.Core.Web.Base.Models
//-------------------------------------------------------------------
// Application properties.
private SaxApplication_Web App { get { return SaxApplication_Web.WebApp; } }
protected SaxSessionConfig SessionConfig { get { return App.SessionConfig; } }
protected SaxAppConfig AppConfig { get { return App.AppConfig; } }
protected SaxSystem_Web System { get { return App.System_Web; } }
public String SessionCookieName { get { return App.SessionCookieName; } }
public SaxSessionData SessionData { get; set; }
@@ -49,7 +49,7 @@ namespace Saxonite.Net.Core.Web.Base.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" + Sax.Version.GetFullVersion() : "v" + Sax.Version.GetAppVersion(); } }
public String InstanceVersion { get { return !StringUtil.IsEmpty(App.AppConfig.Instance) ? App.AppConfig.Instance + " v" + Sax.Version.GetFullVersion() : "v" + Sax.Version.GetAppVersion(); } }
public bool IncludeGoogleAnalytics { get; set; } = false;
//-------------------------------------------------------------------