コード例 #1
0
        /// <summary>
        /// Get raw file.
        /// </summary>
        /// <param name="url">The url.</param>
        /// <returns>Task for getting raw file.</returns>
        public async Task <string> GetRawFile(string url)
        {
            TryGetETAGAndCacheValue(url, out string etag, out object cachedValue, out bool isEntryInCache);

            List <KeyValuePair <string, string> > additionalHeaders = new List <KeyValuePair <string, string> >();

            additionalHeaders.Add(new KeyValuePair <string, string>("Accept", GithubConstants.RawFileHeaderMediaType));
            HttpResponseMessage response = await GetInternal(url, etag, additionalHeaders);

            if (response.StatusCode == HttpStatusCode.NotModified)
            {
                if (isEntryInCache)
                {
                    return(cachedValue.ToString());
                }

                throw new Exception($"url content not found in cache : {url}");

                // TODO : If entry is not in cache for some reason, we need to fetch it again from github without etag header to refresh the cache
            }

            response.EnsureSuccessStatusCode();
            cachedValue = await response.Content.ReadAsStringAsync();

            etag = GetHeaderValue(response, "ETag").Replace("W/", string.Empty);
            Tuple <string, object> cachedInfo = new Tuple <string, object>(etag, cachedValue);

            GitHubCache.AddOrUpdate(url, cachedInfo, (key, oldvalue) => cachedInfo);

            return(cachedValue.ToString());
        }
コード例 #2
0
        private void TryGetETAGAndCacheValue(string url, out string etag, out object cachedValue, out bool isEntryInCache)
        {
            etag           = string.Empty;
            cachedValue    = null;
            isEntryInCache = GitHubCache.TryGetValue(url, out Tuple <string, object> cachedInfo);

            if (isEntryInCache)
            {
                etag        = cachedInfo.Item1;
                cachedValue = cachedInfo.Item2;
            }
        }
コード例 #3
0
ファイル: StatusReport.cs プロジェクト: anurse/AspNetReports
        public static async Task <StatusReportModel> GenerateReportModelAsync(GitHubClient github, DataStore data, Data.Team team, string milestone, DateTime startDate, DateTime endDate, ILoggerFactory loggerFactory)
        {
            var logger = loggerFactory.CreateLogger <StatusReport>();
            var model  = new StatusReportModel();

            model.Name       = team.Name;
            model.ReportDate = endDate.ToString("yyyy-MM-dd");

            var cache = new GitHubCache(github, data, loggerFactory.CreateLogger <GitHubCache>());

            // Establish the time window. Exclude the endDate.
            var range = new DateRange(startDate, endDate.AddDays(-1));

            logger.LogInformation("Using date range {Range}", range);

            var releaseMilestone = data.GetMilestone(milestone);

            model.Milestone = new List <MilestoneDates>()
            {
                ComputeMilestoneDates(data, endDate, releaseMilestone, logger)
            };

            var repos = new RepositoryCollection();

            foreach (var repo in data.Organization.Repositories)
            {
                repos.Add(repo.Owner, repo.Name);
            }

            await GeneratePullRequestInfoAsync(github, data, team, model, cache, range, repos, logger);
            await GenerateIssueInfoAsync(github, team, repos, milestone, model, logger);

            // Try to render burndown data
            var burndown = await data.LoadBurndownAsync(milestone);

            // Check for burndown data for the end date
            if (!burndown.Weeks.Any(w => w.EndDate.Year == endDate.Year && w.EndDate.Month == endDate.Month && w.EndDate.Day == endDate.Day))
            {
                logger.LogWarning("No burndown data is associated with today's date! The burndown data in this report may be out-of-date.");
            }

            model.Burndown = GenerateBurndownModel(team, burndown);

            return(model);
        }