static void SendOrder(Order order)
 {
     var qc = QueueClient.Create(DUPLICATE_QUEUE);
     var msg = new BrokeredMessage(order);
     msg.MessageId = order.Id;
     qc.Send(msg);
 }
 static void SendOrderLater(Order order, DateTime whenToSend)
 {
     var qc = QueueClient.Create(DUPLICATE_QUEUE);
     var msg = new BrokeredMessage(order);
     msg.ScheduledEnqueueTimeUtc = whenToSend;
     qc.Send(msg);
 }
        static void Defer(Order order)
        {
            var deferList = new List<long>();
            var qc = QueueClient.Create(DUPLICATE_QUEUE);

            var orderMsg = new BrokeredMessage(order);
            orderMsg.Properties.Add("type", "place-order");
            qc.Send(orderMsg);

            var command = new BrokeredMessage();
            command.Properties.Add("type", "stop-command");
            qc.Send(command);

            var orderMsg2 = new BrokeredMessage(order);
            orderMsg2.Properties.Add("type", "place-order");
            qc.Send(orderMsg2);

            for(int i=0;i<3;i++)
            {
                var msg = qc.Receive();
                if(String.Equals(msg.Properties["type"], "stop-command"))
                {
                    deferList.Add(msg.SequenceNumber);
                    msg.Defer();
                    Console.WriteLine("Deferred Command");
                }
                else
                {
                    Console.WriteLine("Place order");
                    msg.Complete();
                }
            }
            Console.WriteLine("Press enter to revieve defered messages");
            Console.ReadLine();
            foreach(var sequenceNumber in deferList)
            {
                var cmd = qc.Receive(sequenceNumber);
                Console.WriteLine("Received command {0}", cmd.Properties["type"]);
                cmd.Complete();
            }
        }
        static void DeadletterForward(Order order)
        {
            if (!nsm.QueueExists(DEADLETTER_FORWARD))
            {
                nsm.CreateQueue(new QueueDescription(DEADLETTER_FORWARD)
                {
                    ForwardDeadLetteredMessagesTo = DUPLICATE_QUEUE,
                    EnableDeadLetteringOnMessageExpiration = true,

                });
            }
            var qc = QueueClient.Create(DEADLETTER_FORWARD);
            qc.Send(new BrokeredMessage(order) { TimeToLive = new TimeSpan(0, 0, 10) });

            var dlc = QueueClient.Create(DUPLICATE_QUEUE);
            var msg = dlc.Receive();
            Console.WriteLine("Received Message from {0}", DUPLICATE_QUEUE);
            msg.Complete();
        }
 static Order CreateOrder()
 {
     var order = new Order()
     {
         CustomerName = "Bob",
         Date = DateTime.Today,
         Items = new List<Item>(){
             new Item() { ItemNumber = "1234", Quantity = 3, UnitCost = 100 }}
     };
     return order;
 }
        static void AutoForward(Order order)
        {
            SetupEntities(SampleScenario.AutoForward);
            //send message to old queue
            order.CustomerName += " On Old Queue";
            var oldqc = QueueClient.Create(FORWARD_QUEUE);
            oldqc.Send(new BrokeredMessage(order));

            //read message from forwarded queue
            var qc = QueueClient.Create(DUPLICATE_QUEUE);
            var msg = qc.Receive();
            if(msg != null)
            {
                var forwardedOrder = msg.GetBody<Order>();
                Console.WriteLine("Received Message for customer: {0}", forwardedOrder.CustomerName);
                msg.Complete();
            }
        }
        static void ActionsOnSubscriptions(Order order)
        {
            SetupEntities(SampleScenario.SubscriptionActions);
            var tc = TopicClient.Create(ACTIONS_TOPIC);
            tc.Send(new BrokeredMessage(order));

            var sc = SubscriptionClient.Create(ACTIONS_TOPIC, ACTIONS_SUBSCRIPTION);
            var msg = sc.Receive();
            Console.WriteLine("Message received with stage = {0}", msg.Properties["stage"]);
            msg.Complete();
        }