Exemple #1
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = RouteName)]
            HttpRequestMessage req,
            TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            var hit = await req.Content.ReadAsAsync <Hit>();

            var summaryApiUrl           = ConfigurationManager.AppSettings["SummaryApiUrl"];
            var summaryApiKey           = ConfigurationManager.AppSettings["SummaryApiKey"];
            var storageConnectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            var summaryService = new SummaryService(summaryApiUrl, summaryApiKey);
            var summary        = summaryService.GetSummaryForHit(hit);

            var repo    = new ArticleEntityRepo(storageConnectionString);
            var article = new ArticleEntity(Guid.NewGuid(), hit.Title, hit.Url, summary);

            repo.SaveArticle(article);

            await req.InvokeAzureFunction($"TextToSpeech/id/{article.PartitionKey}/title/{article.RowKey}", RouteName);

            return(req.CreateResponse(HttpStatusCode.OK, summary));
        }