Пример #1
0
        public ActionResult Index(string productId, string socketId)
        {
            ActionResult result = null;

            bool bought = MvcApplication.ProductRepository.Buy(productId);
            var  model  = MvcApplication.ProductRepository.GetProductById(productId);

            if (bought)
            {
                ViewBag.Info = model.Title + " successfully bought";

                var stockEvent = new StockUpdatedEvent(model, socketId);
                ObjectPusherRequest request = new ObjectPusherRequest("presence-" + stockEvent.ProductId, "stockUpdated", stockEvent);
                _provider.Trigger(request);
            }
            else
            {
                ViewBag.Error = "There was a problem buying " + model.Title;
            }

            if (socketId != null)
            {
                result = GetBoughtStatusCode(bought);
            }
            else
            {
                result = View("Index", model);
            }
            return(result);
        }
        public void CanTriggerPushWithAnonymousObject()
        {
            SetupDefaultProvider();
            var request = new ObjectPusherRequest("test_channel", "my_event", new
            {
                some = "data"
            });

            _defaultProvider.Trigger(request);
        }
Пример #3
0
        public void CanTriggerPushWithAnonymousObject()
        {
            SetupDefaultProvider();
            var request = new ObjectPusherRequest("test_channel", "my_event", new
                                                                              	{
                                                                              		some = "data"
                                                                              	});

            _defaultProvider.Trigger(request);
        }
Пример #4
0
        public ActionResult Index(string chatMessage, string username)
        {
            var now     = DateTime.UtcNow;
            var request = new ObjectPusherRequest(
                "chat_channel",
                "message_received",
                new
            {
                message   = chatMessage,
                user      = username,
                timestamp = now.ToShortDateString() + " " + now.ToShortTimeString()
            });

            Provider.Trigger(request);
            return(View());
        }
Пример #5
0
        public ActionResult PrivateMessage(string chatMessage, string username, string ChannelName)
        {
            var now = DateTime.UtcNow;
            ObjectPusherRequest request = new ObjectPusherRequest(
                ChannelName,
                "message_received",
                new
            {
                message   = chatMessage,
                user      = username,
                timestamp = now.ToShortDateString() + " " + now.ToShortTimeString()
            });

            // var socketID =HttpContext.Request["socket_id"].ToString();
            //  Provider.Authenticate("presence-channel",request.SocketId.ToString());
            Provider.Trigger(request);

            return(View());
        }
Пример #6
0
        public void SerializesObjectToJsonData()
        {
            var request = new ObjectPusherRequest("test_channel", "my_event", new { some = "data" });

            Assert.That(request.JsonData, Is.EqualTo(@"{""some"":""data""}"));
        }
        public void SerializesObjectToJsonData()
        {
            var request = new ObjectPusherRequest("test_channel", "my_event", new { some = "data" });

            Assert.That(request.JsonData, Is.EqualTo(@"{""some"":""data""}"));
        }