Exemplo n.º 1
0
        public static async Task <IActionResult> Read(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "host/{ip}")]
            HttpRequest req, string ip, [DurableClient] IDurableEntityClient client, ILogger logger)
        {
            try
            {
                IPAddress.Parse(ip);
            }
            catch
            {
                return(new BadRequestResult());
            }

            var entity = await client.ReadEntityStateAsync <HostEntity>(HostEntity.Id(ip));

            if (!entity.EntityExists)
            {
                return(new NotFoundResult());
            }

            return(new OkObjectResult(new
            {
                uptime = entity.EntityState.DnsUptime * 100m + "%", ipAddress = entity.EntityState.IpAddress,
                monitoringSince = entity.EntityState.MonitoringSince, ARecords = entity.EntityState.ipv4Support,
                isRecursive = true, isHandshake = (bool?)null
            }));
        }
Exemplo n.º 2
0
        public static async Task <IActionResult> Create(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "host/{ip}")]
            HttpRequest req,
            string ip,
            [DurableClient] IDurableEntityClient client,
            ILogger log)
        {
            try
            {
                IPAddress.Parse(ip);
            }
            catch
            {
                return(new BadRequestObjectResult(new { error = "Invalid ip address" }));
            }

            log.LogInformation("Adding {ipAddress} to bucket", ip);

            await client.SignalEntityAsync <IHostEntity>(HostEntity.Id(ip), entity => entity.SetIp(ip));

            await client.SignalEntityAsync <IHostEntity>(HostEntity.Id(ip),
                                                         entity => entity.CheckUp());

            return(new OkResult());
        }