Exemple #1
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();
                }
            }
        }
        //public Guid SubmitDelivery(DeliveryCo.Business.Entities.DeliveryInfo pDeliveryInfo)
        //{
        //    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)));
        //        lScope.Complete();
        //    }
        //    return pDeliveryInfo.DeliveryIdentifier;
        //}

        public void SubmitDelivery(Message message)
        {
            //Specify the binding to be used for the client.
            NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None);

            //Specify the address to be used for the client.
            EndpointAddress address =
                new EndpointAddress("net.msmq://localhost/private/PublisherMessageQueue");
            PublisherServiceClient lClient = new PublisherServiceClient(binding, address);

            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryDataModelContainer lContainer = new DeliveryDataModelContainer())
                {
                    DeliveryMessage mDeliveryMessage = message as DeliveryMessage;
                    mDeliveryMessage.DeliveryIdentifier = Guid.NewGuid();
                    mDeliveryMessage.Status             = 0;
                    mDeliveryMessage.Topic = "delivery";
                    DeliveryInfo pDeliveryInfo = new DeliveryInfo()
                    {
                        OrderNumber                 = mDeliveryMessage.OrderNumber,
                        SourceAddress               = mDeliveryMessage.SourceAddress,
                        DestinationAddress          = mDeliveryMessage.DestinationAddress,
                        DeliveryNotificationAddress = "net.msmq://localhost/private/DeliveryNotificationQueue"
                    };
                    lContainer.DeliveryInfoes.AddObject(pDeliveryInfo);
                    lContainer.SaveChanges();
                    //lClient.Publish(mDeliveryMessage);
                    //Console.WriteLine("Delivery submitted and planing deliver to " + pDeliveryInfo.DestinationAddress);
                    ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo, mDeliveryMessage.DeliveryIdentifier, lClient)));


                    lScope.Complete();
                }
        }
Exemple #3
0
        public void SubmitDelivery(DeliveryInfo pDeliveryInfo)
        {
            SystemWideLogging.LogServiceClient.LogEvent("DeliveryCo :: DeliveryCo.Business\\DeliveryCo.Business.Components\\DeliveryProvider.cs :: public void SubmitDelivery(DeliveryInfo pDeliveryInfo)", "Received Delivery Request from MessageBus - via Pub/Sub");


            using (var lScope = new TransactionScope())
                using (var lContainer = new DeliveryDataModelContainer())
                {
                    pDeliveryInfo.DeliveryIdentifier = pDeliveryInfo.DeliveryIdentifier;
                    pDeliveryInfo.Status             = 0;
                    lContainer.DeliveryInfoes.AddObject(pDeliveryInfo);
                    lContainer.SaveChanges();
                    ThreadPool.QueueUserWorkItem(pObj => ScheduleDelivery(pDeliveryInfo));
                    lScope.Complete();
                }



            SystemWideLogging.LogServiceClient.LogEvent("DeliveryCo :: DeliveryCo.Business\\DeliveryCo.Business.Components\\DeliveryProvider.cs :: public void SubmitDelivery(DeliveryInfo pDeliveryInfo)", "Sending Delivery Confirmation Receipt to VideoStore - via MSMQ");
            // Send notification back to VideoStore App
            var notificationService = ServiceFactory.GetService <IDeliveryNotificationService>(DeliveryNotificationServiceEndpointAddress);

            notificationService.NotifyDeliverySubmission(Guid.Parse(pDeliveryInfo.OrderNumber), pDeliveryInfo.DeliveryIdentifier);

            Console.WriteLine("Delivery request for order '{0}' has submitted", pDeliveryInfo.OrderNumber);
        }
Exemple #4
0
 public Guid SubmitDelivery(DeliveryCo.Business.Entities.DeliveryInfo pDeliveryInfo)
 {
     using (TransactionScope lScope = new TransactionScope())
         using (DeliveryDataModelContainer lContainer = new DeliveryDataModelContainer())
         {
             pDeliveryInfo.Status = 0;
             lContainer.DeliveryInfoes.AddObject(pDeliveryInfo);
             lContainer.SaveChanges();
             ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo)));
             lScope.Complete();
         }
     return(pDeliveryInfo.DeliveryIdentifier);
 }
