Пример #1
0
        public static string Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log,
            IDateTimeResolver dateTimeResolver)
        {
            var date = dateTimeResolver.Get();

            if (date.Hour >= 5)
            {
                if (date.Hour < 12)
                {
                    return("morning");
                }

                if (date.Hour < 17)
                {
                    return("afternoon");
                }

                if (date.Hour < 21)
                {
                    return("evening");
                }
            }

            return("night");
        }
Пример #2
0
        public static async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] string logContent,
            [CosmosDB(databaseName: "functionTest",
                      collectionName: "nightLogs",
                      CreateIfNotExists = true,
                      CollectionThroughput = 400,
                      ConnectionStringSetting = "CosmosDBConnectionString")]
            IAsyncCollector <LogDocument> output,
            IDateTimeResolver dateTimeResolver,
            ILogger log)
        {
            var date = dateTimeResolver.Get();

            // only log what happens during the night
            if (date.Hour >= 21 || date.Hour < 5)
            {
                await output.AddAsync(new LogDocument { Log = logContent });
            }

            return(new OkResult());
        }