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()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ServiceBusTopicHelper.Initialize(); }
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" ); }; }
public ActionResult SubmitOrder(ProductOrder productOrder) { //if (ModelState.IsValid) { try { ViewBag.SubmitResponse = string.Empty; AzureGuidance.Domain.Order order = new AzureGuidance.Domain.Order(); order.CustomerName = productOrder.order.CustomerName; order.OrderDate = DateTime.Now; order.EmailId = productOrder.order.EmailId; order.ProductOrderDetailsList = new List <ProductDetails>(); foreach (AddProduct p in productOrder.lstProducts) { if (true == p.SelectProduct) { ProductDetails productDetails = new ProductDetails(); productDetails.ProductName = p.ProductName; productDetails.ProductQuantity = p.ProductQuantity; order.TotalDue += p.UnitPrice * p.ProductQuantity; order.orderStatus = "Processed"; order.OrderId = Guid.NewGuid(); order.ProductOrderDetailsList.Add(productDetails); p.ProductQuantity = 0; p.SelectProduct = false; } } var message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(order); if (null == ServiceBusTopicHelper.OrdersTopicClient) { ServiceBusTopicHelper.Initialize(); } ServiceBusTopicHelper.OrdersTopicClient.Send(message); } catch (Exception ex) { Console.WriteLine(ex.Message); } } ProductOrder pOrder = new ProductOrder(); List <AddProduct> lstProducts = new List <AddProduct>(); pOrder.lstProducts = productOrder.lstProducts; ModelState.Clear(); ViewBag.SubmitResponse = "Order proccessed successfully."; return(View("DisplayProducts", pOrder)); }