Пример #1
0
        private async Task ProcessSipPendingItem(string sipEventId, string[] itemList)
        {
            var sipAdapter      = new Adapters.Oal.dbo_sip_event_newAdapter();
            var sipPendingPolly = await Policy.Handle <SqlException>(e => e.IsTimeout())
                                  .WaitAndRetryAsync(RetryCount, WaitInterval)
                                  .ExecuteAndCaptureAsync(async() => await sipAdapter.LoadOneAsync(sipEventId));

            if (null != sipPendingPolly.FinalException)
            {
                throw new Exception("Process Sip Pending Polly Error", sipPendingPolly.FinalException);
            }

            var sip  = sipPendingPolly.Result;
            var sips = new List <Adapters.Oal.dbo_sip_event_new>();

            foreach (var item in itemList)
            {
                var console = IsConsole(item);
                var child   = sip.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;
                }
                sips.Add(child);
            }
            foreach (var item in sips)
            {
                var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout())
                         .WaitAndRetryAsync(RetryCount, WaitInterval)
                         .ExecuteAndCaptureAsync(() => sipAdapter.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");
            }
        }
Пример #2
0
        public async Task RunAsync(Sips.Domain.Sip sip)
        {
            //console_details
            var consoleList = new List <string>();

            if (IsConsole(sip.ConsignmentNo))
            {
                consoleList.Add(sip.ConsignmentNo);
            }

            var sipEventAdapter    = new Adapters.Oal.dbo_sip_event_newAdapter();
            var sipWwpEventAdapter = new Adapters.Oal.dbo_wwp_event_new_logAdapter();
            var sipEventMap        = new Integrations.Transforms.RtsSipToOalSipEventNew();
            var parentRow          = await sipEventMap.TransformAsync(sip);

            parentRow.id = GenerateId(34);
            m_sipEventRows.Add(parentRow);

            var sipWwpEventLogMap = new Integrations.Transforms.RtsSipToOalSipWwpEventNewLog();
            var parentWwpRow      = await sipWwpEventLogMap.TransformAsync(sip);

            m_sipWwpEventLogRows.Add(parentWwpRow);

            var consoleItem = await GetItemConsigmentsFromConsoleDetailsAsync(sip.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, sip.ConsignmentNo);
            }

            foreach (var item in m_sipEventRows)
            {
                var pr = Policy.Handle <SqlException>()
                         .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                         .ExecuteAndCaptureAsync(() => TrackEvents(sipEventAdapter.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_sipWwpEventLogRows)
            {
                var pr = Policy.Handle <SqlException>()
                         .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                         .ExecuteAndCaptureAsync(() => TrackEvents(sipWwpEventAdapter.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_sipEventPendingConsoleRows)
            {
                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");
            }
        }