Exemplo n.º 1
0
        private async Task ProcessWwpPendingItem(string wwpEventId, string[] itemList)
        {
            var wwpAdapter = new Adapters.Oal.dbo_wwp_event_new_logAdapter();
            var wwpPolly   = await Policy.Handle <SqlException>(e => e.IsTimeout())
                             .WaitAndRetryAsync(RetryCount, WaitInterval)
                             .ExecuteAndCaptureAsync(async() => await wwpAdapter.LoadOneAsync(wwpEventId));

            if (null != wwpPolly.FinalException)
            {
                throw new Exception("Wwp Pending Polly Error", wwpPolly.FinalException);
            }

            var wwp = wwpPolly.Result;

            if (null == wwp)
            {
                return;
            }

            var wwpItems = new List <Adapters.Oal.dbo_wwp_event_new_log>();

            foreach (var item in itemList)
            {
                var child = wwp.Clone();
                child.id = GenerateId(34);
                child.consignment_note_number = item;
                child.date_sent_date_field    = null;
                wwpItems.Add(child);
            }
            foreach (var item in wwpItems)
            {
                var pr = Policy.Handle <SqlException>(e => e.IsDeadlockOrTimeout())
                         .WaitAndRetryAsync(RetryCount, WaitInterval)
                         .ExecuteAndCaptureAsync(() => wwpAdapter.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");
            }
        }
Exemplo n.º 2
0
        public async Task RunAsync(Deliveries.Domain.Delivery deli)
        {
            //console_details
            var consoleList = new List <string>();

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

            var deliEventAdapter    = new Adapters.Oal.dbo_delivery_event_newAdapter();
            var deliWwpEventAdapter = new Adapters.Oal.dbo_wwp_event_new_logAdapter();
            var deliEventMap        = new Integrations.Transforms.RtsDeliveryToOalDboDeliveryEventNew();
            var deliIpsImportMap    = new Integrations.Transforms.RtsDeliveryToIpsImport();
            var parentRow           = await deliEventMap.TransformAsync(deli);

            var parentIpsRow = await deliIpsImportMap.TransformAsync(deli);

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

            var deliWwpEventLogMap = new Integrations.Transforms.RtsDeliveryOalWwpEventNewLog();
            var parentWwpRow       = await deliWwpEventLogMap.TransformAsync(deli);

            m_deliWwpEventLogRows.Add(parentWwpRow);

            var consoleItem = await GetItemConsigmentsFromConsoleDetailsAsync(deli.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);
                    if (IsIpsImportItem(item))
                    {
                        await ProcessChildIpsImport(parentIpsRow, 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);
                                if (IsIpsImportItem(cc))
                                {
                                    await ProcessChildIpsImport(parentIpsRow, 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);
                                            if (IsIpsImportItem(ccc))
                                            {
                                                await ProcessChildIpsImport(parentIpsRow, ccc);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        AddPendingItems(parentRow.id, parentWwpRow.id, cc);
                                    }
                                }
                            }
                        }
                        else
                        {
                            AddPendingItems(parentRow.id, parentWwpRow.id, item);
                        }
                    }
                }
            }
            else
            {
                AddPendingItems(parentRow.id, parentWwpRow.id, deli.ConsignmentNo);
            }

            foreach (var item in m_deliEventRows)
            {
                var pr = Policy.Handle <SqlException>()
                         .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                         .ExecuteAndCaptureAsync(() => TrackEvents(deliEventAdapter.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_deliWwpEventLogRows)
            {
                var pr = Policy.Handle <SqlException>()
                         .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                         .ExecuteAndCaptureAsync(() => TrackEvents(deliWwpEventAdapter.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 ipsAdapter = new Adapters.Oal.dbo_ips_importAdapter();

            foreach (var item in m_deliIpsImportEventRows)
            {
                var pr = Policy.Handle <SqlException>()
                         .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                         .ExecuteAndCaptureAsync(() => TrackEvents(ipsAdapter.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_deliEventPendingConsoleRows)
            {
                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");
            }
        }
Exemplo n.º 3
0
        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");
            }
        }
Exemplo n.º 4
0
        public async Task RunAsync(Pickup pickup)
        {
            //pickup_event_new
            var eventNewMap        = new Integrations.Transforms.RtsPickupToOalPickupEventNew();
            var pickupEventNewRows = new List <Adapters.Oal.dbo_pickup_event_new>();
            var parentRow          = await eventNewMap.TransformAsync(pickup);

            pickupEventNewRows.Add(parentRow);

            if (null != pickup.BabyConsignment)
            {
                var babies = pickup.BabyConsignment.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var babyConsignmentNo in babies)
                {
                    var childRow = parentRow.Clone();
                    childRow.id = GenerateId(34);
                    childRow.date_created_oal_date_field = DateTime.Now;
                    childRow.consignment_no = babyConsignmentNo;
                    childRow.item_type_code = (babyConsignmentNo.StartsWith("CG") && babyConsignmentNo.EndsWith("MY") &&
                                               babyConsignmentNo.Length == 13)
                        ? "02"
                        : "01";
                    childRow.data_flag = "1";
                    childRow.parent_no = parentRow.consignment_no;
                    pickupEventNewRows.Add(childRow);
                }
            }

            var eventNewAdapter = new Adapters.Oal.dbo_pickup_event_newAdapter();

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

            //consigment_initial
            var consignmentInitialMap  = new Integrations.Transforms.RtsPickupToOalConsigmentInitial();
            var consignmentInitialRows = new List <Adapters.Oal.UspConsigmentInitialRtsRequest>();
            var consignmentParentRow   = await consignmentInitialMap.TransformAsync(pickup);

            consignmentInitialRows.Add(consignmentParentRow);



            if (null != pickup.BabyConsignment)
            {
                var      consignmentBabies = pickup.BabyConsignment.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string[] babiesWeight      = { };
                if (!string.IsNullOrEmpty(pickup.BabyWeigth))
                {
                    babiesWeight = pickup.BabyWeigth.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }
                var babiesHeight = pickup.BabyHeigth.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var babiesWidth  = pickup.BabyWidth.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var babiesLength = pickup.BabyLength.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var index        = 0;

                foreach (var babyConsignmentNo in consignmentBabies)
                {
                    var consignmentChildRow = consignmentParentRow.Clone();
                    consignmentChildRow.id = GenerateId(20);
                    consignmentChildRow.dt_created_date_field = DateTime.Now;
                    consignmentChildRow.baby_item             = consignmentParentRow.id;
                    consignmentChildRow.parent    = consignmentParentRow.id;
                    consignmentChildRow.is_parent = 0;
                    consignmentChildRow.number    = babyConsignmentNo;
                    if (babiesWeight.Length == consignmentBabies.Length)
                    {
                        consignmentChildRow.weight_double = GetDoubleValue(babiesWeight[index]);
                    }
                    else
                    {
                        consignmentChildRow.weight_double = 0;
                    }
                    consignmentChildRow.height_double = GetDoubleValue(babiesHeight[index]);
                    consignmentChildRow.length_double = GetDoubleValue(babiesLength[index]);
                    consignmentChildRow.width_double  = GetDoubleValue(babiesWidth[index]);

                    consignmentInitialRows.Add(consignmentChildRow);
                    index++;
                }
            }

            var oal = new Adapters.Oal.Oal();

            foreach (var item in consignmentInitialRows)
            {
                var pr = Policy.Handle <SqlException>()
                         .WaitAndRetryAsync(5, x => TimeSpan.FromMilliseconds(500 * Math.Pow(2, x)))
                         .ExecuteAndCaptureAsync(() => oal.UspConsigmentInitialRtsAsync(item));
                var result = await pr;
                if (result.FinalException != null)
                {
                    throw result.FinalException; // send to dead letter queue
                }
            }

            //wwp_event_new
            var wwpEventNewLogMap       = new Integrations.Transforms.RtsPickupOalWwpEventNewLog();
            var wwpEventNewLogRows      = new List <Adapters.Oal.dbo_wwp_event_new_log>();
            var wwpEventNewLogParentRow = await wwpEventNewLogMap.TransformAsync(pickup);

            wwpEventNewLogRows.Add(wwpEventNewLogParentRow);

            if (null != pickup.BabyConsignment)
            {
                var wwpLogBabies = pickup.BabyConsignment.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var babyConsignmentNo in wwpLogBabies)
                {
                    var wwpLogChildRow = wwpEventNewLogParentRow.Clone();
                    wwpLogChildRow.id = GenerateId(34);
                    wwpLogChildRow.dt_created_oal_date_field = DateTime.Now;
                    wwpLogChildRow.consignment_note_number   = babyConsignmentNo;
                    wwpEventNewLogRows.Add(wwpLogChildRow);
                }
            }

            var wwpLogAdapter = new Adapters.Oal.dbo_wwp_event_new_logAdapter();

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