Control - Repository initialisation.
This commit is contained in:
+81
-3
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.Models;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.Instance;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
@@ -7,6 +8,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 static Sarand.BusinessMgr.Net.Standard.Base.App.Sbm.Config.Security;
|
||||
@@ -168,7 +170,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId repositoryId = model.Repository.Id.ToSysId();
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (!SysId.IsValid(repositoryId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
@@ -197,6 +199,82 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Repository ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_RepositoryInfo : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_RepositoryInfo(SbmModel_Control model) : base(model) { }
|
||||
// Repository details.
|
||||
public class RepositoryInfoData : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public byte? Initialised { get; set; }
|
||||
/// <summary>Tooltip text if database uninitialised.</summary>
|
||||
public String Uninitialised { get; set; }
|
||||
/// <summary>Tooltip text if database unavailable.</summary>
|
||||
public String Unavailable { get; set; }
|
||||
}
|
||||
public RepositoryInfoData repository { get; } = new RepositoryInfoData();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Instance/Repository/Ajax/GetItemInfo")]
|
||||
[Route("Instance/Repository/Ajax/GetRepositoryInfo")]
|
||||
[Route("Instance/Repository/Ajax/GetRepoInfo")]
|
||||
public IActionResult Ajax_GetRepositoryInfo(Model_Repository model)
|
||||
{
|
||||
String messageTitle = Localiser["label.repository"];
|
||||
AjaxResponse_RepositoryInfo responseData = new AjaxResponse_RepositoryInfo(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<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (!SysId.IsValid(repositoryId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryById(repositoryId);
|
||||
disposables.Add(repository);
|
||||
if (repository == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Failed to retrieve repository for Id: '" + repositoryId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
responseData.repository.Id = SysId.ToString(repository.Id);
|
||||
|
||||
// Repository console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
if (!instanceConsole.HasErrorState())
|
||||
{
|
||||
// Validate database.
|
||||
if (instanceConsole.IsRepositoryValid())
|
||||
{
|
||||
// Check whether repository is initialised.
|
||||
if (instanceConsole.IsRepositoryInitialised())
|
||||
{
|
||||
responseData.repository.Initialised = 1;
|
||||
}
|
||||
else responseData.repository.Uninitialised = instanceConsole.ErrorStateMessage;
|
||||
}
|
||||
else responseData.repository.Unavailable = instanceConsole.ErrorStateMessage;
|
||||
}
|
||||
else responseData.repository.Unavailable = instanceConsole.ErrorStateMessage;
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Store Repository ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
@@ -214,7 +292,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item Id.
|
||||
SysId repositoryId = model.Repository.Id.ToSysId();
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (StringUtil.ToBool(model.Repository.Exists) && !SysId.IsValid(repositoryId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository Id not supplied for existing item.");
|
||||
@@ -245,7 +323,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
}
|
||||
|
||||
// Owner.
|
||||
SysId ownerId = repository?.OwnerId ?? StringUtil.ToSysId(model.Repository.OwnerId);
|
||||
SysId ownerId = repository?.OwnerId ?? SysId.ToSysId(model.Repository.OwnerId);
|
||||
SbmcOwner owner = ControlInstanceMgr.GetOwnerById(ownerId);
|
||||
disposables.Add(owner);
|
||||
if (owner == null)
|
||||
|
||||
Reference in New Issue
Block a user