public async Task Get(Guid id)
        {
            Response.Headers.Add("Content-Type", "text/event-stream");

            _smartEventHubConsumer.RegisterEventQueue(id);

            var model = new TailCommandProcessorModel();

            model.WebRootPath = _environment.WebRootPath;

            //Send an empty table back for initial display
            await RenderCommandProcessorTableAndReturnResponse(this, model, Response).ConfigureAwait(false);

            //5 minute timeout ensures that if an incorrect or out of date GUID is used that this Get function doesn't run forever
            foreach (var commandResult in _smartEventHubConsumer.GetEvents <CommandResult>(id, TimeSpan.FromMinutes(5)))
            {
                model.CommandResults.Add(commandResult);
                await RenderCommandProcessorTableAndReturnResponse(this, model, Response).ConfigureAwait(false);
            }

            model.Completed = true;
            await RenderCommandProcessorTableAndReturnResponse(this, model, Response).ConfigureAwait(false);

            _smartEventHubConsumer.DeregisterEventQueue(id);
        }
Exemple #2
0
        public void GivenJsonThetGetsTVPowerState_WhenCommandDispatcherDispatch_ThenPowerStateMatches()
        {
            using (StreamReader r = new StreamReader(@".\TestAssets\command-processor-get-tv-power-state.json"))
            {
                string json = r.ReadToEnd();

                //Firstly, get the current TV power status directly from the TV device
                PowerStatus?powerStatusDirect = _tvDevice.GetPowerStatus();

                //Secondly, get the current TV power via a command processor json
                Guid id     = Guid.NewGuid();
                bool result = _smartEventHubConsumer.RegisterEventQueue(id);

                _cd.Dispatch(json, id);
                var         commandResult = _smartEventHubConsumer.GetEvents <CommandResult>(id).First();
                PowerStatus?powerStatusCommandDispatcher = commandResult.Result == null ? (PowerStatus?)null : (PowerStatus)(long)commandResult.Result;

                Assert.NotNull(powerStatusDirect);
                Assert.NotNull(powerStatusCommandDispatcher);
                Assert.AreEqual(powerStatusDirect, powerStatusCommandDispatcher);

                _smartEventHubConsumer.DeregisterEventQueue(id);
            }
        }