private void ScheduleDelivery(DeliveryInfo pDeliveryInfo, int[][] confirmedOrders)
        {
            Console.WriteLine("Request has been received for at least one delivery to " + pDeliveryInfo.DestinationAddress);
            Thread.Sleep(2000);

            for (int i = 0; i < confirmedOrders.GetLength(0); i++)
            {
                Console.WriteLine(confirmedOrders[i][2] + " Book(s) with ID " + confirmedOrders[i][0] + " have been picked up from warehouse with ID " + confirmedOrders[i][1]);
                Thread.Sleep(1000);
            }

            for (int i = 0; i < confirmedOrders.GetLength(0); i++)
            {
                Console.WriteLine(confirmedOrders[i][2] + " Book(s) with ID " + confirmedOrders[i][0] + " are on a delivery truck");
                Thread.Sleep(1000);
            }

            //notifying of delivery completion
            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    pDeliveryInfo.Status = 1;
                    IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
                    lService.NotifyDeliveryCompletion(pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Delivered);
                }

            for (int i = 0; i < confirmedOrders.GetLength(0); i++)
            {
                Console.WriteLine(confirmedOrders[i][2] + " Book(s) with ID " + confirmedOrders[i][0] + " have been delivered");
                Thread.Sleep(1000);
            }
            Console.WriteLine("Order is completed. Thank you for shopping with the book store.");
        }
Ejemplo n.º 2
0
        public void SubmitDelivery(DeliveryCo.Business.Entities.DeliveryInfo pDeliveryInfo)
        {
            try
            {
                using (TransactionScope lScope = new TransactionScope())
                    using (DeliveryDataModelContainer lContainer = new DeliveryDataModelContainer())
                    {
                        pDeliveryInfo.DeliveryIdentifier = Guid.NewGuid();
                        pDeliveryInfo.Status             = 0;
                        lContainer.DeliveryInfoes.AddObject(pDeliveryInfo);
                        lContainer.SaveChanges();
                        ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo)));

                        IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
                        lService.NotifyDeliverySubmitted(pDeliveryInfo.OrderNumber, pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Submitted, "");

                        lScope.Complete();
                    }
            }
            catch (Exception ex)
            {
                using (TransactionScope lScope = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
                    lService.NotifyDeliverySubmitted(pDeliveryInfo.OrderNumber, pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Failed, ex.ToString());

                    lScope.Complete();
                }
            }
        }
Ejemplo n.º 3
0
 private void ScheduleDelivery(DeliveryInfo pDeliveryInfo)
 {
     Console.WriteLine("Delivering to" + pDeliveryInfo.DestinationAddress);
     Thread.Sleep(3000);
     //notifying of delivery completion
     using (TransactionScope lScope = new TransactionScope())
         using (DeliveryDataModelContainer lContainer = new DeliveryDataModelContainer())
         {
             pDeliveryInfo.Status = 1;
             IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
             lService.NotifyDeliveryCompletion(pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Delivered);
         }
 }
Ejemplo n.º 4
0
        private void ScheduleDelivery(DeliveryInfo pDeliveryInfo)
        {
            IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);

            Console.WriteLine("Delivering to" + pDeliveryInfo.DestinationAddress + pDeliveryInfo.OrderNumber);
            Thread.Sleep(1000);
            //notifying of delivery completion
            using (DeliveryDataModelContainer lContainer = new DeliveryDataModelContainer())
            {
                pDeliveryInfo.Status = 1;
                lService.NotifyDeliveryCompletion(pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Delivered);
                Console.WriteLine("Just notified Video Store the order: " + pDeliveryInfo.OrderNumber + " has been delivered");
            }
        }
Ejemplo n.º 5
0
        public Guid RefundDelivery(String pDeliveryInfo)
        {
            Console.WriteLine("(" + DateTime.Now + ") Order " + pDeliveryInfo + " has been refunded.");
            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    Guid value = new Guid(pDeliveryInfo);

                    var item = from d in lContainer.DeliveryInfo
                               where d.DeliveryIdentifier == value
                               select d;

                    var i = item.First();
                    i.Status = 2;
                    lContainer.SaveChanges();
                    lScope.Complete();
                    IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(i.DeliveryNotificationAddress);
                    lService.NotifyDeliveryCompletion(i.DeliveryIdentifier, DeliveryInfoStatus.Failed);

                    //do the bank account refund
                    return(i.DeliveryIdentifier);
                }
        }
