private NumberSequenceSeedData GetNumberSequenceDataByTransactionId(SalesTransaction salesTransaction) { long transactionId = ExtractNumberSequenceValueForTransactionId(salesTransaction.Id); var numberSequenceData = new NumberSequenceSeedData { DataType = NumberSequenceSeedType.TransactionId, DataValue = IncrementByOne(transactionId) }; return(numberSequenceData); }
private IEnumerable <NumberSequenceSeedData> GetNumberSequenceFromChannelDatabase(string terminalId) { // Get the next number sequence value by invoking the number sequence data service. var numberSequenceRequest = new GetLatestNumberSequenceDataRequest(terminalId); var response = this.Context.Runtime.Execute <GetLatestNumberSequenceDataResponse>(numberSequenceRequest, this.Context); IList <NumberSequenceSeedData> numberSequenceList = new List <NumberSequenceSeedData>(); // Gets the number sequence value for shift. if (response.NumberSequenceValueForShift != null) { NumberSequenceSeedData numberSequenceSeedDataForShift = GetNumberSequenceDataByShift(response.NumberSequenceValueForShift); AddOrUpdateNumberSequence(numberSequenceList, numberSequenceSeedDataForShift); } // Gets the number sequence value for transaction identifier. if (response.NumberSequenceValueForTransaction != null) { NumberSequenceSeedData numberSequenceSeedDataForTransactionId = this.GetNumberSequenceDataByTransactionId(response.NumberSequenceValueForTransaction); if (numberSequenceSeedDataForTransactionId != null) { AddOrUpdateNumberSequence(numberSequenceList, numberSequenceSeedDataForTransactionId); } } // Gets the number sequence value for the receipt identifier. if (response.NumberSequenceValueForReceipts != null) { foreach (var transItem in response.NumberSequenceValueForReceipts) { NumberSequenceSeedData numberSequenceSeedDataForReceiptId = this.GetNumberSequenceDataByReceiptId(transItem); if (numberSequenceSeedDataForReceiptId != null) { AddOrUpdateNumberSequence(numberSequenceList, numberSequenceSeedDataForReceiptId); } } } return(numberSequenceList); }
private IEnumerable <NumberSequenceSeedData> MergeNumberSequenceSeedData( IEnumerable <NumberSequenceSeedData> seedDataFromHeadquarters, IEnumerable <NumberSequenceSeedData> seedDataFromChannel) { ThrowIf.Null(seedDataFromHeadquarters, "seedDataFromHeadquarters"); long channelId = this.Context.GetPrincipal().ChannelId; if (seedDataFromChannel == null) { NetTracer.Warning("Channel {0} returned an empty number sequence seed data collection. Default values for number sequence will be used if they cannot be retrieved from Headquarters.", channelId); seedDataFromChannel = new NumberSequenceSeedData[0]; } IDictionary <NumberSequenceSeedType, NumberSequenceSeedData> headquartersNumberSequenceByType = seedDataFromHeadquarters.ToDictionary(ns => ns.DataType); IDictionary <NumberSequenceSeedType, NumberSequenceSeedData> channelNumberSequenceByType = seedDataFromChannel.ToDictionary(ns => ns.DataType); // iterate over all posible number sequence values and get the largest number sequence value available (either from AX or channel) foreach (NumberSequenceSeedType seedType in Enum.GetValues(typeof(NumberSequenceSeedType))) { NumberSequenceSeedData numberSequence; long headquartersValue = 1; long channelValue = 1; if (headquartersNumberSequenceByType.TryGetValue(seedType, out numberSequence)) { headquartersValue = numberSequence.DataValue; } if (channelNumberSequenceByType.TryGetValue(seedType, out numberSequence)) { channelValue = numberSequence.DataValue; } yield return(new NumberSequenceSeedData() { DataType = seedType, DataValue = Math.Max(headquartersValue, channelValue) }); } }
private static void AddOrUpdateNumberSequence(IList <NumberSequenceSeedData> numberSequenceList, NumberSequenceSeedData newNumberSeqValue) { var numberSequenceReceipt = numberSequenceList.Where(ns => ns.DataType == newNumberSeqValue.DataType); var numberSequenceSeedData = numberSequenceReceipt.FirstOrDefault(); if (numberSequenceSeedData != null) { if (newNumberSeqValue.DataValue > numberSequenceSeedData.DataValue) { numberSequenceSeedData.DataValue = newNumberSeqValue.DataValue; } } else { numberSequenceList.Add(newNumberSeqValue); } }