Exemplo n.º 1
0
        private void Subscribe()
        {
            // create an instance of the topic helper
            var helper = ServiceBusTopicHelper.Setup(SubscriptionInitializer.Initialize());

            // send the message into the topic
            helper.Subscribe <PizzaOrder>((order) =>
            {
                // save the order
                var context = new EnterprisePizzaDataContext();
                context.Orders.Add(order);
                context.SaveChanges();

                // write out a note
                Console.WriteLine("Order {0} just taken with {1} pizza(s)",
                                  order.Id,
                                  order.Pizzas.Count);

                // now notify the store of the new order
                order.IsOrdered = true;

                // publish the messages as saved but not received yet
                helper.Publish <PizzaOrder>(order, (m) =>
                {
                    m.Properties["IsOrdered"]         = true;
                    m.Properties["IsReceivedByStore"] = false;
                });
            }
                                          , "(IsOrdered = false) AND (IsReceivedByStore = false)",
                                          "NewPizzaOrders"
                                          );
        }
        public ActionResult SampleOrder()
        {
            // create a random order
            var randomOrder = CreateRandomOrder();

            // serialize the order into JSON
            var json = JsonConvert.SerializeObject(randomOrder, Formatting.None, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            // send the message into the topic
            ServiceBusTopicHelper
            .Setup(SubscriptionInitializer.Initialize())
            .Publish <PizzaOrder>(randomOrder, (m) =>
            {
                m.Properties["IsOrdered"]         = false;
                m.Properties["IsReceivedByStore"] = false;
            });

            // queue up the message
            //StorageQueueHelper.OpenQueue("incomingorders").Enqueue(json);

            // remember the clientId for the client
            ViewBag.clientId = randomOrder.ClientIdentifier.ToString();

            return(View());
        }
        public MainWindow()
        {
            InitializeComponent();

            base.Loaded += (sender, args) =>
            {
                this.ViewModel   = new MainPageViewModel();
                this.DataContext = this.ViewModel;

                ServiceBusTopicHelper.Setup(SubscriptionInitializer.Initialize())
                .Subscribe <PizzaOrder>((order) => AddOrderToView(order)
                                        , "(IsOrdered = true) AND (IsReceivedByStore = false)"
                                        , "OrdersSentToStore"
                                        );
            };
        }