private async Task ProcessSopPendingItem(string sopEventId, string[] itemList) { var sopAdapter = new Entt_SopAdapter(); var sopPendingPolly = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(async() => await sopAdapter.LoadOneAsync(sopEventId)); if (null != sopPendingPolly.FinalException) { throw new Exception("Process Sop Pending Polly Error", sopPendingPolly.FinalException); } var sop = sopPendingPolly.Result; var sops = new List <Entt_Sop>(); foreach (var item in itemList) { var console = IsConsole(item); var child = sop.Clone(); child.Id = GenerateId(34); child.ConsignmentNo = item; child.DataFlag = "1"; child.ItemTypeCode = console ? "02" : "01"; sops.Add(child); } foreach (var item in sops) { var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout()) .WaitAndRetryAsync(RetryCount, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => sopAdapter.InsertAsync(item)); var result = await pr; if (result.FinalException != null) { throw result.FinalException; // send to dead letter queue } System.Diagnostics.Debug.Assert(result.Result > 0, "Should be at least 1 row"); } }
public async Task RunAsync(RecordSop sop) { //console_details var consoleList = new List <string>(); if (IsConsole(sop.ConsignmentNo)) { consoleList.Add(sop.ConsignmentNo); } var sopEventMap = new RecordSopToEnttSop(); var sopConsoleRow = await sopEventMap.TransformAsync(sop); sopConsoleRow.Id = GenerateId(34); m_sopEventRows.Add(sopConsoleRow); var consoleItem = await GetItemConsigmentsFromConsoleDetailsAsync(sop.ConsignmentNo); if (null != consoleItem) { var children = consoleItem.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in children) { if (consoleList.Contains(item)) { continue; } ProcessChild(sopConsoleRow, item); //2 level var console = IsConsole(item); if (console) { consoleList.Add(item); var childConsole = await GetItemConsigmentsFromConsoleDetailsAsync(item); if (null != childConsole) { var childConsoleItems = childConsole.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var cc in childConsoleItems) { if (consoleList.Contains(cc)) { continue; } ProcessChild(sopConsoleRow, cc); //3 level var anotherConsole = IsConsole(cc); if (anotherConsole) { consoleList.Add(cc); var anotherChildConsole = await GetItemConsigmentsFromConsoleDetailsAsync(cc); if (null != anotherChildConsole) { var anotherChildConsoleItems = anotherChildConsole.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var ccc in anotherChildConsoleItems) { if (consoleList.Contains(ccc)) { continue; } ProcessChild(sopConsoleRow, ccc); } } else { AddPendingItems(sopConsoleRow.Id, cc); } } } } else { AddPendingItems(sopConsoleRow.Id, item); } } } } else { AddPendingItems(sopConsoleRow.Id, sop.ConsignmentNo); } var sipEventAdapter = new Entt_SopAdapter(); foreach (var item in m_sopEventRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => sipEventAdapter.InsertAsync(item)); var result = await pr; if (result.FinalException != null) { throw result.FinalException; // send to dead letter queue } System.Diagnostics.Debug.Assert(result.Result > 0, "Should be at least 1 row"); } var pendingAdapter = new Entt_EventPendingConsoleAdapter(); foreach (var item in m_sopEventPendingConsoleRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => pendingAdapter.InsertAsync(item)); var result = await pr; if (result.FinalException != null) { throw result.FinalException; // send to dead letter queue } System.Diagnostics.Debug.Assert(result.Result > 0, "Should be at least 1 row"); } }