private async Task <bool> AddToConsoleDetailsAsync(Norms.Domain.Norm norm) { var adapter = new Adapters.Oal.dbo_console_detailsAdapter(); var idPr = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => adapter.ExecuteScalarAsync <string>($"SELECT [id] FROM dbo.console_details WHERE [console_no] = '{norm.ConsoleTag}'")); var id = idPr.Result; var consoleTagNotInConsoleDetails = string.IsNullOrWhiteSpace(id); if (consoleTagNotInConsoleDetails) { var map = new Integrations.Transforms.RtsNormToOalConsoleDetails(); var row = await map.TransformAsync(norm); var dpr = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => adapter.ExecuteScalarAsync <int>($"SELECT COUNT(*) FROM dbo.console_details WHERE console_no ='{row.console_no}'")); if (dpr.Result == 0 && !string.IsNullOrWhiteSpace(row.console_no)) { var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(() => adapter.InsertAsync(row)); 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"); } return(true); } var detailsPolly = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync(async() => await adapter.LoadOneAsync(id)); if (null != detailsPolly.FinalException) { throw new Exception("Console Details Polly Error", detailsPolly.FinalException); } var details = detailsPolly.Result; var normDateTime = norm.Date.AddHours(norm.Time.Hour).AddMinutes(norm.Time.Minute).AddSeconds(norm.Time.Second); if (details.courier_id == norm.CourierId && details.office_no == norm.LocationId && (details.date_field ?? DateTime.MinValue).AddHours(28) >= normDateTime) { var notes = details.item_consignments.Split(new[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList(); notes.AddRange(norm.AllConsignmentNotes.Split(new[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries)); details.item_consignments = string.Join("\t", notes.OrderBy(x => x).Where(x => x.Length > 3 /* remove anything less*/).Distinct()); await adapter.UpdateAsync(details); return(true); } await InsertConsoleDuplicationErrorAndEventExceptionAsync(norm); return(false); }
protected Task <string> GetItemConsigmentsFromConsoleDetailsAsync(string consignmentNo) { var consoleDetailsAdapter = new Adapters.Oal.dbo_console_detailsAdapter(); var query = $"SELECT [item_consignments] FROM [dbo].[console_details] WHERE console_no = '{consignmentNo}'"; return(consoleDetailsAdapter.ExecuteScalarAsync <string>(query)); }
public async Task RunAsync(Norms.Domain.Norm norm) { var pendingConsoles = new List <string>(); var consoleList = new List <string> { norm.ConsoleTag }; //add to console_details first var success = await AddToConsoleDetailsAsync(norm); if (!success) { return; } var rows = new ConcurrentBag <Adapters.Oal.dbo_normal_console_event_new>(); var map = new Integrations.Transforms.RtsNormToNormalConsoleEventNew(); var row = await map.TransformAsync(norm); rows.Add(row); rows.AddRange(await GetEventRowsAsync(row, pendingConsoles, consoleList, norm.AllConsignmentNotes)); // await InsertDeliveryConsoleEventNewAsync(rows); // if (pendingConsoles.Any()) { await InsertEventPendingConsoleAsync(row, pendingConsoles.ToArray()); } var consoleDetailsAdapter = new Adapters.Oal.dbo_console_detailsAdapter(); var pendingCountPr = await Policy.Handle <SqlException>(e => e.IsTimeout()) .WaitAndRetryAsync(RetryCount, WaitInterval) .ExecuteAndCaptureAsync( () => consoleDetailsAdapter.ExecuteScalarAsync <int>( $"SELECT COUNT(*) FROM dbo.event_pending_console WHERE [console_no] = '{norm.ConsoleTag}'")); var tagExistInPendingConsole = pendingCountPr.Result > 0; if (tagExistInPendingConsole) { await ProcessPendingConsoleAsync(norm, rows); } }
public async Task RunAsync(Decos.Domain.Deco deco) { var pendingConsoles = new List <string>(); var consoleList = new List <string> { deco.ConsoleTag }; //add to console_details first var success = await AddToConsoleDetailsAsync(deco); if (!success) { return; } var rows = new ConcurrentBag <Adapters.Oal.dbo_delivery_console_event_new>(); var map = new Integrations.Transforms.RtsDecoOalDeliveryConsoleEventNew(); var row = await map.TransformAsync(deco); rows.Add(row); rows.AddRange(await GetEventRowsAsync(row, pendingConsoles, consoleList, deco.AllConsignmentnNotes)); // await InsertDeliveryConsoleEventNewAsync(rows); // if (pendingConsoles.Any()) { await InsertEventPendingConsoleAsync(row, pendingConsoles.ToArray()); } var consoleDetailsAdapter = new Adapters.Oal.dbo_console_detailsAdapter(); var tagExistInPendingConsole = (await consoleDetailsAdapter.ExecuteScalarAsync <int>($"SELECT COUNT(*) FROM dbo.event_pending_console WHERE [console_no] = '{deco.ConsoleTag}'")) > 0; if (tagExistInPendingConsole) { await ProcessPendingConsoleAsync(deco, rows); } }