private async Task <IEnumerable <Adapters.Oal.dbo_event_pending_console> > SearchEventPendingAsync(string consoleNo) { var pendingAdapter = new Adapters.Oal.dbo_event_pending_consoleAdapter(); var query = $"SELECT [id], [event_class], [event_id] FROM [dbo].[event_pending_console] WHERE console_no = '{consoleNo}'"; var list = new List <Adapters.Oal.dbo_event_pending_console>(); using (var conn = new SqlConnection(pendingAdapter.ConnectionString)) using (var cmd = new SqlCommand(query, conn)) { await conn.OpenAsync(); using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var item = new Adapters.Oal.dbo_event_pending_console { id = reader["id"].ReadNullableString(), event_class = reader["event_class"].ReadNullableString(), event_id = reader["event_id"].ReadNullableString() }; list.Add(item); } } } return(list); }
private async Task InsertEventPendingConsoleAsync(Adapters.Oal.dbo_normal_console_event_new parent, params string[] connoteNotes) { var pendingAdapter = new Adapters.Oal.dbo_event_pending_consoleAdapter(); var rows = new List <Adapters.Oal.dbo_event_pending_console>(); foreach (var connoteNo in connoteNotes) { rows.Add(GetPendingConsoleRow(parent.id, connoteNo)); foreach (var item in rows) { // verify the id, is not duplicate var onePr = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => pendingAdapter.LoadOneAsync(item.id)); var one = onePr.Result; if (null != one) { continue; } await Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => pendingAdapter.InsertAsync(item)); } } }
public async Task RunAsync(Misses.Domain.Miss miss) { //console_details var consoleList = new List <string>(); if (IsConsole(miss.ConsignmentNo)) { consoleList.Add(miss.ConsignmentNo); } var missEventAdapter = new Adapters.Oal.dbo_missort_event_newAdapter(); var missEventMap = new Integrations.Transforms.RtsMissToOalMissortEventNew(); var parentRow = await missEventMap.TransformAsync(miss); parentRow.id = GenerateId(34); m_missEventRows.Add(parentRow); var consoleItem = await GetItemConsigmentsFromConsoleDetailsAsync(miss.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); //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); //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); } } else { AddPendingItems(parentRow.id, cc); } } } } else { AddPendingItems(parentRow.id, item); } } } } else { AddPendingItems(parentRow.id, miss.ConsignmentNo); } foreach (var item in m_missEventRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(missEventAdapter.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_missEventPendingConsoleRows) { 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"); } }
private async Task ProcessEventPendingItem(Norms.Domain.Norm norm, Adapters.Oal.dbo_event_pending_console pending) { var itemList = norm.AllConsignmentNotes.Split(new[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries); var ok = false; switch (pending.event_class) { case "pos.oal.DeliveryEventNew": await ProcessDeliveryPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.SopEventNew": await ProcessSopPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.SipEventNew": await ProcessSipPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.HipEventNew": await ProcessHipPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.HopEventNew": await ProcessHopPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.StatusEventNew": await ProcessStatPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.VasnEventNew": await ProcessVasnPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.NormalConsoleEventNew": //ProcessNormPendingItem(item.console_no, item.event_id); break; case "pos.oal.MissortEventNew": await ProcessMissPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.WwpEventNewLog": await ProcessWwpPendingItem(pending.event_id, itemList); ok = true; break; case "pos.oal.IpsImport": await ProcessIpsPendingItem(pending.event_id, itemList); ok = true; break; } if (ok) { var pendingAdapter = new Adapters.Oal.dbo_event_pending_consoleAdapter(); await pendingAdapter.DeleteAsync(pending.id); } }
public async Task RunAsync(Sops.Domain.Sop sop) { //console_details var consoleList = new List <string> { sop.ConsignmentNo }; var sopWwpEventAdapter = new Adapters.Oal.dbo_wwp_event_new_logAdapter(); var sopEventAdapter = new Adapters.Oal.dbo_sop_event_newAdapter(); var sopEventMap = new Integrations.Transforms.RtsSopToOalSopEventNew(); var parentRow = await sopEventMap.TransformAsync(sop); parentRow.id = GenerateId(34); m_sopEventRows.Add(parentRow); var sopWwpEventLogMap = new Integrations.Transforms.RtsSopToOalSopWwpEventNewLog(); var parentWwpRow = await sopWwpEventLogMap.TransformAsync(sop); m_sopWwpEventLogRows.Add(parentWwpRow); 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(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, sop.ConsignmentNo); } //persist any rows foreach (var item in m_sopEventRows) { //if (item.consignment_no == "EH465625253MY") throw new ArgumentNullException("scenario failed testing"); System.Diagnostics.Debug.WriteLine("sop_event_new: {0}|{1}", item.consignment_no, item.id); var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(sopEventAdapter.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_sopWwpEventLogRows) { var pr = Policy.Handle <SqlException>() .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x))) .ExecuteAndCaptureAsync(() => TrackEvents(sopWwpEventAdapter.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_sopEventPendingConsoleRows) { 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"); } }