Ejemplo n.º 1
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "list")]
            HttpRequestMessage req,
            TraceWriter log
            )
        {
            var repo = new RaspberryPiRepository();

            var list = await repo.GetAll();

            var list2 = new List <ListResponse>();

            foreach (var result in list)
            {
                list2.Add(new ListResponse
                {
                    Id             = result.Id,
                    Name           = result.Name,
                    GotoUrl        = Utils.ParseUri(result.GotoUrl),
                    Hostname       = result.Hostname,
                    SerialNumber   = result.SerialNumber,
                    PostCommandUrl = new Uri(req.RequestUri, $"/api/tv/{result.Id}/commands"),
                });
            }

            return(req.CreateResponse <Result <List <ListResponse> > >(list2));
        }
Ejemplo n.º 2
0
        public static async Task Run(
            [TimerTrigger("0 29 9 * * 1-5")]
            TimerInfo myTimer,
            TraceWriter log
            )
        {
            var repo = new RaspberryPiRepository();

            var list = await repo.GetAll();

            foreach (var pi in list)
            {
                var queue = Storage.GetCommandQueueReference(pi.Id);

                if (!string.IsNullOrEmpty(pi.GotoUrl))
                {
                    Uri gotoUrl;
                    if (Uri.TryCreate(pi.GotoUrl, UriKind.Absolute, out gotoUrl))
                    {
                        await queue.AddCommandAsync(new GotoCommand { Url = gotoUrl });

                        continue;
                    }
                }
                else if (!string.IsNullOrEmpty(pi.Command))
                {
                    await queue.AddCommandAsync(new PuppeteerCommand { Commands = JArray.Parse(pi.Command) });

                    continue;
                }

                await queue.AddCommandAsync(new GotoCommand { Url = new Uri("splash:") });
            }
        }