private async Task ProcessHipPendingItem(string hipEventId, string[] itemList) { var hipAdapter = new Adapters.Oal.dbo_hip_event_newAdapter(); var hipPendingPolly = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(async() => await hipAdapter.LoadOneAsync(hipEventId)); if (null != hipPendingPolly.FinalException) { throw new Exception("Process Hip Pending Polly Error", hipPendingPolly.FinalException); } var hip = hipPendingPolly.Result; var hips = new List <Adapters.Oal.dbo_hip_event_new>(); foreach (var item in itemList) { var console = IsConsole(item); var child = hip.Clone(); child.id = GenerateId(34); child.consignment_no = item; child.data_flag = "1"; child.item_type_code = console ? "02" : "01"; hips.Add(child); } foreach (var item in hips) { var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => hipAdapter.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(Hips.Domain.Hip hip) { //console_details var consoleList = new List <string>(); if (IsConsole(hip.ConsignmentNo)) { consoleList.Add(hip.ConsignmentNo); } var hipEventAdapter = new Adapters.Oal.dbo_hip_event_newAdapter(); var hipWwpEventAdapter = new Adapters.Oal.dbo_wwp_event_new_logAdapter(); var hipEventMap = new Integrations.Transforms.RtsHipToOalHipEventNew(); var parentRow = await hipEventMap.TransformAsync(hip); parentRow.id = GenerateId(34); m_hipEventRows.Add(parentRow); var hipWwpEventLogMap = new Integrations.Transforms.RtsHipToOalWwpEventNewLog(); var parentWwpRow = await hipWwpEventLogMap.TransformAsync(hip); m_hipWwpEventLogRows.Add(parentWwpRow); var consoleItem = await GetItemConsigmentsFromConsoleDetailsAsync(hip.ConsignmentNo); if (null != consoleItem) { var children = consoleItem.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in children) { if (consoleList.Contains(item)) { continue; } ProcessChild(parentRow, item); ProcessChildWwp(parentWwpRow, 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(parentRow, cc); ProcessChildWwp(parentWwpRow, 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(parentRow, ccc); ProcessChildWwp(parentWwpRow, ccc); } } else { AddPendingItems(parentRow.id, parentWwpRow.id, cc); } } } } else { AddPendingItems(parentRow.id, parentWwpRow.id, item); } } } } else { AddPendingItems(parentRow.id, parentWwpRow.id, hip.ConsignmentNo); } foreach (var item in m_hipEventRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(hipEventAdapter.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"); } foreach (var item in m_hipWwpEventLogRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(hipWwpEventAdapter.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 Adapters.Oal.dbo_event_pending_consoleAdapter(); foreach (var item in m_hipEventPendingConsoleRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(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"); } }