Ejemplo n.º 1
0
        protected Task <string> GetItemConsigmentsFromConsoleDetailsAsync(string consoleNo)
        {
            var consoleDetailsAdapter = new Entt_ConsoleAdapter();
            var query = $"SELECT TOP 1 [ItemConsignments] FROM [Entt].[ConsoleDetails] WHERE [ConsoleNo] = '{consoleNo}' ORDER BY [DateTime] DESC";

            return(consoleDetailsAdapter.ExecuteScalarAsync <string>(query));
        }
Ejemplo n.º 2
0
        private async Task InsertConsoleAsync(IEnumerable <Entt_Console> rows)
        {
            var consoleAdapter = new Entt_ConsoleAdapter();

            foreach (var item in rows)
            {
                Console.Write(".");
                if (string.IsNullOrWhiteSpace(item.ItemConsignments))
                {
                    continue;
                }

                var pr0 = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout())
                          .WaitAndRetryAsync(RetryCount, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                          .ExecuteAndCaptureAsync(() => consoleAdapter.ExecuteScalarAsync <int>($"SELECT COUNT(*) FROM [Entt].[Console] WHERE [Id]='{item.Id}'"));
                var result0 = await pr0;
                if (result0.FinalException != null)
                {
                    throw result0.FinalException;
                }
                if (result0.Result > 0)
                {
                    continue;
                }

                var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout())
                         .WaitAndRetryAsync(RetryCount, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                         .ExecuteAndCaptureAsync(() => consoleAdapter.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");
            }
        }