public static async Task <Models.Contribution> GetContributionAsync(string Branch, string Endpoint) { var url = $"https://github.com/{Startup.Config["Organization"]}/{Startup.Config["Repository"]}/contributors/{Branch}/{Startup.Config["RootPath"]}/{Endpoint}"; if (!CachedContributor.ContainsKey(url) || DateTime.Now > CachedContributor[url].Key) { using (var client = new HttpClient { BaseAddress = GitHubUri }) { client.Timeout = new TimeSpan(0, 1, 0); var responseMessage = await client.GetAsync(url); var html = await responseMessage.Content.ReadAsStringAsync(); var ret = new Models.Contribution(); foreach (Match x in ContributorAnchorRegex.Matches(html)) { try { var key = ContributorNameRegex.Match(x.Value).Value; var value = ContributorAvatarRegex.Match(x.Value).Value; ret.Contributors.Add(key, value); } catch { } } try { ret.LastUpdate = Convert.ToDateTime(ContributorLastUpdateRegex.Match(html).Value); } catch { } if (ret.Contributors.Count == 0) { try { var match = SingleContributorNameRegex.Match(html); if (match.Success) { ret.Contributors.Add(match.Value, SingleContributorAvatarRegex.Match(html).Value); } } catch { } } if (CachedContributor.ContainsKey(url)) { CachedContributor[url] = new KeyValuePair <DateTime, Models.Contribution>(DateTime.Now.AddMinutes(Convert.ToInt32(Startup.Config["Caching"])), ret); } else { CachedContributor.Add(url, new KeyValuePair <DateTime, Models.Contribution>(DateTime.Now.AddMinutes(Convert.ToInt32(Startup.Config["Caching"])), ret)); } } } return(CachedContributor[url].Value); }
public Domain.Contribution Save(Domain.Contribution obj) { var contributionDb = new Models.Contribution { Contribution1 = obj.ContributionValue, ContributorId = obj.ContributorId, Message = obj.Message, PackageId = obj.PackageId }; context.Contribution.Add(contributionDb); context.SaveChanges(); obj.Id = contributionDb.Id; return(obj); }