コード例 #1
0
    public static async Task <IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        [Table("FunctionExecutions", Connection = "StorageConnectionString")] CloudTable table,
        ExecutionContext executionContext,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        // query table storage for all entries (you might want to restrict the query to the last day etc)
        TableQuery <FunctionExecution>        query = new TableQuery <FunctionExecution>();
        TableQuerySegment <FunctionExecution> data  = await table.ExecuteQuerySegmentedAsync(query, null);

        // get the last function execution by ordering by Timestamp
        FunctionExecution lastFunctionExecution = data.OrderByDescending(r => r.Timestamp).FirstOrDefault();

        DateTimeOffset?begin = lastFunctionExecution?.Timestamp;
        DateTime       end   = DateTime.UtcNow;

        // call off to ThirdPartyClient

        // log successful execution to table storage
        TableOperation insertOperation = TableOperation.Insert(new FunctionExecution
        {
            PartitionKey = executionContext.InvocationId.ToString(), // using the InvocationId of the function so you can relate executions if needed
            RowKey       = Guid.NewGuid().ToString(),
            Timestamp    = DateTimeOffset.UtcNow,                    // set the Timestamp to now as the function has been successful
            FunctionName = "HttpTriggeredFunction"                   // optional but you might want to save the function name in your case FunctionNames.GetInvoicesAsync
        });

        await table.ExecuteAsync(insertOperation);

        return(new OkObjectResult(null));
    }
コード例 #2
0
        public async Task <IActionResult> Get()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
            CloudTable          table          = tableClient.GetTableReference("WADDefaultdb3ba641747eb813502418838b19ad46");

            var query = new TableQuery <LogRecord>()
                        .Where(
                TableQuery.GenerateFilterConditionForDate("PreciseTimeStamp", QueryComparisons.GreaterThanOrEqual, new DateTimeOffset(DateTime.UtcNow.AddHours(-2)))
                );

            TableQuerySegment <LogRecord> queryResult = await table.ExecuteQuerySegmentedAsync(query, null);

            var result = queryResult.OrderByDescending(l => l.PreciseTimeStamp).Take(100).ToList()
                         .Select(l => new { Details = l.Message, EventMessage = l.EventMessage, TimeStamp = l.PreciseTimeStamp, Id = l.GetHashCode() });

            return(Json(result));
        }