Add project files.
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
using Microsoft.AspNetCore.Mvc.Localization;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr
|
||||
{
|
||||
// <summary>
|
||||
/// Dummy class to group shared resources - named as per '.resx' file in root namespace.
|
||||
/// <para>Required to create the IStringLocalizer instance using the type from the class.</para>
|
||||
/// <para>Name of the class is used as the prefix for localisation filenames.</para>
|
||||
/// <para>Resource files are in the Localization ResourcesPath in Startup.cs.</para>
|
||||
/// </summary>
|
||||
public class OpnProperties { }
|
||||
// Class must be in Root/Default Namespace to reference properties with same name.
|
||||
// NB 'Assembly name' must be the same as 'Default Namespace' until 'Root Namespace' can be set (.Net Core 2.1?).
|
||||
// Ref. Project Properties - Application.
|
||||
}
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnLocaliser
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly IStringLocalizer<OpnProperties> opnLocalizer;
|
||||
private readonly IHtmlLocalizer<OpnProperties> opnHtmlLocalizer;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Localisers are supplied using construction injection.
|
||||
/// </summary>
|
||||
public OpnLocaliser (IStringLocalizer<OpnProperties> opnLocalizer, IHtmlLocalizer<OpnProperties> opnHtmlLocalizer)
|
||||
{
|
||||
this.opnLocalizer = opnLocalizer;
|
||||
this.opnHtmlLocalizer = opnHtmlLocalizer;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Retrieve localised text.</summary>
|
||||
public LocalizedString GetText (string key)
|
||||
{
|
||||
return GetText(key, new object[] { });
|
||||
}
|
||||
public LocalizedString GetText (string key, string param)
|
||||
{
|
||||
return GetText(key, new object[] { param });
|
||||
}
|
||||
public LocalizedString GetText (string key, string param1, string param2)
|
||||
{
|
||||
return GetText(key, new object[] { param1, param2 });
|
||||
}
|
||||
public LocalizedString GetText (string key, object[] parameters)
|
||||
{
|
||||
return opnLocalizer.GetString(key, parameters);
|
||||
}
|
||||
public LocalizedString this[String key]
|
||||
{
|
||||
get { return GetText(key); }
|
||||
}
|
||||
public LocalizedString this[String key, String param]
|
||||
{
|
||||
get { return GetText(key, param); }
|
||||
}
|
||||
public LocalizedString this[String key, String param1, String param2]
|
||||
{
|
||||
get { return GetText(key, param1, param2); }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Localised HTML text.
|
||||
/// <para>Line delimiters changed to '<br/>'.</para>
|
||||
/// </summary>
|
||||
public LocalizedString GetHtmlText (string key)
|
||||
{
|
||||
LocalizedString localisedText = GetText(key);
|
||||
String value = localisedText.Value;
|
||||
// Replace all line delimiters.
|
||||
value = value.Replace("\r\n", "\n").Replace("\n", "<br/>").Replace("\r", "<br/>");
|
||||
return new LocalizedString(localisedText, value, localisedText.ResourceNotFound);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Localised javascript string.
|
||||
/// <para>All quotes are escaped.</para>
|
||||
/// </summary>
|
||||
public LocalizedString GetJavascriptText (string key)
|
||||
{
|
||||
LocalizedString localisedText = GetText(key);
|
||||
return new LocalizedString(localisedText, EscapeJavascriptText(localisedText.Value), localisedText.ResourceNotFound);
|
||||
}
|
||||
public String EscapeJavascriptText (string value)
|
||||
{
|
||||
// Escape all quotes.
|
||||
value = value.Replace("'", "\\'").Replace("\"", "\\\"");
|
||||
return value;
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class Program
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
host.Run();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
// Sarand OperationsMgr Web user session data.
|
||||
// NB private setters are required for JSON deserialisation.
|
||||
//=======================================================================
|
||||
public class SessionData
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SessionData (OpnSessionContext sessionContext, SysId userId, String userCode, String userName)
|
||||
{
|
||||
SessionContext = sessionContext;
|
||||
User = new UserData(userId, userCode, userName);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public OpnSessionContext SessionContext { get; }
|
||||
public Opn.Instance Instance { get { return SessionContext.Instance; } }
|
||||
public String InstanceCode { get { return OpnSystem.GetInstanceCode(Instance); } }
|
||||
public String InstanceDesc { get { return OpnSystem.GetInstanceDesc(Instance); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User data.
|
||||
public class UserData
|
||||
{
|
||||
public UserData (SysId userId, String userCode, String userName)
|
||||
{
|
||||
Id = userId;
|
||||
Code = userCode;
|
||||
Name = userName;
|
||||
}
|
||||
public SysId Id { get; private set; }
|
||||
public String Code { get; private set; }
|
||||
public String Name { get; private set; }
|
||||
}
|
||||
public UserData User { get; private set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.AspNetCore.Mvc.Razor;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.OperationsMgr.Web.System;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class Startup
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SaOperationsMgrWebApp app = null;
|
||||
// Localisation.
|
||||
private static RequestCulture defaultRequestCulture = new RequestCulture("en-GB", "en-GB");
|
||||
private static List<CultureInfo> supportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("en-GB"),
|
||||
new CultureInfo("en-US"),
|
||||
new CultureInfo("en"),
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public Startup (IHostingEnvironment env)
|
||||
{
|
||||
String fn = "SaOperationsMgrWeb.Startup";
|
||||
|
||||
// Load server configuration.
|
||||
String machineName = Environment.MachineName;
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.machine.{machineName}.json", optional: false, reloadOnChange: true)
|
||||
.AddEnvironmentVariables();
|
||||
Logger.Info(fn + " EnvironmentName: " + env.EnvironmentName + ". MachineName: " + machineName + ".");
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
|
||||
builder.AddApplicationInsightsSettings(developerMode: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Staging, Production.
|
||||
}
|
||||
Configuration = builder.Build();
|
||||
|
||||
// Avoid automatic binding of model properties.
|
||||
// Ref. https://stackoverflow.com/questions/2211829/why-does-asp-net-mvc-care-about-my-read-only-properties-during-databinding
|
||||
//DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
|
||||
|
||||
// Initialise application:
|
||||
app = new SaOperationsMgrWebApp(env, Configuration.GetSection("SessionContexts"), Opn.ApplicationCaption + " Startup");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices (IServiceCollection services)
|
||||
{
|
||||
// Add framework services.
|
||||
services.AddApplicationInsightsTelemetry(Configuration);
|
||||
|
||||
// Aug-2017 Added to support memory caching of sessions.
|
||||
services.AddMemoryCache();
|
||||
//services.AddDistributedMemoryCache(); - for multiple web servers.
|
||||
services.AddSession
|
||||
(options =>
|
||||
{
|
||||
/* Default cookie name: '.AspNetCore.Session' */
|
||||
options.CookieName = "SaOperationsMgr.Session";
|
||||
options.IdleTimeout = SacsSystem.DebugMode ? TimeSpan.FromMinutes(15) : TimeSpan.FromMinutes(30);
|
||||
options.CookieHttpOnly = true;
|
||||
}
|
||||
);
|
||||
|
||||
// Application localisation.
|
||||
services.AddSingleton<OpnLocaliser>();
|
||||
// Lovalisation properties folder.
|
||||
String resourcesPath = "Localisation";
|
||||
services.AddLocalization(opts => { opts.ResourcesPath = resourcesPath; });
|
||||
|
||||
services.AddMvc
|
||||
(options =>
|
||||
{
|
||||
// Model binding - intercepting form values being bound to models.
|
||||
options.ModelBinderProviders.Insert(0, new OpnModelBinderProvider());
|
||||
}
|
||||
)
|
||||
// View and data annotation localisations.
|
||||
.AddViewLocalization(
|
||||
LanguageViewLocationExpanderFormat.Suffix,
|
||||
opts => { opts.ResourcesPath = resourcesPath; })
|
||||
.AddDataAnnotationsLocalization();
|
||||
|
||||
// Configure localisation middleware.
|
||||
services.Configure<RequestLocalizationOptions>
|
||||
(opts =>
|
||||
{
|
||||
// Default culture to use for requests.
|
||||
opts.DefaultRequestCulture = defaultRequestCulture;
|
||||
// Cultures supported by the application. Formatting numbers, dates, etc.
|
||||
opts.SupportedCultures = supportedCultures;
|
||||
// UI cultures supported by the application. UI strings that have been localized.
|
||||
opts.SupportedUICultures = supportedCultures;
|
||||
}
|
||||
);
|
||||
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
// Application insights telemetry for requests.
|
||||
//app.UseApplicationInsightsRequestTelemetry();
|
||||
//app.UseApplicationInsightsExceptionTelemetry();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
//app.UseBrowserLink();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
|
||||
// Enable static file serving.
|
||||
app.UseStaticFiles();
|
||||
|
||||
// Localisation.
|
||||
var localisationOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
|
||||
app.UseRequestLocalization(localisationOptions.Value);
|
||||
|
||||
// Initialise session handling.
|
||||
app.UseSession();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Sarand.OperationsMgr.App.Consoles;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.Win.Dbas.CodeTypes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnCodeTypeConsole_Web : OpnCodeTypeConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnCodeTypeConsole_Web(OpnSessionContext sessionContext, SacsDatabase database) :
|
||||
base (database)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Method to display Code Types dialog.
|
||||
protected override MaintainCodeTypesFunction MaintainCodeTypesFn
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using Sarand.Core.CodeTypes;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.ItemOptions;
|
||||
using Sarand.Core.ReferenceData;
|
||||
using Sarand.Core.Security;
|
||||
using Sarand.Core.UpdateLog;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.OperationsMgr.Web.App;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static Sarand.OperationsMgr.Web.App.SaOperationsMgrWebApp;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnConsoleHelper_Web : OpnConsoleHelper
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Session console data.
|
||||
private class ConsoleData
|
||||
{
|
||||
public OpnSecurityConsole_Web SecurityConsole { get; set; }
|
||||
public OpnCodeTypeConsole_Web CodeTypeConsole { get; set; }
|
||||
public OpnReferenceDataConsole_Web ReferenceDataConsole { get; set; }
|
||||
public OpnItemOptionConsole_Web ItemOptionConsole { get; set; }
|
||||
public OpnInterfaceConsole_Web InterfaceConsole { get; set; }
|
||||
public OpnUpdateLogConsole_Web UpdateLogConsole { get; set; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Dictionary<ushort, ConsoleData> sessionConsoleData = new Dictionary<ushort, ConsoleData>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnConsoleHelper_Web ()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
private SaOperationsMgrWebApp App { get { return SaOperationsMgrWebApp.GetInstance(); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session context configuration.
|
||||
private SessionContextConfig GetSessionContextConfig (OpnSessionContext sessionContext)
|
||||
{
|
||||
return App.GetSessionContextConfig(sessionContext.Index);
|
||||
}
|
||||
private ConsoleData GetConsoleData (OpnSessionContext sessionContext)
|
||||
{
|
||||
// Add console data for this session if not already defined.
|
||||
if (!sessionConsoleData.ContainsKey(sessionContext.Index))
|
||||
sessionConsoleData[sessionContext.Index] = new ConsoleData();
|
||||
return sessionConsoleData[sessionContext.Index];
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Database.
|
||||
public override ISacsDatabase GetDatabase (OpnSessionContext sessionContext)
|
||||
{
|
||||
SessionContextConfig sessionContextConfig = GetSessionContextConfig(sessionContext);
|
||||
if (sessionContextConfig != null)
|
||||
return sessionContextConfig.Database;
|
||||
return null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security console.
|
||||
public override SaSecurityConsole GetSecurityConsole (OpnSessionContext sessionContext)
|
||||
{
|
||||
ConsoleData consoleData = GetConsoleData(sessionContext);
|
||||
if (consoleData.SecurityConsole == null)
|
||||
{
|
||||
consoleData.SecurityConsole = new OpnSecurityConsole_Web(sessionContext, GetDatabase(sessionContext) as SacsDatabase);
|
||||
consoleData.SecurityConsole.LogSecurityProfile = OpnGlobals.System.IsExtendedLogging(OpnSystem.ExtendedLogginOption.SecurityProfile);
|
||||
consoleData.SecurityConsole.RegisterSecurityRights();
|
||||
}
|
||||
return consoleData.SecurityConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Code Type console.
|
||||
public override SaCodeTypeConsole GetCodeTypeConsole (OpnSessionContext sessionContext)
|
||||
{
|
||||
ConsoleData consoleData = GetConsoleData(sessionContext);
|
||||
if (consoleData.CodeTypeConsole == null)
|
||||
{
|
||||
consoleData.CodeTypeConsole = new OpnCodeTypeConsole_Web(sessionContext, GetDatabase(sessionContext) as SacsDatabase);
|
||||
OpnSystem.RegisterCodeTypes(consoleData.CodeTypeConsole, sessionContext.Instance);
|
||||
}
|
||||
return consoleData.CodeTypeConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Reference Data console.
|
||||
public override SaReferenceDataConsole GetReferenceDataConsole (OpnSessionContext sessionContext)
|
||||
{
|
||||
ConsoleData consoleData = GetConsoleData(sessionContext);
|
||||
if (consoleData.ReferenceDataConsole == null)
|
||||
{
|
||||
consoleData.ReferenceDataConsole = new OpnReferenceDataConsole_Web(sessionContext, GetDatabase(sessionContext) as SacsDatabase);
|
||||
}
|
||||
return consoleData.ReferenceDataConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item option console.
|
||||
public override SaItemOptionConsole GetItemOptionConsole (OpnSessionContext sessionContext)
|
||||
{
|
||||
ConsoleData consoleData = GetConsoleData(sessionContext);
|
||||
if (consoleData.ItemOptionConsole == null)
|
||||
{
|
||||
consoleData.ItemOptionConsole = new OpnItemOptionConsole_Web(sessionContext, GetDatabase(sessionContext) as SacsDatabase);
|
||||
}
|
||||
return consoleData.ItemOptionConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Interface console.
|
||||
public override SaInterfaceConsole GetInterfaceConsole (OpnSessionContext sessionContext)
|
||||
{
|
||||
ConsoleData consoleData = GetConsoleData(sessionContext);
|
||||
if (consoleData.InterfaceConsole == null)
|
||||
{
|
||||
consoleData.InterfaceConsole = new OpnInterfaceConsole_Web(sessionContext, GetDatabase(sessionContext) as SacsDatabase);
|
||||
//consoleData.InterfaceConsole.RegisterInterfaces(sessionContext.Instance);
|
||||
}
|
||||
return consoleData.InterfaceConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Log console.
|
||||
public override SaUpdateLogConsole GetUpdateLogConsole (OpnSessionContext sessionContext)
|
||||
{
|
||||
ConsoleData consoleData = GetConsoleData(sessionContext);
|
||||
if (consoleData.UpdateLogConsole == null)
|
||||
{
|
||||
consoleData.UpdateLogConsole = new OpnUpdateLogConsole_Web(sessionContext, GetDatabase(sessionContext) as SacsDatabase);
|
||||
}
|
||||
return consoleData.UpdateLogConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.ItemOptions;
|
||||
using Sarand.Core.Procs;
|
||||
using Sarand.OperationsMgr.App.Consoles;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.OperationsMgr.Win.Consoles;
|
||||
using Sarand.OperationsMgr.Win.Interfaces;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnInterfaceConsole_Web : OpnInterfaceConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
//private List<TypeCodeDesc> dataItemTypes = OpnSystem.GetCodesOfType(Opn.SystemCode.DataItemType);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnInterfaceConsole_Web (OpnSessionContext sessionContext, SacsDatabase database) :
|
||||
base(null)
|
||||
{
|
||||
Database = database;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
internal Opn.Instance Instance { get { return SessionContext.Instance; } }
|
||||
internal SacsDatabase Database { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Method to display Interface management form.
|
||||
protected override MaintainInterfacesFunction MaintainInterfacesFn
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Interface item option definitions.
|
||||
public override List<SaItemOptionDfn> GetInterfaceItemOptionDfns (SaInterfaceCategory interfaceCategory, short interfaceType)
|
||||
{
|
||||
return OpnProcessConsole.GetInterfaceItemOptionDfns(interfaceCategory, interfaceType);
|
||||
}
|
||||
public override List<SaItemOptionDfn> GetInterfaceItemOptionDfns (SysId interfaceId)
|
||||
{
|
||||
SaInterface interfaceObj = GetInterfaceById(interfaceId);
|
||||
if (interfaceObj != null)
|
||||
return OpnProcessConsole.GetInterfaceItemOptionDfns(interfaceObj.Category, interfaceObj.Type);
|
||||
return new List<SaItemOptionDfn>();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// I n t e r f a c e A c c e s s C o n t r o l
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// P r o c e s s i n g O p t i o n s
|
||||
//---------------------------------------------------------------
|
||||
private List<SacsProcess.GroupData> GetProcessingOptions (SaInterface interfaceObj)
|
||||
{
|
||||
if (interfaceObj != null && SysId.IsValid(interfaceObj.Id))
|
||||
{
|
||||
switch (interfaceObj.Category)
|
||||
{
|
||||
case SaInterfaceCategory.System:
|
||||
return GetProcessingOptions_System(interfaceObj);
|
||||
}
|
||||
}
|
||||
return new List<SacsProcess.GroupData>();
|
||||
}
|
||||
private List<SacsProcess.GroupData> GetProcessingOptions_System (SaInterface interfaceObj)
|
||||
{
|
||||
if (interfaceObj.Category != SaInterfaceCategory.System) throw new NotSupportedException("Invalid interface category: " + interfaceObj.Category.ToString() + ". Expected: System");
|
||||
List<SacsProcess.GroupData> optionGroups = null;
|
||||
//switch ((Opn.InterfaceType)interfaceObj.Type)
|
||||
//{
|
||||
//}
|
||||
return optionGroups ?? new List<SacsProcess.GroupData>();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// P r o c e s s I n t e r f a c e
|
||||
//---------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Interface can only be 'processed' if it defines processing options.
|
||||
/// </summary>
|
||||
/// <param name="interfaceObj"></param>
|
||||
/// <returns></returns>
|
||||
public override bool CanProcessInterface (SaInterface interfaceObj)
|
||||
{
|
||||
return (GetProcessingOptions(interfaceObj).Count > 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Popup form to select options for processing interface.
|
||||
/// </summary>
|
||||
/// <param name="interfaceObj"></param>
|
||||
/// <returns></returns>
|
||||
public override bool ProcessInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
private OpnInterfaceProcess ConfigureProcess (SaInterface interfaceObj, SacsProcess.GroupData processGroup, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
switch (interfaceObj.Category)
|
||||
{
|
||||
case SaInterfaceCategory.System:
|
||||
return ConfigureProcess_System(interfaceObj, processGroup, dbUpdateInfo);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private OpnInterfaceProcess ConfigureProcess_System (SaInterface interfaceObj, SacsProcess.GroupData processGroup, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
if (interfaceObj.Category != SaInterfaceCategory.System) throw new NotSupportedException("Invalid interface category: " + interfaceObj.Category.ToString() + ". Expected: System");
|
||||
//switch ((Opn.InterfaceType)interfaceObj.Type)
|
||||
//{
|
||||
//}
|
||||
return null;
|
||||
}
|
||||
public override bool AreMultipleInterfaceInstancesAllowed (string context, SaInterfaceCategory interfaceCategory, short interfaceType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override bool AreMultipleActiveInterfacesAllowed (string context, SaInterfaceCategory interfaceCategory)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Sarand.OperationsMgr.App.Consoles;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnItemOptionConsole_Web : OpnItemOptionConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnItemOptionConsole_Web (OpnSessionContext sessionContext, SacsDatabase database) :
|
||||
base (database)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Method to display Security management dialog.
|
||||
protected override ShowItemOptionsDialogFunction ShowItemOptionsDialogFn
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Sarand.OperationsMgr.App.Consoles;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.Win.Dbas.ReferenceData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnReferenceDataConsole_Web : OpnReferenceDataConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnReferenceDataConsole_Web (OpnSessionContext sessionContext, SacsDatabase database) :
|
||||
base(null, database)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Method to display Reference Data Maintenance form.
|
||||
protected override MaintainReferenceDataFunction MaintainReferenceDataFn
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.OperationsMgr.App.Consoles;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnSecurityConsole_Web : OpnSecurityConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
//private List<TypeCodeDesc> securityRights = OpnSystem.GetCodesOfType(Opn.SystemCode.SecurityRight);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnSecurityConsole_Web(OpnSessionContext sessionContext, SacsDatabase database) :
|
||||
base (database)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security events.
|
||||
protected override bool OnLogin (SysId userId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
protected override void OnLogout ()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Method to show User Login form.
|
||||
protected override ShowUserLoginFormFunction ShowUserLoginFormFn
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Method to display Security management form.
|
||||
protected override ShowManageSecurityDialogFunction ShowManageSecurityDialogFn
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override bool OnUserModified (SysId userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override bool OnSecurityGroupModified (SysId secGroupId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Sarand.OperationsMgr.App.Consoles;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnUpdateLogConsole_Web : OpnUpdateLogConsole_Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnUpdateLogConsole_Web (OpnSessionContext sessionContext, SacsDatabase database) :
|
||||
base(database)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Method to display Security management dialog.
|
||||
protected override ShowUpdateLogDialogFunction ShowUpdateLogDialogFn
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.CodeTypes;
|
||||
using Sarand.Core.Security;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.OperationsMgr.Web.App;
|
||||
using Sarand.OperationsMgr.Web.Models;
|
||||
using Sarand.OperationsMgr.Web.System;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
public class Controller_Base : Controller
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private List<TypeCodeDesc> assetTypes;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction - use derived classes.
|
||||
protected Controller_Base (OpnLocaliser localiser) : base()
|
||||
{
|
||||
Localiser = localiser;
|
||||
|
||||
// Initialise console (debug) logging listener.
|
||||
if (Directory.Exists(App.LoggingRootFolder))
|
||||
OpnConsoleListener.ConfigureDebugListener(App.LoggingRootFolder);
|
||||
if (SacsSystem.DebugMode) Logger.Trace(GetType().Name + ".CTR");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected SaOperationsMgrWebApp App { get { return SaOperationsMgrWebApp.GetInstance(); } }
|
||||
public OpnLocaliser Localiser { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// C u l t u r e
|
||||
//-------------------------------------------------------------------
|
||||
private string LanguageIso2
|
||||
{
|
||||
get
|
||||
{
|
||||
var feature = HttpContext.Features.Get<IRequestCultureFeature>();
|
||||
return feature.RequestCulture.UICulture.TwoLetterISOLanguageName.ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// R e d i r e c t i o n L o c a t i o n s
|
||||
//-------------------------------------------------------------------
|
||||
protected enum RedirectLocation
|
||||
{
|
||||
Home,
|
||||
Home_SessionExpired,
|
||||
}
|
||||
protected String GetRedirectLocation (RedirectLocation redirectLocation)
|
||||
{
|
||||
switch (redirectLocation)
|
||||
{
|
||||
case RedirectLocation.Home:
|
||||
return "/Home";
|
||||
case RedirectLocation.Home_SessionExpired:
|
||||
return "/Home?SessionExpired";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// A c t i o n E v e n t s
|
||||
//-------------------------------------------------------------------
|
||||
public override void OnActionExecuting (ActionExecutingContext context)
|
||||
{
|
||||
//if (SacsSystem.DebugMode) Logger.Trace(GetType().Name + ".OnActionExecuting");
|
||||
base.OnActionExecuting(context);
|
||||
}
|
||||
public override void OnActionExecuted (ActionExecutedContext context)
|
||||
{
|
||||
//if (SacsSystem.DebugMode) Logger.Trace(GetType().Name + ".OnActionExecuted");
|
||||
ViewData["CopyrightNotice"] = new HtmlString(OpnSystem.GetCopyrightNotice(true));
|
||||
|
||||
// Refreh model properties.
|
||||
Model_Base baseModel = ViewData.Model as Model_Base;
|
||||
if (baseModel != null)
|
||||
{
|
||||
// Session data.
|
||||
baseModel.SessionData = SessionData;
|
||||
baseModel.AwaitingLogin = !ValidSession;
|
||||
|
||||
// Redirect locations.
|
||||
baseModel.RedirectLocation.Home = GetRedirectLocation(RedirectLocation.Home);
|
||||
baseModel.RedirectLocation.Home_SessionExpired = GetRedirectLocation(RedirectLocation.Home_SessionExpired);
|
||||
}
|
||||
|
||||
// Store session data if present - as potentially modfied.
|
||||
if (sessionData != null)
|
||||
{
|
||||
String sessionDataJson = JsonConvert.SerializeObject(sessionData);
|
||||
HttpContext.Session.Set(SessionKey_SessionConfig, sessionDataEncoding.GetBytes(sessionDataJson));
|
||||
if (baseModel != null)
|
||||
baseModel.SessionIdx = SessionData.SessionContext.Index;
|
||||
}
|
||||
|
||||
base.OnActionExecuted(context);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// M o d e l
|
||||
//-------------------------------------------------------------------
|
||||
protected void InitModel (Model_Base model)
|
||||
{
|
||||
model.AwaitingLogin = !ValidSession;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// S e s s i o n
|
||||
//-------------------------------------------------------------------
|
||||
private SessionData sessionData;
|
||||
public static readonly String SessionKey_SessionConfig = "OpnUserSessionConfig";
|
||||
private static readonly Encoding sessionDataEncoding = Encoding.UTF8;
|
||||
private class OpnSessionDataContractResolver : DefaultContractResolver
|
||||
{
|
||||
// To allow private properties to be deserialised.
|
||||
protected override List<MemberInfo> GetSerializableMembers (Type objectType)
|
||||
{
|
||||
var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||
MemberInfo[] fields = objectType.GetFields(flags);
|
||||
return fields
|
||||
.Concat(objectType.GetProperties(flags).Where(propInfo => propInfo.CanWrite))
|
||||
.ToList();
|
||||
}
|
||||
protected override IList<JsonProperty> CreateProperties (Type type, MemberSerialization memberSerialization)
|
||||
{
|
||||
return base.CreateProperties(type, MemberSerialization.Fields);
|
||||
}
|
||||
};
|
||||
JsonSerializerSettings OpnSessionDataJsonSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new OpnSessionDataContractResolver()
|
||||
};
|
||||
public bool ValidSession
|
||||
{
|
||||
get
|
||||
{
|
||||
return (SessionData != null && SysId.IsValid(SessionData.User.Id));
|
||||
}
|
||||
}
|
||||
public SessionData SessionData
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve session data if not already in controller.
|
||||
if (sessionData == null)
|
||||
{
|
||||
byte[] sessionDataBytes = null;
|
||||
HttpContext.Session.TryGetValue(SessionKey_SessionConfig, out sessionDataBytes);
|
||||
if (sessionDataBytes != null)
|
||||
{
|
||||
String sessionDataJson = sessionDataEncoding.GetString(sessionDataBytes);
|
||||
sessionData = JsonConvert.DeserializeObject<SessionData>(sessionDataJson, OpnSessionDataJsonSerializerSettings);
|
||||
}
|
||||
}
|
||||
return sessionData;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".SessionData " + exc.GetType().Name + " - " + exc.Message + exc.GetStackEntries().Concat("", "\n\t"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
protected bool OpenUserSession (OpnSessionContext sessioContext, SysId userId, String userCode, String userName)
|
||||
{
|
||||
// Validate user properties.
|
||||
if (!SysId.IsValid(userId)) return false;
|
||||
if (StringUtil.IsEmpty(userCode)) return false;
|
||||
if (StringUtil.IsEmpty(userName)) return false;
|
||||
|
||||
// Close previous session.
|
||||
CloseUserSession();
|
||||
|
||||
// Open session.
|
||||
sessionData = new SessionData(sessioContext, userId, userCode, userName);
|
||||
|
||||
return true;
|
||||
}
|
||||
protected void CloseUserSession ()
|
||||
{
|
||||
HttpContext.Session.Clear();
|
||||
sessionData = null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// A j a x A c t i o n s
|
||||
//-------------------------------------------------------------------
|
||||
protected static readonly Encoding ajaxResponseEncoding = Encoding.UTF8;
|
||||
public class AjaxResponse
|
||||
{
|
||||
// Response status.
|
||||
public bool Success { get; set; } = false;
|
||||
public bool SessionExpired { get; private set; } = false;
|
||||
public bool GoHome { get; private set; } = false;
|
||||
public AjaxResponse SetSessionExpired (String title, String text)
|
||||
{
|
||||
SessionExpired = true;
|
||||
return SetMessage(title, text);
|
||||
}
|
||||
public AjaxResponse SetGoHome (String title, String text)
|
||||
{
|
||||
GoHome = true;
|
||||
return SetMessage(title, text);
|
||||
}
|
||||
// Message - displays alert popup.
|
||||
public class MessageData
|
||||
{
|
||||
public String Title { get; set; }
|
||||
public String Text { get; set; }
|
||||
}
|
||||
public MessageData Message { get; private set; }
|
||||
public AjaxResponse SetMessage (String title, String text)
|
||||
{
|
||||
Message = new MessageData() { Title = title, Text = text };
|
||||
return this;
|
||||
}
|
||||
// Notification - briefly displays after response received.
|
||||
public class NotificationData
|
||||
{
|
||||
public String Title { get; set; }
|
||||
public String Message { get; set; }
|
||||
}
|
||||
public NotificationData Notification { get; private set; }
|
||||
public bool HasNotification { get { return Notification != null; } }
|
||||
public AjaxResponse SetNotification (String title, String message)
|
||||
{
|
||||
Notification = new NotificationData() { Title = title, Message = message };
|
||||
return this;
|
||||
}
|
||||
// Paged data.
|
||||
public class PagingData
|
||||
{
|
||||
public bool Paged { get { return (PageNo > 0 && PageLength > 0 && ItemTotal > PageLength); } }
|
||||
public uint PageNo { get; set; } = 0;
|
||||
public ushort PageLength { get; set; } = 0;
|
||||
public uint PageCount { get { return (PageLength > 0 ? (uint)Math.Ceiling((decimal)ItemTotal / PageLength) : 0); } }
|
||||
public uint ItemCount { get; set; } = 0;
|
||||
public uint ItemTotal { get; set; } = 0;
|
||||
}
|
||||
public PagingData Paging { get; private set; }
|
||||
public void SetPaging (uint pageNo, ushort pageLength, uint itemCount, uint itemTotal)
|
||||
{
|
||||
Paging = new PagingData() { PageNo = pageNo, PageLength = pageLength, ItemCount = itemCount, ItemTotal = itemTotal };
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// S e s s i o n C o n t e x t
|
||||
//-------------------------------------------------------------------
|
||||
protected OpnSessionContext GetSessionContext ()
|
||||
{
|
||||
if (SessionData != null)
|
||||
return SessionData.SessionContext;
|
||||
Logger.Warn(GetType().Name + ".GetSessionContext() Session data is not available.");
|
||||
return null;
|
||||
}
|
||||
protected OpnSessionContext GetSessionContext (ushort index)
|
||||
{
|
||||
try
|
||||
{
|
||||
return App.GetSessionContextConfig(index).SessionContext;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetSessionContext(" + index + ") " + exc.GetType().Name + " - " + exc.Message + exc.GetStackEntries().Concat("", "\n\t"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// D a t a b a s e
|
||||
//-------------------------------------------------------------------
|
||||
private OpnSessionContext databaseSessionContext;
|
||||
private SacsDatabase database = null;
|
||||
protected SacsDatabase GetDatabase ()
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetDatabase(GetSessionContext());
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetDatabase() " + exc.GetType().Name + " - " + exc.Message + exc.GetStackEntries().Concat("", "\n\t"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected SacsDatabase GetDatabase (OpnSessionContext sessionContext)
|
||||
{
|
||||
if (databaseSessionContext != null && databaseSessionContext.Equals(sessionContext)) return database;
|
||||
try
|
||||
{
|
||||
database = App.GetSessionContextConfig(sessionContext.Index).Database;
|
||||
databaseSessionContext = sessionContext;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetDatabase(" + sessionContext.Index + "," + OpnSystem.GetInstanceCode(sessionContext.Instance) + ") " + exc.GetType().Name + " - " + exc.Message + exc.GetStackEntries().Concat("", "\n\t"));
|
||||
}
|
||||
return database;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Managers.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security console.
|
||||
private SaSecurityConsole securityConsole;
|
||||
protected SaSecurityConsole SecurityConsole { get { if (securityConsole == null) securityConsole = OpnGlobals.ConsoleHelper.GetSecurityConsole(GetSessionContext()); return securityConsole; } }
|
||||
// Code Type console.
|
||||
private SaCodeTypeConsole codeTypeConsole;
|
||||
protected SaCodeTypeConsole CodeTypeConsole { get { if (codeTypeConsole == null) codeTypeConsole = OpnGlobals.ConsoleHelper.GetCodeTypeConsole(GetSessionContext()); return codeTypeConsole; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// C o n s o l e s
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Security;
|
||||
using Sarand.OperationsMgr.Core.App;
|
||||
using Sarand.OperationsMgr.Web.App;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
public class HomeController : Controller_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public HomeController (OpnLocaliser localiser) : base(localiser)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Home - Index.
|
||||
public IActionResult Index (Models.Model_Home_Index model)
|
||||
{
|
||||
Logger.Debug(GetType().Name + ".Index");
|
||||
if (HttpContext.Session != null)
|
||||
{
|
||||
foreach (var sessionKey in HttpContext.Session.Keys)
|
||||
{
|
||||
Logger.Debug(GetType().Name + ".Index Session key: " + sessionKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Actions.
|
||||
if (model.FormAction.EqualsCI(Localiser.GetText("form.action.login")))
|
||||
{
|
||||
// Validate login properties.
|
||||
if (StringUtil.IsEmpty(model.UserCode))
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.login.userCode.missing"));
|
||||
|
||||
// Retrieve session context.
|
||||
OpnSessionContext sessionContext = null;
|
||||
if (model.OK)
|
||||
{
|
||||
sessionContext = GetSessionContext(model.InstanceIdx);
|
||||
if (sessionContext == null)
|
||||
{
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.sessionContext.unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve security console.
|
||||
SaSecurityConsole securityConsole = null;
|
||||
if (model.OK)
|
||||
{
|
||||
securityConsole = OpnGlobals.ConsoleHelper.GetSecurityConsole(sessionContext);
|
||||
if (securityConsole == null)
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.securityConsole.unavailable"));
|
||||
}
|
||||
|
||||
// Retrieve and validate user.
|
||||
SaSecurityItem secItemUser = null;
|
||||
if (model.OK)
|
||||
{
|
||||
secItemUser = securityConsole.GetUserByCode(model.UserCode);
|
||||
if (secItemUser == null)
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.login.credentials.invalid"));
|
||||
}
|
||||
// Start user session.
|
||||
if (model.OK)
|
||||
{
|
||||
if (OpenUserSession(sessionContext, secItemUser.Id, secItemUser.Code, secItemUser.Description))
|
||||
Logger.Info("User logged in: " + secItemUser.Description + ". Instance: " + sessionContext.InstanceCode);
|
||||
}
|
||||
}
|
||||
else if (model.FormAction.EqualsCI(Localiser.GetText("form.action.logout")))
|
||||
{
|
||||
// Make a note of the session index for the login form.
|
||||
model.InstanceIdx = model.SessionIdx;
|
||||
|
||||
// Clear user session.
|
||||
// NB Session Data may not be available, eg. if session has timed out.
|
||||
if (SessionData != null)
|
||||
{
|
||||
String userName = SessionData.User.Name;
|
||||
String instanceCode = OpnSystem.GetInstanceCode(SessionData.Instance);
|
||||
Logger.Info("User logging out: " + userName + ". Instance: " + instanceCode);
|
||||
}
|
||||
else Logger.Warn("User logging out - session has expired.");
|
||||
CloseUserSession();
|
||||
}
|
||||
else if (model.SessionExpired != null)
|
||||
model.AddWarningMessage(Localiser.GetHtmlText("msg.warn.session.expired"));
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public IActionResult Error ()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.OperationsMgr.Web.App;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly List<String> infoMessages = new List<string>();
|
||||
private readonly List<String> warningMessages = new List<string>();
|
||||
private readonly List<String> errorMessages = new List<string>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction - use derived class.
|
||||
protected Model_Base ()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Application properties.
|
||||
protected SaOperationsMgrWebApp App { get { return SaOperationsMgrWebApp.GetInstance(); } }
|
||||
public bool OK { get { return !HasMessages; } }
|
||||
public bool AwaitingLogin { get; set; } = true;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session profile.
|
||||
public SessionData SessionData { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Business Object Managers.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Version parameter for includes.
|
||||
public String HrefVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime versionDate = SacsSystem.AssemblyBuildAt;
|
||||
if (!DateUtil.IsValid(versionDate) || SacsSystem.DebugMode)
|
||||
versionDate = DateTime.Now;
|
||||
return DateUtil.Format(versionDate, "yyyyMMdd" /*+ (SacsSystem.Debug ? "HHmm" : "")*/);
|
||||
}
|
||||
}
|
||||
// Additional includes.
|
||||
public List<String> AdditionalFiles_CSS { get; set; } = new List<string>();
|
||||
public List<String> AdditionalFiles_JS { get; set; } = new List<string>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Redirection locations.
|
||||
public class RedirectLocationData
|
||||
{
|
||||
// Properties populated in Controller_Base.OnActionExecuted.
|
||||
public String Home { get; internal set; }
|
||||
public String Home_SessionExpired { get; internal set; }
|
||||
}
|
||||
public RedirectLocationData RedirectLocation { get; } = new RedirectLocationData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Paging properties.
|
||||
private readonly DbQuery.Paging dataPaging = new DbQuery.Paging();
|
||||
public bool DataPaged { get { return dataPaging.Paged; } }
|
||||
public uint DataPageNo { get { return dataPaging.PageNo; } set { dataPaging.PageNo = value; } }
|
||||
public ushort DataPageLength { get { return dataPaging.PageLength; } set { dataPaging.PageLength = value; } }
|
||||
public uint DataPageCount { get { return (DataPageLength > 0 ? (uint)Math.Ceiling((decimal)DataItemTotal / DataPageLength) : 0); } }
|
||||
public uint DataItemCount { get; set; }
|
||||
public uint DataItemTotal { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form properties.
|
||||
/// <summary>
|
||||
/// User session index to identify the site resources, eg. database.
|
||||
/// <para>Equivalent to the Site index on the login form.</para>
|
||||
/// <para>Populates value on logout form to identify default site for next login.</para>
|
||||
/// </summary>
|
||||
public ushort SessionIdx { get; set; }
|
||||
public String FormAction { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Message properties.
|
||||
public virtual bool ShowMessagesAtTopOfBody { get; } = true;
|
||||
public bool HasMessages { get { return (infoMessages.Count > 0 || warningMessages.Count > 0 || errorMessages.Count > 0); } }
|
||||
public List<String> InfoMessages { get { return new List<string>(infoMessages); } }
|
||||
public List<String> WarningMessages { get { return new List<string>(warningMessages); } }
|
||||
public List<String> ErrorMessages { get { return new List<string>(errorMessages); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form messages.
|
||||
public void AddInfoMessage (String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||
infoMessages.Add(message);
|
||||
}
|
||||
public void AddWarningMessage (String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||
warningMessages.Add(message);
|
||||
}
|
||||
public void AddErrorMessage (String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||
errorMessages.Add(message);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static Sarand.OperationsMgr.Web.App.SaOperationsMgrWebApp;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_Home_Index : Model_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private List<SelectListItem> instances = null;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form properties.
|
||||
public ushort InstanceIdx { get; set; } = 0;
|
||||
public String UserCode { get; set; }
|
||||
public String UserPwrd { get; set; }
|
||||
public String SessionExpired { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// I n s t a n c e s
|
||||
//-------------------------------------------------------------------
|
||||
public IEnumerable<SelectListItem> Instances
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SacsSystem.DebugMode) Logger.Trace(GetType().Name + ".GetInstances()");
|
||||
if (instances == null)
|
||||
{
|
||||
// Populate list of instances.
|
||||
instances = new List<SelectListItem>();
|
||||
foreach (ushort sessionContextConfigIndex in App.GetSessionContextIndices())
|
||||
{
|
||||
SessionContextConfig sessionContextConfig = App.GetSessionContextConfig(sessionContextConfigIndex);
|
||||
if (sessionContextConfig != null)
|
||||
{
|
||||
instances.Add(new SelectListItem() { Value = sessionContextConfig.SessionContext.Index.ToString(), Text = sessionContextConfig.Caption });
|
||||
}
|
||||
}
|
||||
Logger.Debug(GetType().Name + ".Instances Populated instances: " + instances.Count);
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.System
|
||||
{
|
||||
//=======================================================================
|
||||
public class OpnConsoleListener : TextWriterTraceListener
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnConsoleListener() : base()
|
||||
{
|
||||
base.Name = DefaultName;
|
||||
base.Writer = null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public static String DefaultName { get; } = "SaOperationssMgr_Console";
|
||||
public String OutputPath { get; private set; } = "";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Configure Debug listener.
|
||||
public static bool ConfigureDebugListener (String logsRootFolder)
|
||||
{
|
||||
// Locate existing console listener.
|
||||
OpnConsoleListener consoleListener = null;
|
||||
foreach (TraceListener listener in global::System.Diagnostics.Debug.Listeners)
|
||||
{
|
||||
consoleListener = listener as OpnConsoleListener;
|
||||
if (consoleListener != null)
|
||||
break;
|
||||
}
|
||||
// If no console listener found, add one to the list.
|
||||
if (consoleListener == null)
|
||||
{
|
||||
consoleListener = new OpnConsoleListener();
|
||||
global::System.Diagnostics.Debug.Listeners.Add(consoleListener);
|
||||
}
|
||||
// Set the console listener's output file.
|
||||
if (consoleListener != null)
|
||||
consoleListener.RefreshOutputFile(logsRootFolder);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Output file.
|
||||
public bool RefreshOutputFile (String logsRootFolder)
|
||||
{
|
||||
// Take the opportunity to flush existing output.
|
||||
Flush();
|
||||
|
||||
// Generate complete log folder path.
|
||||
String logsFolder = logsRootFolder + Path.DirectorySeparatorChar + DateUtil.Format(DateTime.Now, "yyyy") + Path.DirectorySeparatorChar + DateUtil.Format(DateTime.Now, "yyyyMM");
|
||||
if (!FileUtil.ValidateDirectory(logsFolder, true))
|
||||
return false;
|
||||
|
||||
// Generate log filename.
|
||||
String outputPath = logsFolder + Path.DirectorySeparatorChar + "OPN-Web-" + DateUtil.Format(DateTime.Now, "yyyyMMdd") + "-Console.log";
|
||||
if (Writer != null && !OutputPath.EqualsCI(outputPath))
|
||||
{
|
||||
// Close existing writer.
|
||||
Writer.Close();
|
||||
Writer.Dispose();
|
||||
Writer = null;
|
||||
}
|
||||
// Assign new writer.
|
||||
if (Writer == null)
|
||||
Writer = new StreamWriter(OutputPath = outputPath, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.Base;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.System
|
||||
{
|
||||
//=======================================================================
|
||||
/// <summary>
|
||||
/// Maps a browser request to a data object. Default class provides a base implementation of a model binder.
|
||||
/// <para>Overridden to trim whitespace from input values.</para>
|
||||
/// </summary>
|
||||
public class OpnModelBinder : IModelBinder
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public OpnModelBinder ()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public Task BindModelAsync (ModelBindingContext bindingContext)
|
||||
{
|
||||
// Ignore selected properties by name.
|
||||
var modelName = bindingContext.ModelName;
|
||||
if (modelName == "RetainAllWhiteSpace")
|
||||
return Task.CompletedTask;
|
||||
|
||||
ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
|
||||
if (valueProviderResult == ValueProviderResult.None)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// Trim text values.
|
||||
bindingContext.Result = ModelBindingResult.Success(valueProviderResult.FirstValue.TrimAll());
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.OperationsMgr.Web.System
|
||||
{
|
||||
//=======================================================================
|
||||
/// <summary>
|
||||
/// Maps a browser request to a data object. Default class provides a base implementation of a model binder.
|
||||
/// <para>Overridden to trim whitespace from input values.</para>
|
||||
/// </summary>
|
||||
public class OpnModelBinderProvider : IModelBinderProvider
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
public OpnModelBinderProvider ()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public IModelBinder GetBinder (ModelBinderProviderContext context)
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
|
||||
// Intercept String form values.
|
||||
if (context.Metadata.ModelType == typeof(string))
|
||||
return new BinderTypeModelBinder(typeof(OpnModelBinder));
|
||||
|
||||
// Default - return null so that default binding provider is used.
|
||||
return null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user