Control - Repository initialisation.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.App;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmCoreInstanceConsole_Control : SbmCoreInstanceConsole_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SacsDatabase coreDatabase;
|
||||
private readonly SysId organisationId;
|
||||
private readonly SysId repositoryId;
|
||||
private SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmCoreInstanceConsole_Control(SbmcRepository repository)
|
||||
{
|
||||
organisationId = repository.OwnerId;
|
||||
repositoryId = repository.Id;
|
||||
|
||||
// Repository connection.
|
||||
SacsDatabaseConsole.OdbcConfig config = GetRepositoryOdbcConfig(repository);
|
||||
coreDatabase = SacsDatabaseConsole.OpenOdbcDatabase(config);
|
||||
if (coreDatabase.HasErrorState())
|
||||
SetErrorState(coreDatabase.ErrorStateMessage);
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public SbmApplication_Control App { get { return SbmApplication_Control.Instance; } }
|
||||
public override ISacsDatabase Database_Core { get { return coreDatabase; } }
|
||||
public override SbmInternals Internals_Core { get { if (internals == null) { internals = CreateCoreInternals(); } return internals; } }
|
||||
public override DbUpdateInfo DbUpdateInfo_Core { get { return Internals_Core.DbUpdateInfo; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
public static SacsDatabaseConsole.OdbcConfig GetRepositoryOdbcConfig(SbmcRepository repository)
|
||||
{
|
||||
SacsDatabaseConsole.OdbcConfig config = new SacsDatabaseConsole.OdbcConfig();
|
||||
config.Location = $"MsSql:{repository.ServerName}\\{repository.InstanceName}.{repository.DatabaseName}";
|
||||
config.User = repository.UserName;
|
||||
config.Password = repository.Password;
|
||||
return config;
|
||||
}
|
||||
|
||||
/// <summary>Core internals for accessing core managers etc.</summary>
|
||||
public SbmInternals CreateCoreInternals()
|
||||
{
|
||||
ushort sessionIndex = App.GetCoreSessionIndexForControlRepository(organisationId, repositoryId);
|
||||
SbmSessionContext sessionContext = new SbmSessionContext_Web(sessionIndex, Sbm.Application.WebControl);
|
||||
SbmUserContext userContext = new SbmUserContext_Web(sessionContext);
|
||||
return new SbmInternals(userContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create core security console.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override SaSecurityConsole CreateSecurityConsole()
|
||||
{
|
||||
return App.CreateSecurityConsole(internals.UserContext);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user