public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "refreshfromgithubyaml")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("RefreshFromGithubYaml(): Received request");

            using StreamReader reader = new StreamReader(req.Body);
            try
            {
                string requestBody = reader.ReadToEnd();
                var    repo        = JsonConvert.DeserializeObject <RepositoryEntity>(requestBody);

                var yamlData = await GithubExpertsData.GetTutorYamlAsync(repo.Repository);

                await ExpertData.UpsertExpertsAsync(yamlData.Experts, repo.Repository);

                return(new OkResult());
            }
            catch (JsonSerializationException ex)
            {
                log.LogError(string.Format("RefreshFromGithubYaml(): JsonSerializationException occurred {0}:{1}", ex.Message, ex.InnerException));
                return(new BadRequestObjectResult(ex.Message));
            }
            catch (StorageException ex)
            {
                log.LogError(string.Format("RefreshFromGithubYaml(): StorageException occurred {0}:{1}", ex.Message, ex.InnerException));
                return(new BadRequestObjectResult(ex.Message));
            }
            catch (Exception ex)
            {
                log.LogError(string.Format("RefreshFromGithubYaml(): Exception occurred {0}:{1}", ex.Message, ex.InnerException));
                return(new InternalServerErrorResult());
            }
        }
Пример #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "experts/{repo}")] HttpRequest req,
            string repo,
            ILogger log)
        {
            GithubExperts yamlData = null;

            log.LogInformation("Experts(): Received request");

            var result = await ExpertData.GetExpertsAsync(repo);

            // If no results, we might not have data for this repo yet...try and get it.
            if (result.Count == 0)
            {
                try
                {
                    yamlData = await GithubExpertsData.GetTutorYamlAsync(repo.Replace("+", "/"));

                    if (yamlData != null)
                    {
                        await ExpertData.UpsertExpertsAsync(yamlData.Experts, repo);

                        result = yamlData.Experts;
                    }
                }
                catch (Exception ex)
                {
                    log.LogError(string.Format("Experts(): Exception occurred {0}:{1}", ex.Message, ex.InnerException));
                    return(new InternalServerErrorResult());
                }
            }

            return(new OkObjectResult(result));
        }