Exemple #5
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.NotifyDeliveryProcessed(pDeliveryInfo.OrderNumber, pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Submitted, "");
                        Common.Model.DeliverProcessedMessage deliverProcessedMessage = new Common.Model.DeliverProcessedMessage()
                        {
                            Topic       = "VideoStore",
                            orderNumber = pDeliveryInfo.OrderNumber,
                            pDeliveryId = pDeliveryInfo.DeliveryIdentifier,
                            status      = (int)DeliveryInfoStatus.Submitted,
                            errorMsg    = ""
                        };
                        PublisherServiceClient lClient = new PublisherServiceClient();
                        lClient.Publish(deliverProcessedMessage);
                        lScope.Complete();
                    }
                //  return pDeliveryInfo.DeliveryIdentifier;
            }
            catch (Exception ex)
            {
                using (TransactionScope lScope = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    //IDeliveryNotificationService lService = DeliveryNotificationServiceFactory.GetDeliveryNotificationService(pDeliveryInfo.DeliveryNotificationAddress);
                    //lService.NotifyDeliveryProcessed(pDeliveryInfo.OrderNumber, pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Failed, ex.ToString());

                    //lScope.Complete();
                    Common.Model.DeliverProcessedMessage deliverProcessedMessage = new Common.Model.DeliverProcessedMessage()
                    {
                        Topic       = "VideoStore",
                        orderNumber = pDeliveryInfo.OrderNumber,
                        pDeliveryId = pDeliveryInfo.DeliveryIdentifier,
                        status      = (int)DeliveryInfoStatus.Failed,
                        errorMsg    = ex.ToString()
                    };
                    PublisherServiceClient lClient = new PublisherServiceClient();
                    lClient.Publish(deliverProcessedMessage);
                    lScope.Complete();
                }
            }
        }
Exemple #6
0
        public void SubmitDelivery(DeliveryCo.Business.Entities.DeliveryInfo pDeliveryInfo)
        {
            using (TransactionScope lScope = new TransactionScope())
                using (DeliveryDataModelContainer lContainer = new DeliveryDataModelContainer())
                {
                    pDeliveryInfo.DeliveryIdentifier = Guid.NewGuid();
                    pDeliveryInfo.Status             = 0;
                    lContainer.DeliveryInfoes.AddObject(pDeliveryInfo);
                    lContainer.SaveChanges();

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

                    ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo)));
                    lScope.Complete();
                }
        }
Exemple #7
0
 public void SubmitDelivery(DeliveryCo.Business.Entities.DeliveryInfo pDeliveryInfo)
 {
     using (TransactionScope lScope = new TransactionScope())
         using (DeliveryDataModelContainer lContainer = new DeliveryDataModelContainer())
         {
             try
             {
                 //pDeliveryInfo.DeliveryIdentifier = Guid.NewGuid();
                 pDeliveryInfo.Status = 0;
                 lContainer.DeliveryInfoes.AddObject(pDeliveryInfo);
                 lContainer.SaveChanges();
                 ThreadPool.QueueUserWorkItem(new WaitCallback((pObj) => ScheduleDelivery(pDeliveryInfo)));
                 lScope.Complete();
             }
             catch (Exception lException)
             {
                 Console.WriteLine("Error occured while delivering:  " + lException.Message);
                 DeliveryNotificationService.DeliveryNotificationServiceClient lClient = new DeliveryNotificationService.DeliveryNotificationServiceClient();
                 lClient.NotifyDeliveryCompletion(pDeliveryInfo.DeliveryIdentifier, DeliveryInfoStatus.Failed);
                 throw;
             }
         }
     //return pDeliveryInfo.DeliveryIdentifier;
 }
Exemple #8
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;
                    lContainer.SaveChanges();

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

                    lScope.Complete();
                }
            }
        }