219 lines
12 KiB
C#
219 lines
12 KiB
C#
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.ItemOptions;
|
|
using Sarand.Net.Standard.Base.UpdateLog;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.Net.Standard.Base.Interfaces
|
|
{
|
|
//=======================================================================
|
|
public abstract class SaInterfaceConsole : SaErrorStateItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Interface definition.
|
|
public class SaInterfaceDfn
|
|
{
|
|
public SaInterfaceDfn (String context, SaInterfaceCategory category, TypeCodeDesc typeDfn, bool duplicatesAllowed)
|
|
{
|
|
Context = context;
|
|
Category = category;
|
|
TypeDfn = typeDfn;
|
|
DuplicatesAllowed = duplicatesAllowed;
|
|
}
|
|
public String Context { get; } = "";
|
|
public SaInterfaceCategory Category { get; } = SaInterfaceCategory.Unknown;
|
|
public short InterfaceType { get { return (short)TypeDfn.Type; } }
|
|
public TypeCodeDesc TypeDfn { get; } = null;
|
|
public bool DuplicatesAllowed { get; } = false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly List<SaInterfaceDfn> interfaceDfns = new List<SaInterfaceDfn>();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Static initialisation.
|
|
static SaInterfaceConsole ()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SaInterfaceConsole ()
|
|
{
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public abstract short InterfaceDataType { get; }
|
|
public abstract SaItemOptionConsole ItemOptionConsole { get; }
|
|
public abstract SaUpdateLogConsole UpdateLogConsole { get; }
|
|
// Database.
|
|
public abstract bool DatabaseIsValid { get; }
|
|
public abstract bool CanUpdateDatabase { get; }
|
|
|
|
//---------------------------------------------------------------
|
|
// Manage interfaces - displays dialog.
|
|
public abstract bool ManageInterfaces (String interfaceContext, bool userCanManageInterfaces, bool userCanProcessInterfaces, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//---------------------------------------------------------------
|
|
// Utilities.
|
|
public abstract String GetItemTypeDesc (short itemType);
|
|
public abstract String GetItemCaption (ItemId itemId);
|
|
|
|
//---------------------------------------------------------------
|
|
// Interface item option definitions.
|
|
public abstract List<SaItemOptionDfn> GetInterfaceItemOptionDfns (SaInterfaceCategory interfaceCategory, short interfaceType);
|
|
public abstract List<SaItemOptionDfn> GetInterfaceItemOptionDfns (SysId interfaceId);
|
|
|
|
//-------------------------------------------------------------------
|
|
// I n t e r f a c e R e g i s t r a t i o n
|
|
//-------------------------------------------------------------------
|
|
public bool HasRegisteredInterfaces ()
|
|
{
|
|
return (interfaceDfns.Count > 0);
|
|
}
|
|
protected void RegisterInterfaces (String context, SaInterfaceCategory category, List<TypeCodeDesc> types, bool allowDuplicates)
|
|
{
|
|
foreach (TypeCodeDesc typeDfn in types)
|
|
{
|
|
// Remove any matches from the list.
|
|
interfaceDfns.RemoveAll(item => item.Context.EqualsCI(context) && item.Category == category && item.InterfaceType == typeDfn.Type);
|
|
// Add interface definition to list.
|
|
SaInterfaceDfn interfaceDfn = new SaInterfaceDfn(context, category, typeDfn, allowDuplicates);
|
|
interfaceDfns.Add(interfaceDfn);
|
|
}
|
|
}
|
|
public void ClearRegisteredInterfaces ()
|
|
{
|
|
interfaceDfns.Clear();
|
|
}
|
|
public List<SaInterfaceDfn> GetInterfaceDfns (String context, bool createOnly)
|
|
{
|
|
List<SaInterfaceDfn> interfaceDfns = new List<SaInterfaceDfn>();
|
|
foreach (SaInterfaceDfn dfn in this.interfaceDfns.FindAll(item => item.Context.EqualsCI(context)))
|
|
{
|
|
if (!createOnly || CanCreateInterface(dfn.Context, dfn.Category, dfn.InterfaceType))
|
|
interfaceDfns.Add(dfn);
|
|
}
|
|
return interfaceDfns;
|
|
}
|
|
public bool HasInterfaceDfns (String context, SaInterfaceCategory interfaceCategory, short interfaceType, bool createOnly)
|
|
{
|
|
List<SaInterfaceDfn> interfaceDfns = new List<SaInterfaceDfn>();
|
|
foreach (SaInterfaceDfn dfn in this.interfaceDfns.FindAll(item => item.Context.EqualsCI(context) && ((int)interfaceCategory < 1 || item.Category == interfaceCategory) && ((int)interfaceType < 1 || item.InterfaceType == interfaceType)))
|
|
{
|
|
if (!createOnly || CanCreateInterface(dfn.Context, dfn.Category, dfn.InterfaceType))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public List<SaInterfaceDfn> GetInterfaceDfns (String context, SaInterfaceCategory interfaceCategory, short interfaceType, bool createOnly)
|
|
{
|
|
List<SaInterfaceDfn> interfaceDfns = new List<SaInterfaceDfn>();
|
|
foreach (SaInterfaceDfn dfn in this.interfaceDfns.FindAll(item => item.Context.EqualsCI(context) && ((int)interfaceCategory < 1 || item.Category == interfaceCategory) && ((int)interfaceType < 1 || item.InterfaceType == interfaceType)))
|
|
{
|
|
if (!createOnly || CanCreateInterface(dfn.Context, dfn.Category, dfn.InterfaceType))
|
|
interfaceDfns.Add(dfn);
|
|
}
|
|
return interfaceDfns;
|
|
}
|
|
public virtual String GetInterfaceTypeDesc (String context, SaInterfaceCategory category, short type)
|
|
{
|
|
SaInterfaceDfn dfn = interfaceDfns.Find(item => item.Context.EqualsCI(context) && item.Category == category && item.InterfaceType == type);
|
|
if (dfn != null)
|
|
return dfn.TypeDfn.Desc;
|
|
return "";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I n t e r f a c e A c c e s s C o n t r o l
|
|
//-------------------------------------------------------------------
|
|
public abstract bool CanCreateInterfaces ();
|
|
public abstract bool CanCreateInterfaces (String context, SaInterfaceCategory interfaceCategory);
|
|
public abstract bool CanCreateInterface (String context, SaInterfaceCategory interfaceCategory, short interfaceType);
|
|
public abstract bool AreMultipleInterfaceInstancesAllowed (String context, SaInterfaceCategory interfaceCategory, short interfaceType);
|
|
public abstract bool AreMultipleActiveInterfacesAllowed (String context, SaInterfaceCategory interfaceCategory);
|
|
public abstract bool CanUpdateInterface (SaInterface interfaceObj);
|
|
public abstract bool CanCopyInterfaces ();
|
|
public abstract bool CanCopyInterfaces (String context, SaInterfaceCategory interfaceCategory);
|
|
public abstract bool CanCopyInterface (String context, SaInterfaceCategory interfaceCategory, short interfaceType);
|
|
public abstract bool CanCopyInterface (SaInterface interfaceObj);
|
|
public abstract bool IsCompatibleForInterfaceCopy (String context, SaInterfaceCategory interfaceCategory, int typeFrom, int typeTo);
|
|
public abstract bool CanRemoveInterface (SaInterface interfaceObj);
|
|
// Interface management.
|
|
public abstract SysId CreateInterface (String context, SaInterfaceCategory interfaceCategory, short interfaceType, String code, String caption, DbUpdateInfo dbUpdateInfo);
|
|
// Associated events.
|
|
public abstract void OnInterfaceCreated (SysId interfaceId);
|
|
public abstract void OnInterfaceUpdated (SysId interfaceId);
|
|
public abstract void OnInterfaceRemoved (SysId interfaceId);
|
|
// Clear configuration options, data items, processes etc.
|
|
public abstract bool ClearDependentData (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo);
|
|
//---------------------------------------------------------------
|
|
// Process interface.
|
|
public abstract bool CanProcessInterface (SaInterface interfaceObj);
|
|
public abstract bool ProcessInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo);
|
|
//---------------------------------------------------------------
|
|
// Retrieve interfaces.
|
|
public abstract SaInterface GetInterfaceById (SysId interfaceId);
|
|
public abstract SaInterface GetInterface (SaInterface.Params prmInterface);
|
|
public abstract List<SaInterface> GetInterfaceList (SaInterface.Params prmInterface);
|
|
//---------------------------------------------------------------
|
|
// Conversion between Interface Category & Code and the equivalent database Id.
|
|
public abstract SysId GetInterfaceIdForContextCategoryType (String context, SaInterfaceCategory interfaceCategory, short interfaceType);
|
|
public abstract SysId GetInterfaceIdForContextCategoryCode (String context, SaInterfaceCategory interfaceCategory, String code);
|
|
public abstract SaInterfaceCategory GetCategoryForInterfaceId (SysId interfaceId);
|
|
public abstract String GetCodeForInterfaceId (SysId interfaceId);
|
|
|
|
//---------------------------------------------------------------
|
|
// I n t e r f a c e P r o c e s s e s
|
|
//---------------------------------------------------------------
|
|
// Identify the highest sequence currently in use for an interface.
|
|
public abstract int GetMaxProcessSequence (SysId interfaceId, SaInterfaceProcessDirection processDirection, bool completedOnly = true);
|
|
// Create new process and imediately store details on database (status set to 'In Progress').
|
|
public abstract SaInterfaceProcess StartInterfaceProcess (SysId interfaceId, SaInterfaceProcessDirection eDirection, String batchRef, DateTime batchAt, int sequence, DbUpdateInfo dbUpdateInfo);
|
|
// Retrieve a process using its identity (restricted by interface).
|
|
public abstract SaInterfaceProcess GetInterfaceProcess (SysId interfaceId, SysId interfaceProcessId);
|
|
// Update the details for a process.
|
|
public abstract bool StoreInterfaceProcess (SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//---------------------------------------------------------------
|
|
// I n t e r f a c e P r o c e s s M e s s a g e s
|
|
//---------------------------------------------------------------
|
|
public abstract bool LogInterfaceProcessMessage (SysId interfaceProcessId, DbUpdateInfo dbUpdateInfo, String message, SaMessageLevel messageLevel = SaMessageLevel.Info, String Filename = "", int LineNumber = 0, ItemId ItemId = null);
|
|
|
|
//---------------------------------------------------------------
|
|
// I n t e r f a c e D a t a I t e m s
|
|
//---------------------------------------------------------------
|
|
public abstract bool ItemHasDataItems (ItemId itemId);
|
|
public abstract bool InterfaceDataItemExistsByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference);
|
|
public abstract SaInterfaceDataItem CreateInterfaceDataItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference);
|
|
public abstract SaInterfaceDataItem GetInterfaceDataItem (SysId interfaceDataItemId);
|
|
/// <summary><para>Fails if more than 1 matching data item.</para></summary>
|
|
public abstract SaInterfaceDataItem GetInterfaceDataItemByItemRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference);
|
|
/// <summary><para>Fails if more than 1 matching data item.</para></summary>
|
|
public abstract SaInterfaceDataItem GetInterfaceDataItemByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference);
|
|
/// <summary><para>Fails if more than 1 matching data item.</para></summary>
|
|
public abstract SaInterfaceDataItem GetInterfaceDataItemByItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId);
|
|
public abstract List<SaInterfaceDataItem> GetInterfaceDataItemsByItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId);
|
|
public abstract List<SaInterfaceDataItem> GetInterfaceDataItemsByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference);
|
|
public abstract bool StoreInterfaceDataItem (SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool StoreInterfaceDataItems (List<SaInterfaceDataItem> interfaceDataItems, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool ClearInterfaceDataItem (SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool ClearInterfaceDataItems (ItemId itemId, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|