Ejemplo n.º 1
0
        public string CommandWaitPolling(string deviceId, int timeout)
        {
            RabbitQueue rabbit = new RabbitQueue();
            TimerCallback tm = Count;

            JsonStrings.Add(deviceId, rabbit.Consumer(deviceId));
            Connections.Add(deviceId);
            var timer = new Timer(tm, deviceId, timeout, timeout);
            while (JsonStrings[deviceId] == null)
            {
                // loop
            }
            timer.Dispose();
            Connections.Remove(deviceId);
            return "";
        }
Ejemplo n.º 2
0
        public ActionResult Index(string deviceId, string command)
        {
            RabbitQueue rabbit = new RabbitQueue();
            CommandValidation validation = new CommandValidation();

            if (validation.Validation(command))
            {
                rabbit.Producer(deviceId, command);
                rabbit.CreateTimeout(deviceId);
                if (LongPolling.Connections.Contains(deviceId))
                    LongPolling.JsonStrings[deviceId] = (rabbit.Consumer(deviceId));
            }
            else
            {
                return new HttpStatusCodeResult(400, "Validation error");
            }
            return new HttpStatusCodeResult(202, "Accepted");
        }