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.");
        }
 public bool DeleteDelivery(String OrderNumber)
 {
     using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
     {
         try
         {
             Console.WriteLine("===========Delivery Deleted===========");
             Console.WriteLine("Order Number: " + OrderNumber);
             Console.WriteLine("Status: SUCCESS");
             Console.WriteLine("Time: " + DateTime.Now);
             Console.WriteLine("======================================");
             DeliveryInfo deleteDelivery = lContainer.DeliveryInfo.Where <DeliveryInfo>(s => s.OrderNumber.Equals(OrderNumber)).First();
             lContainer.DeliveryInfo.Remove(deleteDelivery);
             return(true);
         }
         catch (Exception e)
         {
             Console.WriteLine("===========Delivery Deleted===========");
             Console.WriteLine("Order Number: " + OrderNumber);
             Console.WriteLine("Status: FAILED");
             Console.WriteLine("Time: " + DateTime.Now);
             Console.WriteLine("======================================");
             return(false);
         }
     }
 }
示例#3
0
 public List <DeliveryInfo> getAllDelivery()
 {
     using (TransactionScope lScope = new TransactionScope())
         using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
         {
             return(lContainer.DeliveryInfo.Where((delivery) => delivery.Status != 2).ToList());
         }
 }
 public Guid SubmitDelivery(DeliveryCo.Business.Entities.DeliveryInfo pDeliveryInfo, int[][] confirmedOrders)
 {
     using (TransactionScope lScope = new TransactionScope())
         using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
         {
             pDeliveryInfo.DeliveryIdentifier = Guid.NewGuid();
             pDeliveryInfo.Status             = 0;
             lContainer.DeliveryInfo.Add(pDeliveryInfo);
             lContainer.SaveChanges();
             ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo, confirmedOrders)));
             lScope.Complete();
         }
     return(pDeliveryInfo.DeliveryIdentifier);
 }
示例#5
0
        public void SubmitDelivery(Entities.DeliveryInfo pDeliveryInfo)
        {
            using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
            {
                pDeliveryInfo.DeliveryIdentifier = Guid.NewGuid();
                pDeliveryInfo.Status             = 0;
                lContainer.DeliveryInfo.Add(pDeliveryInfo);
                lContainer.SaveChanges();

                DeliverySubmittedInfo lItem = new DeliverySubmittedInfo {
                    OrderNumber = Guid.Parse(pDeliveryInfo.OrderNumber), DeliveryId = pDeliveryInfo.DeliveryIdentifier
                };
                DeliverySubmittedInfoMessageToDeliveryNotification lVisitor =
                    new DeliverySubmittedInfoMessageToDeliveryNotification(pDeliveryInfo.DeliveryIdentifier);
                lVisitor.Visit(lItem);
                PublisherServiceClient lClient = new PublisherServiceClient();
                lClient.Publish(lVisitor.Result);

                ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo)));
            }
        }
示例#6
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);
                }
        }
示例#7
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();
                    }
                }
        }
        public Guid SubmitDelivery(DeliveryCo.Business.Entities.DeliveryInfo pDeliveryInfo, List <Tuple <String, List <String> > > pOrderItems)
        {
            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    pDeliveryInfo.DeliveryIdentifier = Guid.NewGuid();
                    pDeliveryInfo.Status             = 0;
                    lContainer.DeliveryInfo.Add(pDeliveryInfo);
                    lContainer.SaveChanges();
                    ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo, pOrderItems)));
                    lScope.Complete();
                }

            Console.WriteLine("===========Delivery Submitted===========");
            Console.WriteLine("Order items:");
            foreach (Tuple <String, List <String> > x in pOrderItems)
            {
                Console.WriteLine("          " + x.Item1);
            }
            Console.WriteLine("Time: " + DateTime.Now);
            Console.WriteLine("========================================");
            Console.WriteLine(" ");
            return(pDeliveryInfo.DeliveryIdentifier);
        }
示例#9
0
        private void ScheduleDelivery(DeliveryInfo pDeliveryInfo)
        {
            Console.WriteLine("Delivery Request Submitted. Order" + pDeliveryInfo.OrderNumber + " is ready for pickup from warehouse: " + pDeliveryInfo.SourceAddress + ". Delivering to: " + pDeliveryInfo.DestinationAddress);
            Thread.Sleep(5000);
            //notifying of delivery pick up
            using (TransactionScope lScope = new TransactionScope())
            {
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    pDeliveryInfo.Status = 1;
                    lContainer.SaveChanges();

                    DeliveryStatus lItem = new DeliveryStatus {
                        DeliveryInfo = pDeliveryInfo
                    };
                    DeliveryStatusMessageToDeliveryNotification lVisitor = new DeliveryStatusMessageToDeliveryNotification();
                    lVisitor.Visit(lItem);
                    PublisherServiceClient lClient = new PublisherServiceClient();
                    lClient.Publish(lVisitor.Result);

                    lScope.Complete();
                }
            }
            Console.WriteLine("Delivery picked up from warehouse " + pDeliveryInfo.SourceAddress + ". Delivering to:" + pDeliveryInfo.DestinationAddress);
            Thread.Sleep(5000);
            //notifying of delivery in transit
            using (TransactionScope lScope = new TransactionScope())
            {
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    pDeliveryInfo.Status = 2;
                    lContainer.SaveChanges();

                    DeliveryStatus lItem = new DeliveryStatus {
                        DeliveryInfo = pDeliveryInfo
                    };
                    DeliveryStatusMessageToDeliveryNotification lVisitor = new DeliveryStatusMessageToDeliveryNotification();
                    lVisitor.Visit(lItem);
                    PublisherServiceClient lClient = new PublisherServiceClient();
                    lClient.Publish(lVisitor.Result);

                    lScope.Complete();
                }
            }
            Console.WriteLine("Delivery " + pDeliveryInfo.Id + " completed. Books in order " + pDeliveryInfo.OrderNumber + " delivered to " + pDeliveryInfo.DestinationAddress);
            Thread.Sleep(5000);
            using (TransactionScope lScope = new TransactionScope())
            {
                using (DeliveryCoEntityModelContainer lContainer = new DeliveryCoEntityModelContainer())
                {
                    pDeliveryInfo.Status = 3;
                    lContainer.SaveChanges();

                    DeliveryStatus lItem = new DeliveryStatus {
                        DeliveryInfo = pDeliveryInfo
                    };
                    DeliveryStatusMessageToDeliveryNotification lVisitor = new DeliveryStatusMessageToDeliveryNotification();
                    lVisitor.Visit(lItem);
                    PublisherServiceClient lClient = new PublisherServiceClient();
                    lClient.Publish(lVisitor.Result);

                    lScope.Complete();
                }
            }
        }
        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!");
        }