private async Task ProcessVasnPendingItem(string vasnEventId, string[] itemList) { var vasnAdapter = new Adapters.Oal.dbo_vasn_event_newAdapter(); var vasnPendingPolly = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(async() => await vasnAdapter.LoadOneAsync(vasnEventId)); if (null != vasnPendingPolly.FinalException) { throw new Exception("Process Vasn Pending Polly Error", vasnPendingPolly.FinalException); } var vasn = vasnPendingPolly.Result; var vasnItems = new List <Adapters.Oal.dbo_vasn_event_new>(); foreach (var item in itemList) { var console = IsConsole(item); var child = vasn.Clone(); child.id = GenerateId(34); child.consignment_no = item; child.data_flag = "1"; child.item_type_code = console ? "02" : "01"; if (child.dateCreatedOALDateField.HasValue && child.dateCreatedOALDateField.Value < new DateTime(1753, 1, 1)) { child.dateCreatedOALDateField = null; } vasnItems.Add(child); } foreach (var item in vasnItems) { var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => vasnAdapter.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(Vasns.Domain.Vasn vasn) { //console_details var consoleList = new List <string>(); if (IsConsole(vasn.ConsignmentNo)) { consoleList.Add(vasn.ConsignmentNo); } var vasnEventAdapter = new Adapters.Oal.dbo_vasn_event_newAdapter(); var vasnWwpEventAdapter = new Adapters.Oal.dbo_wwp_event_new_logAdapter(); var vasnEventMap = new Integrations.Transforms.RtsVasnToOalVasnEventNew(); var parentRow = await vasnEventMap.TransformAsync(vasn); parentRow.id = GenerateId(34); m_vasnEventRows.Add(parentRow); var vasnWwpEventLogMap = new Integrations.Transforms.RtsVasnOalWwpEventNewLog(); var parentWwpRow = await vasnWwpEventLogMap.TransformAsync(vasn); m_vasnWwpEventLogRows.Add(parentWwpRow); var consoleItem = await GetItemConsigmentsFromConsoleDetailsAsync(vasn.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) { continue; } 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) { continue; } 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, vasn.ConsignmentNo); } foreach (var item in m_vasnEventRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(vasnEventAdapter.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_vasnWwpEventLogRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(vasnWwpEventAdapter.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_vasnEventPendingConsoleRows) { 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"); } }