290 lines
12 KiB
C#
290 lines
12 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
|
{
|
|
//=======================================================================
|
|
public class SbmInstanceConfig_Control : SbmInstanceConfig
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
protected const String ParamContext_OptionAllowed = "OptionAllowed";
|
|
protected const String ParamContext_AffiliateTypeAllowed = "AffiliateTypeAllowed";
|
|
protected const String ParamContext_AssociationTypeAllowed = "AssociationTypeAllowed";
|
|
protected const String ParamContext_TransactionTypeAllowed = "TransactionTypeAllowed";
|
|
protected const String ParamContext_TransactionCreation = "TransactionCreation";
|
|
protected const String ParamContext_TransactionReferencePrefix = "TransactionReferencePrefix";
|
|
protected const String ParamContext_StockControl = "StockControl";
|
|
protected const String ParamContext_InterfaceCategoryAllowed = "InterfaceCategoryAllowed";
|
|
protected const String ParamContext_InterfaceTypeAllowed = "InterfaceTYpeAllowed";
|
|
protected const String ParamContext_DefaultValue = "DefaultValue";
|
|
protected const String ParamContext_ColumnChangeLogged = "ColumnChangeLogged";
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SysId controlOwnerId;
|
|
private readonly SysId controlRepositoryId;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SbmInstanceConfig_Control(SysId controlOwnerId, SysId controlRepositoryId)
|
|
{
|
|
this.controlOwnerId = controlOwnerId;
|
|
this.controlRepositoryId = controlRepositoryId;
|
|
PopulateControlParams();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Owner/Instance configuration parameters.
|
|
public enum ConfigParamType
|
|
{
|
|
AffiliateTypeAllowed,
|
|
AssociationTypeAllowed,
|
|
TransactionTypeAllowed,
|
|
ApplicationOptionAllowed,
|
|
}
|
|
public class ConfigParamData
|
|
{
|
|
public ConfigParamType ConfigParam { get; set; }
|
|
public String Context { get; set; }
|
|
public String Name { get; set; }
|
|
public HashSet<String> Values { get; } = new HashSet<string>();
|
|
public bool Password { get; set; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Populate Repository Configuration parameters.
|
|
private void PopulateControlParams()
|
|
{
|
|
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
|
{
|
|
SbmcItemMgr controlItemMgr = SbmGlobals_Web.System.CreateControlItemMgr();
|
|
if (controlItemMgr != null)
|
|
{
|
|
disposables.Add(controlItemMgr);
|
|
PopulateControlParams(controlItemMgr, new ItemId((short)SbmcHierarchyItem.ItemType.Owner, controlOwnerId));
|
|
PopulateControlParams(controlItemMgr, new ItemId((short)SbmcHierarchyItem.ItemType.Repository, controlRepositoryId));
|
|
}
|
|
}
|
|
}
|
|
private void PopulateControlParams(SbmcItemMgr controlItemMgr, ItemId paramItemId)
|
|
{
|
|
if (!ItemId.IsValid(paramItemId)) return;
|
|
using (DisposableCollection<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
|
{
|
|
// Query item params.
|
|
SbmcItemParam.Params prmParam = new SbmcItemParam.Params();
|
|
prmParam.ItemIdsIncluded.Add(paramItemId);
|
|
prmParam.StatusCat = SbmcItemParam.StatusCat.ActiveOnly;
|
|
List<SbmcItemParam> itemParams = controlItemMgr.GetItemParamList(prmParam);
|
|
disposables.AddRange(itemParams);
|
|
foreach (SbmcItemParam itemParam in itemParams)
|
|
PopulateControlParam(itemParam);
|
|
}
|
|
}
|
|
private void PopulateControlParam(SbmcItemParam itemParam)
|
|
{
|
|
if (itemParam.Context.EqualsCI(ParamContext_OptionAllowed))
|
|
{
|
|
// Application options.
|
|
Sbm.ConfigOption option = EnumUtil.ParseEnum(itemParam.Name, Sbm.ConfigOption.Unknown);
|
|
if (option != Sbm.ConfigOption.Unknown)
|
|
{
|
|
if (StringUtil.ToBool(itemParam.Value))
|
|
ApplicationOptions_Allowed.Add(option);
|
|
else
|
|
ApplicationOptions_Disallowed.Add(option);
|
|
}
|
|
else SaLogger.Warn($"{SysUtil.Fn} Unrecognised application option: {itemParam.Name}.");
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_AffiliateTypeAllowed))
|
|
{
|
|
// Affiliate types.
|
|
Sbm.AffiliateType affiliateType = EnumUtil.ParseEnum(itemParam.Name, Sbm.AffiliateType.Unknown);
|
|
if (affiliateType != Sbm.AffiliateType.Unknown)
|
|
{
|
|
if (StringUtil.ToBool(itemParam.Value))
|
|
AffiliateTypes_Allowed.Add(affiliateType);
|
|
else
|
|
AffiliateTypes_Disallowed.Add(affiliateType);
|
|
}
|
|
else SaLogger.Warn($"{SysUtil.Fn} Unrecognised Affiliate type: {itemParam.Name}.");
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_AssociationTypeAllowed))
|
|
{
|
|
// Association types.
|
|
Sbm.AssociationType associationType = EnumUtil.ParseEnum(itemParam.Name, Sbm.AssociationType.Unknown);
|
|
if (associationType != Sbm.AssociationType.Unknown)
|
|
{
|
|
if (StringUtil.ToBool(itemParam.Value))
|
|
AssociationTypes_Allowed.Add(associationType);
|
|
else
|
|
AssociationTypes_Disallowed.Add(associationType);
|
|
}
|
|
else SaLogger.Warn($"{SysUtil.Fn} Unrecognised Association type: {itemParam.Name}.");
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_TransactionTypeAllowed))
|
|
{
|
|
// Transaction types.
|
|
Sbm.TransactionType transactionType = EnumUtil.ParseEnum(itemParam.Name, Sbm.TransactionType.Unknown);
|
|
if (transactionType != Sbm.TransactionType.Unknown)
|
|
{
|
|
if (StringUtil.ToBool(itemParam.Value))
|
|
TransactionTypes_Allowed.Add(transactionType);
|
|
else
|
|
TransactionTypes_Disallowed.Add(transactionType);
|
|
}
|
|
else SaLogger.Warn($"{SysUtil.Fn} Unrecognised Transaction type: {itemParam.Name}.");
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_TransactionCreation))
|
|
{
|
|
// Transaction Creation.
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_TransactionReferencePrefix))
|
|
{
|
|
// Transaction Reference Prefix.
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_StockControl))
|
|
{
|
|
// Stock Control.
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_InterfaceCategoryAllowed))
|
|
{
|
|
// Interface Category.
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_InterfaceTypeAllowed))
|
|
{
|
|
// Interface Type.
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_DefaultValue))
|
|
{
|
|
// Default Value.
|
|
if (itemParam.Name.EqualsCI("CommodityType"))
|
|
{
|
|
Sbm.CommodityType commodityType = EnumUtil.ParseEnum(itemParam.Value, Sbm.CommodityType.Unknown);
|
|
if (commodityType > 0)
|
|
Defaults.CommodityType = commodityType;
|
|
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised Default Commodity Type: '{itemParam.Value}'. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
|
}
|
|
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised Default Value. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
|
}
|
|
else if (itemParam.Context.EqualsCI(ParamContext_ColumnChangeLogged))
|
|
{
|
|
// Update Log.
|
|
SbmDbDfn.ColumnIdx column = EnumUtil.ParseEnum(itemParam.Name, SbmDbDfn.ColumnIdx.Unknown);
|
|
if (column != SbmDbDfn.ColumnIdx.Unknown)
|
|
{
|
|
if (StringUtil.ToBool(itemParam.Value))
|
|
ColumnChangeLogged_Allowed.Add(column);
|
|
else ColumnChangeLogged_Disallowed.Add(column);
|
|
}
|
|
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised Change Log column. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
|
}
|
|
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised option. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Configuration rules.
|
|
//-------------------------------------------------------------------
|
|
// Application options.
|
|
|
|
// Supported application options.
|
|
private readonly HashSet<Sbm.ConfigOption> ApplicationOptions_Allowed = new HashSet<Sbm.ConfigOption>();
|
|
private readonly HashSet<Sbm.ConfigOption> ApplicationOptions_Disallowed = new HashSet<Sbm.ConfigOption>();
|
|
public override bool AllowApplicationOption(Sbm.ConfigOption option, bool defaultResponse)
|
|
{
|
|
if (ApplicationOptions_Disallowed.Contains(option)) return false;
|
|
if (ApplicationOptions_Allowed.Contains(option)) return true;
|
|
return defaultResponse;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Defaults.
|
|
|
|
private ISbmInstanceConfig.DefaultsData Defaults { get; } = new ISbmInstanceConfig.DefaultsData();
|
|
|
|
public override ISbmInstanceConfig.DefaultsData GetDefaults()
|
|
{
|
|
return Defaults;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Contacts.
|
|
|
|
// Supported Affiliate types.
|
|
private readonly HashSet<Sbm.AffiliateType> AffiliateTypes_Allowed = new HashSet<Sbm.AffiliateType>();
|
|
private readonly HashSet<Sbm.AffiliateType> AffiliateTypes_Disallowed = new HashSet<Sbm.AffiliateType>();
|
|
public override bool AllowAffiliateType(Sbm.AffiliateType affiliateType, bool defaultResponse)
|
|
{
|
|
if (AffiliateTypes_Disallowed.Contains(affiliateType)) return false;
|
|
if (AffiliateTypes_Allowed.Contains(affiliateType)) return true;
|
|
return defaultResponse;
|
|
}
|
|
|
|
// Supported Association types.
|
|
private readonly HashSet<Sbm.AssociationType> AssociationTypes_Allowed = new HashSet<Sbm.AssociationType>();
|
|
private readonly HashSet<Sbm.AssociationType> AssociationTypes_Disallowed = new HashSet<Sbm.AssociationType>();
|
|
public override bool AllowAssociationType(Sbm.AssociationType affiliateType, bool defaultResponse)
|
|
{
|
|
if (AssociationTypes_Disallowed.Contains(affiliateType)) return false;
|
|
if (AssociationTypes_Allowed.Contains(affiliateType)) return true;
|
|
return defaultResponse;
|
|
}
|
|
|
|
// Supported Transaction types.
|
|
private readonly HashSet<Sbm.TransactionType> TransactionTypes_Allowed = new HashSet<Sbm.TransactionType>();
|
|
private readonly HashSet<Sbm.TransactionType> TransactionTypes_Disallowed = new HashSet<Sbm.TransactionType>();
|
|
public override bool AllowTransactionType(Sbm.TransactionType affiliateType, bool defaultResponse)
|
|
{
|
|
if (TransactionTypes_Disallowed.Contains(affiliateType)) return false;
|
|
if (TransactionTypes_Allowed.Contains(affiliateType)) return true;
|
|
return defaultResponse;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Interfaces.
|
|
|
|
private readonly HashSet<SaInterfaceCategory> InterfaceCategories_Allowed = new HashSet<SaInterfaceCategory>();
|
|
private readonly HashSet<SaInterfaceCategory> InterfaceCategories_Disallowed = new HashSet<SaInterfaceCategory>();
|
|
|
|
/// <summary>
|
|
/// Whether the Interface Category is allowed.
|
|
/// </summary>
|
|
public override bool AllowInterfaceCategory(SaInterfaceCategory interfaceCategory, bool defaultResponse)
|
|
{
|
|
if (InterfaceCategories_Disallowed.Contains(interfaceCategory)) return false;
|
|
if (InterfaceCategories_Allowed.Contains(interfaceCategory)) return true;
|
|
return defaultResponse;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Update Log.
|
|
|
|
private readonly HashSet<SbmDbDfn.ColumnIdx> ColumnChangeLogged_Allowed = new HashSet<SbmDbDfn.ColumnIdx>();
|
|
private readonly HashSet<SbmDbDfn.ColumnIdx> ColumnChangeLogged_Disallowed = new HashSet<SbmDbDfn.ColumnIdx>();
|
|
|
|
/// <summary>
|
|
/// Are changes to values in the specified database column recorded in the Change Log.
|
|
/// </summary>
|
|
public override bool IsColumnChangeLogged(SbmDbDfn.ColumnIdx column, bool defaultResponse)
|
|
{
|
|
if (ColumnChangeLogged_Disallowed.Any(item => item == column)) return false;
|
|
if (ColumnChangeLogged_Allowed.Any(item => item == column)) return true;
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|