Ejemplo n.º 1
0
        protected async Task <JObject> PerformPassthroughRequest(AlexaSmartHomeRequest request, Configuration config, ILambdaContext lambdaContext)
        {
            var client = new PubSubClient(config, lambdaContext);

            Log.Debug(lambdaContext, "Starting passthrough...");
            var     sw       = Stopwatch.StartNew();
            JObject response = await client.RequestBridgePassthrough(Meta.AloxiMessageOperation.PipeAlexaRequest, JObject.FromObject(request, this.json));

            sw.Stop();

            if (response == null)
            {
                Log.Warn(lambdaContext, $"Passthrough completed in {sw.Elapsed.TotalSeconds}s without result");
            }
            else
            {
                Log.Info(lambdaContext, $"Successful passthrough, took {sw.Elapsed.TotalSeconds}s");
            }
            return(response);
        }
Ejemplo n.º 2
0
        private async Task <JObject> PerformEchoRequest(JObject payload, Configuration config, ILambdaContext lambdaContext)
        {
            var client = new PubSubClient(config, lambdaContext);

            var         sw           = Stopwatch.StartNew();
            EchoPayload outgoingEcho = new EchoPayload()
            {
                Salt = Guid.NewGuid().ToString()
            };
            EchoPayload response = await client.RequestBridge <EchoPayload>(AloxiMessageOperation.Echo, outgoingEcho);

            sw.Stop();

            if (!(response?.Salt == outgoingEcho.Salt))
            {
                throw new Exception("Echo response invalid");
            }

            Log.Info(lambdaContext, $"Successful echo, took {sw.Elapsed.TotalSeconds}s");
            return(CreateResponse(new { Message = "Echo fine", DurationInSeconds = sw.Elapsed.TotalSeconds, Salt = response.Salt }));
        }