3.0.0.3 Control Repository Schema & Logs.
This commit is contained in:
@@ -123,6 +123,31 @@ namespace Sarand.BusinessMgr.Web.Control.App
|
||||
}
|
||||
public UserProfileData Profile { get; protected set; } = new UserProfileData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// System.
|
||||
public class SystemData
|
||||
{
|
||||
// Databases.
|
||||
public class DatabaseData
|
||||
{
|
||||
}
|
||||
public DatabaseData Database { get; private set; } = new DatabaseData();
|
||||
|
||||
// Logs.
|
||||
public class LogsData
|
||||
{
|
||||
public class FilterData
|
||||
{
|
||||
public String Folder { get; set; }
|
||||
public String Year { get; set; }
|
||||
public String Month { get; set; }
|
||||
}
|
||||
public FilterData Filter { get; private set; } = new FilterData();
|
||||
}
|
||||
public LogsData Logs { get; private set; } = new LogsData();
|
||||
}
|
||||
public SystemData System { get; private set; } = new SystemData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Control application encryption IV value - for consistent encryption during session.
|
||||
public String Base64IV_ControlApp { get; private set; } = SacsEncryptionHelper.InitSymmetricEncryptionIV(SbmController_Control.Base64Key_ControlApp);
|
||||
|
||||
+8
-8
@@ -17,7 +17,7 @@ using System.Linq;
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
//=======================================================================
|
||||
partial class CoreDatabaseController
|
||||
partial class RepositoryDatabaseController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
@@ -35,21 +35,21 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
//-------------------------------------------------------------------
|
||||
// Get Core Database Table list ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_CoreDatabaseTableList : AjaxResponse_Data
|
||||
private class AjaxResponse_RepositoryTableList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_CoreDatabaseTableList(SbmModel_Control model) : base(model) { }
|
||||
// CoreDatabase list.
|
||||
public AjaxResponse_RepositoryTableList(SbmModel_Control model) : base(model) { }
|
||||
// Table list.
|
||||
public List<TableListData> Tables { get; } = new List<TableListData>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Instance/CoreDatabase/Ajax/GetTableList")]
|
||||
[Route("Instance/CoreDatabase/Ajax/GetTables")]
|
||||
public IActionResult Ajax_GetTableList(Model_CoreDatabase model)
|
||||
[Route("Instance/Repository/Ajax/GetTableList")]
|
||||
[Route("Instance/Repository/Ajax/GetTables")]
|
||||
public IActionResult Ajax_GetTableList(Model_RepositoryDatabase model)
|
||||
{
|
||||
String messageTitle = Localiser["label.database"];
|
||||
AjaxResponse_CoreDatabaseTableList responseData = new AjaxResponse_CoreDatabaseTableList(model);
|
||||
AjaxResponse_RepositoryTableList responseData = new AjaxResponse_RepositoryTableList(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
+29
-5
@@ -3,25 +3,26 @@ using Microsoft.Extensions.Logging;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Web.Control.Components;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.Instance;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
//======================================================================
|
||||
public partial class CoreDatabaseController : SbmController_Control
|
||||
public partial class RepositoryDatabaseController : SbmController_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public CoreDatabaseController(SbmLocaliser localiser, ILogger<CoreDatabaseController> logger) :
|
||||
public RepositoryDatabaseController(SbmLocaliser localiser, ILogger<RepositoryDatabaseController> logger) :
|
||||
base(localiser, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
[Route("Instance/CoreDatabase")]
|
||||
public IActionResult Index(Model_CoreDatabase model)
|
||||
[Route("Instance/Repository/Database/Tables")]
|
||||
public IActionResult DatabaseTables(Model_RepositoryDatabase model)
|
||||
{
|
||||
if (!ValidUserSession)
|
||||
AutoLoginUser();
|
||||
@@ -38,7 +39,30 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
model.Filter.Context = SessionData_Control.Profile.Filter.InstanceContext;
|
||||
|
||||
// Core Database view.
|
||||
return View("Views/Instance/CoreDatabase/Index.cshtml", model);
|
||||
return View("Views/Instance/Repository/Database/Tables.cshtml", model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
[Route("Instance/Repository/Database/Schema")]
|
||||
public IActionResult Schema()
|
||||
{
|
||||
if (!ValidUserSession)
|
||||
AutoLoginUser();
|
||||
|
||||
// Redirect to sign-in if not signed-in.
|
||||
if (!ValidUserSession)
|
||||
{
|
||||
ClearKeepLoggedInCookie();
|
||||
return RedirectToAction("", "Security");
|
||||
}
|
||||
|
||||
// Refresh model.
|
||||
Model_System model = new Model_System(Localiser);
|
||||
RefreshModel(model);
|
||||
model.DatabaseFilter.Instance = SessionData_Control.Profile.Filter.InstanceContext;
|
||||
|
||||
// Core Database view.
|
||||
return View("Views/Instance/Repository/Database/Schema.cshtml", model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
+25
-6
@@ -72,7 +72,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
Sbm.Database databaseInstance = EnumUtil.ParseEnum(StringUtil.EmptyOnNull(model.DatabaseFilter.Instance), Sbm.Database.Unknown);
|
||||
if (databaseInstance <= 0)
|
||||
return Json(responseData.SetMessage(messageTitle, $"Database instance must be specified."));
|
||||
ISacsDatabase db = GetDatabase(databaseInstance);
|
||||
ISacsDatabase db = GetDatabase(databaseInstance, model.DatabaseFilter.Context);
|
||||
if (db == null)
|
||||
return Json(responseData.SetMessage(messageTitle, $"Database unavailable for instance '{databaseInstance}'."));
|
||||
|
||||
@@ -123,12 +123,14 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
/// <summary>
|
||||
/// Get database by type.
|
||||
/// </summary>
|
||||
private ISacsDatabase GetDatabase(Sbm.Database databaseInstance)
|
||||
private ISacsDatabase GetDatabase(Sbm.Database databaseInstance, String context)
|
||||
{
|
||||
switch (databaseInstance)
|
||||
{
|
||||
case Sbm.Database.Control:
|
||||
return App.GetControlDatabase();
|
||||
case Sbm.Database.BusMgr:
|
||||
return GetDatabaseByContext(context);
|
||||
case Sbm.Database.Template:
|
||||
return GetDatabaseByContext(Sbm.RepositoryContext_Template);
|
||||
case Sbm.Database.Demo:
|
||||
@@ -169,6 +171,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
public AjaxResponse_ValidateDatabaseSchema(SbmModel_Control model) : base(model) { }
|
||||
// Database instance.
|
||||
public String Instance { get; set; }
|
||||
public String Context { get; set; }
|
||||
// Schema validation list.
|
||||
public List<DbSchemaItemResponseData> Items { get; } = new List<DbSchemaItemResponseData>();
|
||||
}
|
||||
@@ -194,13 +197,21 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
return Json(responseData.SetMessage(messageTitle, "Database instance must be specified"));
|
||||
responseData.Instance = databaseInstance.ToString();
|
||||
|
||||
// Context.
|
||||
if (databaseInstance == Sbm.Database.BusMgr)
|
||||
{
|
||||
if (StringUtil.IsBlank(model.DatabaseFilter.Context))
|
||||
return Json(responseData.SetMessage(messageTitle, "BusMgr Database context must be specified"));
|
||||
responseData.Context = model.DatabaseFilter.Context;
|
||||
}
|
||||
|
||||
// Database connection.
|
||||
ISacsDatabase db = GetDatabase(databaseInstance);
|
||||
ISacsDatabase db = GetDatabase(databaseInstance, model.DatabaseFilter.Context);
|
||||
if (db == null)
|
||||
return Json(responseData.SetMessage(messageTitle, $"Unrecognised database instance specified: '{model.DatabaseFilter.Instance}'."));
|
||||
|
||||
// Retrieve XML database schema definition.
|
||||
Dictionary<String, String> xmlSchemas = GetSmlSchema(databaseInstance);
|
||||
Dictionary<String, String> xmlSchemas = GetSmlSchemas(databaseInstance);
|
||||
if (!xmlSchemas.Any())
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to extract XML schema definitions."));
|
||||
|
||||
@@ -253,7 +264,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
private Dictionary<String, String> GetSmlSchema(Sbm.Database databaseInstance)
|
||||
private Dictionary<String, String> GetSmlSchemas(Sbm.Database databaseInstance)
|
||||
{
|
||||
Dictionary<String, String> schemas = new Dictionary<String, String>();
|
||||
switch (databaseInstance)
|
||||
@@ -264,6 +275,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
schemas.Add("SbmDbDfn_Control.xml", SacsResourceHelper.GetManifestResourceAsText(assembly, "", "SbmDbDfn_Control.xml"));
|
||||
break;
|
||||
}
|
||||
case Sbm.Database.BusMgr:
|
||||
case Sbm.Database.Template:
|
||||
case Sbm.Database.Demo:
|
||||
{
|
||||
@@ -436,8 +448,15 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
if (databaseInstance <= 0)
|
||||
return Json(responseData.SetMessage(messageTitle, "Database instance must be specified"));
|
||||
|
||||
// Context.
|
||||
if (databaseInstance == Sbm.Database.BusMgr)
|
||||
{
|
||||
if (StringUtil.IsBlank(model.DatabaseFilter.Context))
|
||||
return Json(responseData.SetMessage(messageTitle, "BusMgr Database context must be specified"));
|
||||
}
|
||||
|
||||
// Database connection.
|
||||
ISacsDatabase db = GetDatabase(databaseInstance);
|
||||
ISacsDatabase db = GetDatabase(databaseInstance, model.DatabaseFilter.Context);
|
||||
|
||||
// Table definition.
|
||||
DbDfnTable tableDfn = db.GetTableDfn(model.DatabaseTable.Name, true);
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Dbas.App;
|
||||
using Sarand.BusinessMgr.Web.Control.Components;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Data;
|
||||
using Sarand.Net.Standard.Dbas.Proc;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.System;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using DocumentFormat.OpenXml.EMMA;
|
||||
using System.Linq;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.Net.Standard.Dbas.Base;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using System.Reflection;
|
||||
using static Sarand.BusinessMgr.Net.Standard.Dbas.Utils.SbmDbDfnGenerator;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Dbas.Consoles;
|
||||
using Sarand.Net.Standard.Base.IO;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
{
|
||||
//======================================================================
|
||||
// System Controller - Ajax - Logs.
|
||||
//======================================================================
|
||||
partial class SystemController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Database data.
|
||||
private class LogFolderData
|
||||
{
|
||||
public String Name { get; set; }
|
||||
}
|
||||
private class LogFileData
|
||||
{
|
||||
public String Name { get; set; }
|
||||
public String UpdateFmt { get; set; }
|
||||
public long Size { get; set; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Log Folder List ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_LogFolderList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_LogFolderList(SbmModel_Control model) : base(model) { }
|
||||
// Log file list.
|
||||
public List<LogFolderData> Folders { get; } = new List<LogFolderData>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Retrieve the list of folders under the root folder.
|
||||
/// <para>- These should correspond to applications (control, busmgr, api etc).</para>
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/Logs/GetFolderList")]
|
||||
[Route("System/Ajax/Logs/GetFolders")]
|
||||
public IActionResult Ajax_GetLogFolderList(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetLogFolderList";
|
||||
String messageTitle = Localiser["system.caption.logs"];
|
||||
AjaxResponse_LogFolderList responseData = new AjaxResponse_LogFolderList(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Identify folders in root log folder.
|
||||
String rootLogFolder = model.LoggingRootFolder;
|
||||
foreach (String folder in Directory.EnumerateDirectories(rootLogFolder))
|
||||
{
|
||||
String folderName = Path.GetFileName(folder);
|
||||
if (folderName.IsMatch("^(?:Sbm|BusMgr|Web|)(?:Control|Portal|Api)$", RegexOptions.IgnoreCase))
|
||||
responseData.Folders.Add(new LogFolderData() { Name = folderName });
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Log Year Folder List ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_LogYearList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_LogYearList(SbmModel_Control model) : base(model) { }
|
||||
// Log file list.
|
||||
public List<LogFolderData> Years { get; } = new List<LogFolderData>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Retrieve the list of year folders under the selected folder.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/Logs/GetYearList")]
|
||||
[Route("System/Ajax/Logs/GetYears")]
|
||||
public IActionResult Ajax_GetLogYearList(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetLogYearList";
|
||||
String messageTitle = Localiser["system.caption.logs"];
|
||||
AjaxResponse_LogYearList responseData = new AjaxResponse_LogYearList(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Store filter properties to session.
|
||||
SessionData_Control.System.Logs.Filter.Folder = model.LogsFilter.Folder;
|
||||
SessionData_Control.System.Logs.Filter.Year = "";
|
||||
SessionData_Control.System.Logs.Filter.Month = "";
|
||||
|
||||
// Identify folders in selected log folder.
|
||||
String logFolder = Path.Combine(model.LoggingRootFolder, model.LogsFilter.Folder);
|
||||
foreach (String folder in Directory.EnumerateDirectories(logFolder))
|
||||
{
|
||||
String folderName = Path.GetFileName(folder);
|
||||
if (folderName.IsMatch("^\\d{4}$"))
|
||||
responseData.Years.Add(new LogFolderData() { Name = folderName });
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Log Month Folder List ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_LogMonthList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_LogMonthList(SbmModel_Control model) : base(model) { }
|
||||
// Log file list.
|
||||
public List<LogFolderData> Months { get; } = new List<LogFolderData>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Retrieve the list of year folders under the selected folder.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/Logs/GetMonthList")]
|
||||
[Route("System/Ajax/Logs/GetMonths")]
|
||||
public IActionResult Ajax_GetLogMonthList(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetLogMonthList";
|
||||
String messageTitle = Localiser["system.caption.logs"];
|
||||
AjaxResponse_LogMonthList responseData = new AjaxResponse_LogMonthList(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Store filter properties to session.
|
||||
SessionData_Control.System.Logs.Filter.Folder = model.LogsFilter.Folder;
|
||||
SessionData_Control.System.Logs.Filter.Year = model.LogsFilter.Year;
|
||||
SessionData_Control.System.Logs.Filter.Month = "";
|
||||
//SessionData_Control.System.Logs.Filter.Month = model.LogsFilter.Month;
|
||||
|
||||
// Identify folders in selected year folder.
|
||||
String logFolder = Path.Combine(model.LoggingRootFolder, model.LogsFilter.Folder, model.LogsFilter.Year);
|
||||
foreach (String folder in Directory.EnumerateDirectories(logFolder))
|
||||
{
|
||||
String folderName = Path.GetFileName(folder);
|
||||
if (folderName.IsMatch("^\\d{6}$"))
|
||||
responseData.Months.Add(new LogFolderData() { Name = folderName });
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Log File List ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_LogFileList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_LogFileList(SbmModel_Control model) : base(model) { }
|
||||
// Log file list.
|
||||
public List<LogFileData> Files { get; } = new List<LogFileData>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/Logs/GetFileList")]
|
||||
[Route("System/Ajax/Logs/GetFiles")]
|
||||
public IActionResult Ajax_GetLogFileList(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetLogFileList";
|
||||
String messageTitle = Localiser["system.caption.logs"];
|
||||
AjaxResponse_LogFileList responseData = new AjaxResponse_LogFileList(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Store filter properties to session.
|
||||
SessionData_Control.System.Logs.Filter.Folder = model.LogsFilter.Folder;
|
||||
SessionData_Control.System.Logs.Filter.Year = model.LogsFilter.Year;
|
||||
SessionData_Control.System.Logs.Filter.Month = model.LogsFilter.Month;
|
||||
|
||||
// Identify folders in selected year folder.
|
||||
String logFolder = Path.Combine(model.LoggingRootFolder, model.LogsFilter.Folder, model.LogsFilter.Year, model.LogsFilter.Month);
|
||||
DirectoryInfo folder = new DirectoryInfo(logFolder);
|
||||
foreach (FileInfo file in folder.EnumerateFiles())
|
||||
{
|
||||
responseData.Files.Add(new LogFileData() { Name = file.Name, UpdateFmt = file.LastWriteTime.ToString("d-MMM-yy HH:mm"), Size = file.Length });
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Log File ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_LogFile : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_LogFile(SbmModel_Control model) : base(model) { }
|
||||
// Log file.
|
||||
public class LogFileData
|
||||
{
|
||||
public String Path { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String Data { get; set; }
|
||||
public String Html { get; set; } = "";
|
||||
}
|
||||
public LogFileData File { get; } = new LogFileData();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/Logs/GetFile")]
|
||||
[Route("System/Ajax/Logs/GetLogFile")]
|
||||
public IActionResult Ajax_GetLogFile(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetLogFile";
|
||||
String messageTitle = Localiser["system.caption.logs"];
|
||||
AjaxResponse_LogFile responseData = new AjaxResponse_LogFile(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Store filter properties to session.
|
||||
SessionData_Control.System.Logs.Filter.Folder = model.LogsFilter.Folder;
|
||||
SessionData_Control.System.Logs.Filter.Year = model.LogsFilter.Year;
|
||||
SessionData_Control.System.Logs.Filter.Month = model.LogsFilter.Month;
|
||||
|
||||
// Identify folders in selected year folder.
|
||||
responseData.File.Path = Path.Combine(model.LoggingRootFolder, model.LogsFilter.Folder, model.LogsFilter.Year, model.LogsFilter.Month, model.LogsFilter.Filename);
|
||||
responseData.File.Name = Path.GetFileName(responseData.File.Path);
|
||||
try
|
||||
{
|
||||
String[] fileLines = FileUtil.ReadAllFileLines(responseData.File.Path);
|
||||
responseData.File.Data = String.Join("\n", fileLines);
|
||||
// Construct html data.
|
||||
foreach (var fileLine in fileLines)
|
||||
{
|
||||
String line = fileLine;
|
||||
List<String> classNames = new List<string>();
|
||||
if (fileLine.IsMatch("^\t{2}"))
|
||||
{
|
||||
line = Regex.Replace(fileLine, "^\t+", "");
|
||||
classNames.Add("tab2");
|
||||
}
|
||||
if (fileLine.IsMatch("^\t"))
|
||||
{
|
||||
line = Regex.Replace(fileLine, "^\t", "");
|
||||
classNames.Add("tab");
|
||||
}
|
||||
if (line.IsMatch("\\d{8}:\\d{6}\\s+(error|err)\\s+", RegexOptions.IgnoreCase))
|
||||
classNames.Add("err");
|
||||
else if (line.IsMatch("\\d{8}:\\d{6}\\s+(warn|wrn)\\s+", RegexOptions.IgnoreCase))
|
||||
classNames.Add("wrn");
|
||||
else if (line.IsMatch("\\d{8}:\\d{6}\\s+(info|inf)\\s+", RegexOptions.IgnoreCase))
|
||||
classNames.Add("inf");
|
||||
responseData.File.Html += $"<div class='{String.Join(" ", classNames)}'>" + line + "</div>";
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc, "reading log file", 0)}");
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//======================================================================
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using DocumentFormat.OpenXml.EMMA;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Web.Control.Components;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.System;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
{
|
||||
@@ -29,6 +33,34 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.System
|
||||
return RedirectToAction("", "");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// System - Logs.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public IActionResult Logs()
|
||||
{
|
||||
if (!ValidUserSession)
|
||||
AutoLoginUser();
|
||||
|
||||
// Redirect to sign-in if not signed-in.
|
||||
if (!ValidUserSession)
|
||||
{
|
||||
ClearKeepLoggedInCookie();
|
||||
return RedirectToAction("", "Security");
|
||||
}
|
||||
|
||||
// Refresh model.
|
||||
Model_System model = new Model_System(Localiser);
|
||||
RefreshModel(model);
|
||||
model.LogsFilter.Folder = StringUtil.OnBlank(SessionData_Control.System.Logs.Filter.Folder, "Control");
|
||||
model.LogsFilter.Year = StringUtil.OnBlank(SessionData_Control.System.Logs.Filter.Year, DateTime.Today.ToString("yyyy"));
|
||||
model.LogsFilter.Month = StringUtil.OnBlank(SessionData_Control.System.Logs.Filter.Month, DateTime.Today.ToString("yyyyMM"));
|
||||
|
||||
// Core Database view.
|
||||
return View("Views/System/Logs.cshtml", model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//======================================================================
|
||||
|
||||
+2
-2
@@ -5,11 +5,11 @@ using System;
|
||||
namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_CoreDatabase : SbmModel_Control
|
||||
public class Model_RepositoryDatabase : SbmModel_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_CoreDatabase(SbmLocaliser localiser) :
|
||||
public Model_RepositoryDatabase(SbmLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
}
|
||||
@@ -24,9 +24,11 @@ namespace Sarand.BusinessMgr.Web.Control.Models.System
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Database page properties.
|
||||
// ToDo: System-Database model may not be required..
|
||||
public class DatabaseFilterData
|
||||
{
|
||||
public String Instance { get; set; }
|
||||
public String Context { get; set; }
|
||||
public String Search { get; set; }
|
||||
}
|
||||
public DatabaseFilterData DatabaseFilter { get; } = new DatabaseFilterData();
|
||||
@@ -42,8 +44,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.System
|
||||
List<CodeDesc> items = new List<CodeDesc>();
|
||||
if (ValidUserSession)
|
||||
{
|
||||
items.Add("Core", Localiser["label.core"]);
|
||||
items.Add("Reference", Localiser["label.reference"]);
|
||||
items.Add("Control", Localiser["label.control"]);
|
||||
items.Add("Support", Localiser["label.support"]);
|
||||
}
|
||||
return new SelectList(items, "Code", "Desc");
|
||||
@@ -51,7 +52,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.System
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Logs page properties.
|
||||
public String LoggingRootFolder { get; } = Regex.Replace(SaLogger.LogFolder, "[\\\\/]Admin$", "");
|
||||
public String LoggingRootFolder { get; } = Regex.Replace(SaLogger.LogFolder, "[\\\\/](?:Sbm|BusMgr|Web)Control$", "");
|
||||
// Log file filter.
|
||||
public class LogsFilterData
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user