예제 #1
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log,
            ExecutionContext context)
        {
            var reportedUrlRow = new ReportedUrl
            {
                PartitionKey = "reportedUrl",
                RowKey       = Guid.NewGuid().ToString(),
                Url          = req.Query["url"]
            };

            Config config = new ConfigBuilder(context.FunctionAppDirectory).Build();

            await SaveReportedUrl(reportedUrlRow, config.StorageConnectionString);

            log.LogInformation($"Reported url: {reportedUrlRow.Url}");

            return(new HtmlResponseMessage(
                       HttpStatusCode.OK,
                       $@"<html>
                <head>
                    <meta charset=""UTF-8"">
                    <title>Article reported</title>
                </head>
                <body>
                    <h1>Thank you for submiting that article!</h1>
                    <p>We'll investigate {reportedUrlRow.Url} soon.</p>
                </body>
                </html>"));
        }
예제 #2
0
        private static async Task SaveReportedUrl(ReportedUrl reportedUrlRow, string storageConnectionString)
        {
            var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
            var tableClient    = storageAccount.CreateCloudTableClient();
            var cloudTable     = tableClient.GetTableReference("ReportedUrls");
            await cloudTable.CreateIfNotExistsAsync();

            var insertOperation = TableOperation.Insert(reportedUrlRow);
            await cloudTable.ExecuteAsync(insertOperation);
        }