-
-
Save ste-bel/c3d8a380c88d5ff71fbc6102d4d9539a to your computer and use it in GitHub Desktop.
The slot loader and search entry point
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; | |
using System.Collections.Generic; | |
namespace PB.Objects.B2B.Slot { | |
public class ConversionDetails : IPrefetchable { | |
private static readonly string SLOT_NAME = typeof(ConversionDetails).Name; | |
private static readonly Type SLOT_TYPE = typeof(B2ConversionDetail); | |
private static readonly string ALIAS = SLOT_TYPE.Name; | |
private IEnumerable<PXDataRecord> GetData() { | |
var data = PXDatabase.SelectMulti<B2ConversionDetail>( | |
new PXDataField<B2ConversionDetail.conversionID>(ALIAS), // Always put key here | |
new PXDataField<B2ConversionDetail.organizationID>(ALIAS), | |
new PXDataField<B2ConversionDetail.bAccountID>(ALIAS), | |
new PXDataField<B2ConversionDetail.messageType>(ALIAS), | |
new PXDataField<B2ConversionDetail.convertFrom>(ALIAS), | |
new PXDataField<B2ConversionDetail.convertTo>(ALIAS) | |
); | |
return data; | |
} | |
private readonly IDictionary<string, ConversionDetailHelper> content = new Dictionary<string, ConversionDetailHelper>(); | |
public void Prefetch() { | |
content.Clear(); | |
var data = GetData(); // Watch out, cannot be enumerated multiple times | |
foreach (var record in data) { | |
var index = 0; | |
var conversionID = record.GetString(index++); | |
if (!content.TryGetValue(conversionID, out var helper)) { | |
helper = new ConversionDetailHelper(conversionID); | |
content.Add(conversionID, helper); | |
} | |
var organizationID = record.GetString(index++); | |
var bAccountID = record.GetInt32(index++); | |
var messageType = record.GetString(index++); | |
var convertFrom = record.GetString(index++); | |
var convertTo = record.GetString(index++); | |
helper.Add(organizationID, bAccountID, messageType, convertFrom, convertTo); | |
} | |
} | |
public static bool TryGetHelper(string conversionID, out ConversionDetailHelper value) { | |
var slot = PXDatabase.GetSlot<ConversionDetails>(SLOT_NAME, SLOT_TYPE); | |
var found = slot.content.TryGetValue(conversionID, out var helper); | |
value = helper; | |
return found; | |
} | |
public static ConversionDetailHelper GetHelper(string conversionID) { | |
var found = TryGetHelper(conversionID, out var helper); | |
if (found) { | |
return helper; | |
} | |
throw new PXException(PXLocalizer.LocalizeFormat(Messages.ConversionDetailCannotFind, conversionID)); | |
} | |
public static void Reset() { | |
PXDatabase.ResetSlot<ConversionDetails>(SLOT_NAME, SLOT_TYPE); | |
} | |
public static bool Exists(string conversionID) { | |
var found = TryGetHelper(conversionID, out var helper); | |
return found; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment