3.0.0.4 Portal Commodity Sales properties. Control Index population.
This commit is contained in:
+91
-6
@@ -2,6 +2,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Dbas.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.Components;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.Instance;
|
||||
@@ -10,6 +11,7 @@ using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -61,17 +63,17 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
|
||||
// Validate Repository.
|
||||
SessionData_Control.Profile.Filter.InstanceContext = model.Filter.Context;
|
||||
if (StringUtil.IsBlank(model.Filter.Context))
|
||||
SessionData_Control.Profile.Filter.InstanceContext = model.DatabaseFilter.Context;
|
||||
if (StringUtil.IsBlank(model.DatabaseFilter.Context))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Instance Context not supplied.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryByContext(model.Filter.Context);
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryByContext(model.DatabaseFilter.Context);
|
||||
disposables.Add(repository);
|
||||
if (repository == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository does not exist. Context: {model.Filter.Context}.");
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository does not exist. Context: {model.DatabaseFilter.Context}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
@@ -88,8 +90,8 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
|
||||
// Table filter.
|
||||
List<String> filter = new List<string>();
|
||||
if (!StringUtil.IsBlank(model.Filter.Search))
|
||||
filter.Add($"tbl.name Like '%{DbQuery.FormatForLike(model.Filter.Search)}%'");
|
||||
if (!StringUtil.IsBlank(model.DatabaseFilter.Search))
|
||||
filter.Add($"tbl.name Like '%{DbQuery.FormatForLike(model.DatabaseFilter.Search)}%'");
|
||||
if (!filter.Any()) filter.Add("1=1");
|
||||
|
||||
// Construction query.
|
||||
@@ -133,6 +135,89 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Populate Repository Database Indices ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_RepositoryIndexPopulation : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_RepositoryIndexPopulation(SbmModel_Control model) : base(model) { }
|
||||
// Stats.
|
||||
public class StatsData
|
||||
{
|
||||
public int? PrimaryIndicesCreated { get; set; }
|
||||
public int? IndicesCreated { get; set; }
|
||||
public int? IndicesDropped { get; set; }
|
||||
}
|
||||
public StatsData Stats { get; } = new StatsData();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Instance/Repository/Ajax/PopulateIndices")]
|
||||
public IActionResult Ajax_PopulateRepositoryDatabaseIndices(Model_RepositoryDatabase model)
|
||||
{
|
||||
String messageTitle = Localiser["label.database"];
|
||||
AjaxResponse_RepositoryIndexPopulation responseData = new AjaxResponse_RepositoryIndexPopulation(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
|
||||
// Validate Repository.
|
||||
SessionData_Control.Profile.Filter.InstanceContext = model.DatabaseFilter.Context;
|
||||
if (StringUtil.IsBlank(model.DatabaseFilter.Context))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Instance Context not supplied.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryByContext(model.DatabaseFilter.Context);
|
||||
disposables.Add(repository);
|
||||
if (repository == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository does not exist. Context: {model.DatabaseFilter.Context}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Repository Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
|
||||
disposables.Add(instanceConsole);
|
||||
|
||||
SbmDatabaseConsole dbConsole = new SbmDatabaseConsole(instanceConsole.Internals.SessionContext);
|
||||
|
||||
// Populate indices.
|
||||
SaLogger.Info($"{SysUtil.Fn} Populating indices for Repository Context '{model.DatabaseFilter.Context}'.", true);
|
||||
SacsDatabaseConsole.IndexStats indexStats = new SacsDatabaseConsole.IndexStats();
|
||||
dbConsole.InstallDbIndices(indexStats);
|
||||
if (dbConsole.HasErrorState())
|
||||
return Json(responseData.SetMessage(messageTitle, $"Error encountered: {dbConsole.ErrorStateMessage.Trim('.')}."));
|
||||
|
||||
// Statistics.
|
||||
if (indexStats.PrimaryIndicesCreated > 0)
|
||||
responseData.Stats.PrimaryIndicesCreated = indexStats.PrimaryIndicesCreated;
|
||||
if (indexStats.IndicesCreated > 0)
|
||||
responseData.Stats.IndicesCreated = indexStats.IndicesCreated;
|
||||
if (indexStats.IndicesDropped > 0)
|
||||
responseData.Stats.IndicesDropped = indexStats.IndicesDropped;
|
||||
List<String> statsOutput = new List<string>();
|
||||
if (indexStats.PrimaryIndicesCreated > 0)
|
||||
statsOutput.Add($"Primary Created: {indexStats.PrimaryIndicesCreated}.");
|
||||
if (indexStats.IndicesCreated > 0)
|
||||
statsOutput.Add($"Indices Created: {indexStats.IndicesCreated}.");
|
||||
if (indexStats.IndicesDropped > 0)
|
||||
statsOutput.Add($"Indices dropped: {indexStats.IndicesDropped}.");
|
||||
responseData.SetMessage(messageTitle, $"Indices populated.\n{statsOutput.Concat("", "\n")}");
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
Reference in New Issue
Block a user