Files
BusinessMgr-2019/SaBusMgrStandardDbas/Dbas/Consoles/SbmInterfaceConsole_Dbas.cs
T

205 lines
7.1 KiB
C#

using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
using Sarand.BusinessMgr.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Interfaces;
using Sarand.Net.Standard.Base.ItemOptions;
using Sarand.Net.Standard.Base.UpdateLog;
using Sarand.Net.Standard.Base.Utils;
using Sarand.Net.Standard.Dbas.Base;
using Sarand.Net.Standard.Dbas.Interfaces;
using System;
using System.Collections.Generic;
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
{
//=======================================================================
public abstract class SbmInterfaceConsole_Dbas : SaInterfaceConsole_Dbas
{
//-------------------------------------------------------------------
// Data members.
private SbmConfigConsole configConsole;
private SaItemOptionConsole itemOptionConsole;
private SaUpdateLogConsole updateLogConsole;
private readonly List<TypeCodeDesc> dataItemTypes;
private readonly List<TypeCodeDesc> interfaceDataTypes;
//-------------------------------------------------------------------
// Construction.
protected SbmInterfaceConsole_Dbas(ISbmUserContext_Core userContext) : base(SbmGlobals.Application.GetBusMgrDatabase(userContext.SessionContext))
{
UserContext = userContext;
dataItemTypes = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.ItemType);
interfaceDataTypes = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.InterfaceDataType);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (configConsole != null) configConsole.Dispose(); configConsole = null;
if (itemOptionConsole != null) itemOptionConsole.Dispose(); itemOptionConsole = null;
if (updateLogConsole != null) updateLogConsole.Dispose(); updateLogConsole = null;
}
base.Dispose(disposing);
}
//-------------------------------------------------------------------
// Properties.
public ISbmUserContext_Core UserContext { get; }
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
public override short InterfaceDataType { get { return (short)Sbm.ItemType.Interface; } }
// Consoles.
private SbmConfigConsole ConfigConsole
{
get
{
if (configConsole == null)
configConsole = SbmGlobals.Application.CreateConfigConsole(UserContext.SessionContext);
return configConsole;
}
}
public override SaItemOptionConsole ItemOptionConsole
{
get
{
if (itemOptionConsole == null)
itemOptionConsole = SbmGlobals.Application.CreateItemOptionConsole(UserContext);
return itemOptionConsole;
}
}
public override SaUpdateLogConsole UpdateLogConsole
{
get
{
if (updateLogConsole == null)
updateLogConsole = SbmGlobals.Application.CreateUpdateLogConsole(UserContext);
return updateLogConsole;
}
}
//---------------------------------------------------------------
// Utilities.
public override String GetItemTypeDesc(short itemType)
{
return dataItemTypes.GetDescForType(itemType);
}
public override String GetItemCaption(ItemId itemId)
{
return GetItemTypeDesc(itemId.Type) + " #" + SysId.ToString(itemId.Id);
}
//-------------------------------------------------------------------
// R e g i s t e r I n t e r f a c e s
//-------------------------------------------------------------------
private List<TypeCodeDesc> GetInterfaceTypesForCategory(SaInterfaceCategory interfaceCategory)
{
if (interfaceCategory == SaInterfaceCategory.Website)
return SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.InterfaceType_Website);
if (interfaceCategory == SaInterfaceCategory.Accounts)
return SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.InterfaceType_Accounts);
if (interfaceCategory == SaInterfaceCategory.System)
return SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.InterfaceType_System);
if (interfaceCategory == SaInterfaceCategory.File)
return SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.InterfaceType_File);
return new List<TypeCodeDesc>();
}
public void RegisterInterfaces(String context)
{
foreach (SaInterfaceCategory interfaceCategory in EnumUtil.GetValues<SaInterfaceCategory>())
{
List<TypeCodeDesc> interfaceTypesForCategory = new List<TypeCodeDesc>();
foreach (TypeCodeDesc interfaceType in GetInterfaceTypesForCategory(interfaceCategory))
{
if (InterfaceTypeValidForContextCategory(interfaceCategory, (short)interfaceType.Type))
interfaceTypesForCategory.Add(interfaceType);
}
if (interfaceTypesForCategory.Count > 0)
RegisterInterfaces(context, interfaceCategory, interfaceTypesForCategory, InterfaceAllowsDuplicates(interfaceCategory));
}
}
public bool InterfaceAllowsDuplicates(SaInterfaceCategory interfaceCategory)
{
switch (interfaceCategory)
{
case SaInterfaceCategory.File:
return true;
}
return false;
}
public bool InterfaceTypeValidForContextCategory(SaInterfaceCategory interfaceCategory, short interfaceType)
{
return ConfigConsole.AllowInterface(UserContext, interfaceCategory, interfaceType);
}
//-------------------------------------------------------------------
// I n t e r f a c e A c c e s s C o n t r o l
//-------------------------------------------------------------------
public override bool CanCreateInterfaces()
{
return true;
}
public override bool CanCreateInterfaces(String context, SaInterfaceCategory interfaceCategory)
{
switch (interfaceCategory)
{
case SaInterfaceCategory.System:
return true;
}
return false;
}
public override bool CanCreateInterface(String context, SaInterfaceCategory interfaceCategory, short interfaceType)
{
switch (interfaceCategory)
{
case SaInterfaceCategory.System:
return true;
}
return false;
}
public override bool CanUpdateInterface(SaInterface interfaceObj)
{
return true;
}
public override bool CanCopyInterfaces()
{
return false;
}
public override bool CanCopyInterfaces(String context, SaInterfaceCategory interfaceCategory)
{
return false;
}
public override bool CanCopyInterface(String context, SaInterfaceCategory interfaceCategory, short interfaceType)
{
return false;
}
public override bool CanCopyInterface(SaInterface interfaceObj)
{
return false;
}
public override bool IsCompatibleForInterfaceCopy(String context, SaInterfaceCategory interfaceCategory, int typeFrom, int typeTo)
{
return false;
}
public override bool CanRemoveInterface(SaInterface interfaceObj)
{
return false;
}
//---------------------------------------------------------------
// I n t e r f a c e E v e n t s
//---------------------------------------------------------------
public override void OnInterfaceCreated(SysId interfaceId)
{
}
public override void OnInterfaceUpdated(SysId interfaceId)
{
}
public override void OnInterfaceRemoved(SysId interfaceId)
{
}
//-------------------------------------------------------------------
}
//=======================================================================
}