Ejemplo n.º 6
0
        private void ScheduleDelivery(DeliveryInfo pDeliveryInfo)
        {
            Console.WriteLine("(" + DateTime.Now + ") Delivering to " + pDeliveryInfo.DestinationAddress);
            Thread.Sleep(10000);
            //notifying of delivery completion
            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    var item = from d in lContainer.DeliveryInfo
                               where d.DeliveryIdentifier == pDeliveryInfo.DeliveryIdentifier
                               select d;

                    var i = item.First();
                    if (i != null && i.Status != 2)
                    {
                        i.Status = 1;
                        IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(i.DeliveryNotificationAddress);
                        lService.NotifyDeliveryCompletion(i.DeliveryIdentifier, DeliveryInfoStatus.Delivered);
                        lContainer.SaveChanges();
                        lScope.Complete();
                    }
                }
        }
Ejemplo n.º 7
0
        private void ScheduleDelivery(DeliveryInfo pDeliveryInfo, List <Tuple <String, List <String> > > pOrderItems)
        {
            // Pick up notification
            Console.WriteLine("Request for delivering items received! Delivering from warehouse address: " + pDeliveryInfo.SourceAddress + " to " + pDeliveryInfo.DestinationAddress);

            // notify received request
            ExternalServiceFactory.Instance.OrderService.GetNotificationFromDeliveryCo("Notification from DeliveryCo: Received request to deliver books from warehouse address: " + pDeliveryInfo.SourceAddress + " to " + pDeliveryInfo.DestinationAddress);


            Thread.Sleep(3000);

            // notify goods have been picked up
            ExternalServiceFactory.Instance.OrderService.GetNotificationFromDeliveryCo("Notification from DeliveryCo: Books for delivery number: " + pDeliveryInfo.DeliveryIdentifier + " has been picked up");

            bool lEmailResult = true;

            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
                    lEmailResult = lService.NotifyPickedUpOrder(pDeliveryInfo.DeliveryIdentifier);
                }

            // Order got cancelled
            if (!lEmailResult)
            {
                Console.WriteLine("Delivery number " + pDeliveryInfo.DeliveryIdentifier + " was cancelled by the customer.");
                ExternalServiceFactory.Instance.OrderService.GetNotificationFromDeliveryCo("Notification from DeliveryCo: Delivery number " + pDeliveryInfo.DeliveryIdentifier + " was cancelled by the customer.");
                return;
            }

            Thread.Sleep(3000);

            // notify that goods are on their way
            ExternalServiceFactory.Instance.OrderService.GetNotificationFromDeliveryCo("Notification from DeliveryCo: Books for delivery number " + pDeliveryInfo.DeliveryIdentifier + " are on their way to the customer at address " + pDeliveryInfo.DestinationAddress);

            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
                    lEmailResult = lService.NotifyOnDeliveryTruckOrder(pDeliveryInfo.DeliveryIdentifier);
                }

            foreach (Tuple <string, List <String> > e in pOrderItems)
            {
                Console.WriteLine("Book " + e.Item1 + " dispatching from warehouses:");
                foreach (String f in e.Item2)
                {
                    Console.WriteLine(f);
                }
                Console.WriteLine();
            }

            // Order got cancelled
            if (!lEmailResult)
            {
                Console.WriteLine("Delivery number " + pDeliveryInfo.DeliveryIdentifier + " was cancelled by the customer.");
                ExternalServiceFactory.Instance.OrderService.GetNotificationFromDeliveryCo("Notification from DeliveryCo: Delivery number " + pDeliveryInfo.DeliveryIdentifier + " was cancelled by the customer.");
                return;
            }

            Console.WriteLine("Delivering to " + pDeliveryInfo.DestinationAddress);

            //notifying of delivery completion
            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    pDeliveryInfo.Status = 1;
                    IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
                    lService.NotifyDeliveryCompletion(pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Delivered);
                }

            // notify order is completed to the BookStore
            ExternalServiceFactory.Instance.OrderService.GetNotificationFromDeliveryCo("Notification from DeliveryCo: Books for delivery number: " + pDeliveryInfo.DeliveryIdentifier + " were delivered successfully!");
        }