-
-
Save ste-bel/26088249b9b584fce94af07631c7393c to your computer and use it in GitHub Desktop.
A Helper/Bucket to store and search the data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using PX.Data; | |
using System.Collections.Generic; | |
namespace PB.Objects.B2B.Slot { | |
public class ConversionDetailHelper { | |
public string ConversionID { get; private set; } | |
private IDictionary<ConversionKey, string> ConversionMap { get; } = new Dictionary<ConversionKey, string>(); | |
public ConversionDetailHelper(string conversionID) { | |
this.ConversionID = conversionID; | |
} | |
public void Add(string organizationID, int? bAccountID, string messageType, string convertFrom, string convertTo) { | |
var key = new ConversionKey(organizationID, bAccountID, messageType, convertFrom); | |
if (!ConversionMap.ContainsKey(key)) { | |
ConversionMap.Add(key, convertTo); | |
} | |
} | |
public bool TryGetValue(string scheme, string organizationID, int? bAccountID, int? parentAccountID, string messageType, string convertFrom, out string convertTo) { | |
scheme ??= B2ConversionScheme.Default; | |
var keys = new List<ConversionKey>(); | |
switch (scheme) { | |
case B2ConversionScheme.BAccount: | |
keys.Add(new ConversionKey(null, bAccountID, null, convertFrom)); | |
keys.Add(new ConversionKey(null, parentAccountID, null, convertFrom)); | |
break; | |
case B2ConversionScheme.Organization: | |
keys.Add(new ConversionKey(organizationID, null, null, convertFrom)); | |
break; | |
case B2ConversionScheme.MessageType: | |
keys.Add(new ConversionKey(null, bAccountID, messageType, convertFrom)); | |
keys.Add(new ConversionKey(null, parentAccountID, messageType, convertFrom)); | |
keys.Add(new ConversionKey(null, null, messageType, convertFrom)); | |
break; | |
case B2ConversionScheme.Default: | |
keys.Add(new ConversionKey(organizationID, bAccountID, messageType, convertFrom)); | |
keys.Add(new ConversionKey(organizationID, parentAccountID, messageType, convertFrom)); | |
keys.Add(new ConversionKey(organizationID, bAccountID, null, convertFrom)); | |
keys.Add(new ConversionKey(organizationID, parentAccountID, null, convertFrom)); | |
keys.Add(new ConversionKey(organizationID, null, messageType, convertFrom)); | |
keys.Add(new ConversionKey(organizationID, null, null, convertFrom)); | |
keys.Add(new ConversionKey(null, null, null, convertFrom)); | |
break; | |
} | |
foreach (var key in keys) { | |
PXTrace.WriteVerbose($"Try to convert {ConversionID} '{convertFrom}' with scheme '{key.OrganizationID}'/{key.BAccountID}/'{key.MessageType}'"); ; | |
if (ConversionMap.TryGetValue(key, out convertTo)) { | |
PXTrace.WriteVerbose($"Found {ConversionID} '{convertTo}'"); | |
return true; | |
} | |
} | |
PXTrace.WriteVerbose($"No conversion found for {ConversionID} '{convertFrom}'"); | |
convertTo = null; | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment