Files
BusinessMgr-2019/SaBusMgrCoreWeb/Web/App/SbmInstanceConfig_Web.cs
T

154 lines
7.2 KiB
C#

using DocumentFormat.OpenXml.Drawing.Diagrams;
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
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;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Sarand.BusinessMgr.Net.Core.Web.App
{
//=======================================================================
public class SbmInstanceConfig_Web : SbmInstanceConfig
{
//-------------------------------------------------------------------
// Data members.
private readonly SysId controlOwnerId;
private readonly SysId controlRepositoryId;
//-------------------------------------------------------------------
// Construction.
public SbmInstanceConfig_Web(SysId controlOwnerId, SysId controlRepositoryId)
{
this.controlOwnerId = controlOwnerId;
this.controlRepositoryId = controlRepositoryId;
PopulateControlParams();
}
//-------------------------------------------------------------------
// 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)
{
// Affiliate types.
if (IsConfigParamOfType(ConfigParamType.AllowedAffiliateTypes, itemParam))
AffiliateTypes_Allowed.UnionWith(EnumUtil.ParseEnums<Sbm.AffiliateType>(Regex.Split(itemParam.Value, "[\\s,;\\-]+")));
else if (IsConfigParamOfType(ConfigParamType.DisallowedAffiliateTypes, itemParam))
AffiliateTypes_Disallowed.UnionWith(EnumUtil.ParseEnums<Sbm.AffiliateType>(Regex.Split(itemParam.Value, "[\\s,;\\-]+")));
// Association types.
else if (IsConfigParamOfType(ConfigParamType.AllowedAssociationTypes, itemParam))
AssociationTypes_Allowed.UnionWith(EnumUtil.ParseEnums<Sbm.AssociationType>(Regex.Split(itemParam.Value, "[\\s,;\\-]+")));
else if (IsConfigParamOfType(ConfigParamType.DisallowedAssociationTypes, itemParam))
AssociationTypes_Disallowed.UnionWith(EnumUtil.ParseEnums<Sbm.AssociationType>(Regex.Split(itemParam.Value, "[\\s,;\\-]+")));
// Transaction types.
else if (IsConfigParamOfType(ConfigParamType.AllowedTransactionTypes, itemParam))
TransactionTypes_Allowed.UnionWith(EnumUtil.ParseEnums<Sbm.TransactionType>(Regex.Split(itemParam.Value, "[\\s,;\\-]+")));
else if (IsConfigParamOfType(ConfigParamType.DisallowedTransactionTypes, itemParam))
TransactionTypes_Disallowed.UnionWith(EnumUtil.ParseEnums<Sbm.TransactionType>(Regex.Split(itemParam.Value, "[\\s,;\\-]+")));
// Application options.
else if (IsConfigParamOfType(ConfigParamType.ApplicationOption, itemParam))
{
Sbm.ConfigOption option = EnumUtil.ParseEnum(itemParam.Name, Sbm.ConfigOption.Unknown);
if (option != Sbm.ConfigOption.Unknown)
{
if (itemParam.Value.EqualsCI(ApplicationOptionValue_Allow))
ApplicationOptions_Allowed.Add(option);
else if (itemParam.Value.EqualsCI(ApplicationOptionValue_Disallow))
ApplicationOptions_Disallowed.Add(option);
else if (itemParam.Value.EqualsCI(ApplicationOptionValue_Default))
ApplicationOptions_Default.Add(option);
else
SaLogger.Warn($"{SysUtil.Fn} Unrecognised application option value: {itemParam.Value}. Option: {option}.");
}
else
SaLogger.Warn($"{SysUtil.Fn} Unrecognised application option: {itemParam.Name}.");
}
}
//-------------------------------------------------------------------
// Allowed data component types.
//-------------------------------------------------------------------
// 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)
{
if (AffiliateTypes_Disallowed.Contains(affiliateType)) return false;
if (AffiliateTypes_Allowed.Contains(affiliateType)) return true;
return false;
}
// Supported affiliate 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)
{
if (AssociationTypes_Disallowed.Contains(affiliateType)) return false;
if (AssociationTypes_Allowed.Contains(affiliateType)) return true;
return false;
}
// Supported affiliate 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)
{
if (TransactionTypes_Disallowed.Contains(affiliateType)) return false;
if (TransactionTypes_Allowed.Contains(affiliateType)) return true;
return false;
}
//-------------------------------------------------------------------
// 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>();
private readonly HashSet<Sbm.ConfigOption> ApplicationOptions_Default = 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;
if (ApplicationOptions_Default.Contains(option)) return defaultResponse;
return false;
}
//-------------------------------------------------------------------
}
//=======================================================================
}