public static Pin ToPin(this IAmACommunityMember membro) { var avatar = PegarAvatar(membro); var localizacao = membro.Localizacao; return(new Pin(localizacao, avatar)); }
private async Task <ISyndicationFeedSource> TryLoadFeedAsync(IAmACommunityMember tamarin, Uri uri) { try { var iFilterMyBlogPosts = tamarin as IFilterMyBlogPosts; var filter = iFilterMyBlogPosts != null ? (Func <SyndicationItem, bool>)iFilterMyBlogPosts.Filter : (si => true); var feedSource = new DummyRemoteSyndicationFeedSource(); var feed = await FetchAsync(uri, filter).ConfigureAwait(false); feedSource.Feed = feed; return(feedSource); } catch (Exception ex) { Logger.Error(ex, $"{tamarin.FirstName} {tamarin.LastName}'s feed of {uri} failed to load."); // Not my problem if your feed asplodes but we at least won't crash the app for all the other nice people :) return(null); } }
private static ISyndicationFeedSource TryLoadFeed(IAmACommunityMember tamarin, Uri uri) { try { var iFilterMyBlogPosts = tamarin as IFilterMyBlogPosts; var filter = iFilterMyBlogPosts != null ? (Func <SyndicationItem, bool>)iFilterMyBlogPosts.Filter : (si => true); var feedSource = BlogMonsterBuilder .FromUrl(uri) .WithFilter(filter) .Grr(); var dummy = feedSource.Feed; // poke it to make sure it doesn't go bang. return(feedSource); } catch (Exception ex) { Logger.Error(ex, $"{tamarin.FirstName} {tamarin.LastName}'s feed of {uri} failed to load."); // Not my problem if your feed asplodes but we at least won't crash the app for all the other nice people :) return(null); } }
private async Task <ISyndicationFeedSource> TryLoadFeedAsync(IAmACommunityMember tamarin, Uri uri, bool tryAgain) { try { var feedSource = new DummyRemoteSyndicationFeedSource(); var filter = GetFilterFunction(tamarin); var client = GetHttpClient(); var feed = await FetchAsync(client, uri, filter).ConfigureAwait(false); feed.Language = CultureInfo.CreateSpecificCulture(tamarin.FeedLanguageCode).Name; feedSource.Feed = feed; return(feedSource); } catch (Exception ex) { Logger.Error(ex, $"{tamarin.FirstName} {tamarin.LastName}'s feed of {uri} failed to load."); if (tryAgain) { return(await TryLoadFeedAsync(tamarin, uri, false)); } } // Not my problem if your feed asplodes but we at least won't crash the app for all the other nice people :) return(null); }
private async Task Author_Has_Secure_And_Parseable_Feed(IAmACommunityMember author) { try { foreach (var feedUri in author.FeedUris) { Assert.Equal("https", feedUri.Scheme); } var authors = new[] { author }; var feedSource = new CombinedFeedSource(authors); var allFeeds = await feedSource.LoadAllFeedsAsync(authors).ConfigureAwait(false); Assert.NotNull(allFeeds); var allItems = allFeeds.SelectMany(f => f?.Feed?.Items).Where(i => i != null).ToList(); Assert.True(allItems?.Count > 0, $"Author {author?.FirstName} {author?.LastName} @{author?.GitHubHandle} doesn't meet post policy @{author?.FeedUris?.FirstOrDefault()?.OriginalString}"); } catch (Exception) { Assert.True(false, $"Feed(s) for {author.FirstName} {author.LastName} @{author?.GitHubHandle} is null or empty @{author?.FeedUris?.FirstOrDefault()?.OriginalString}"); _output.WriteLine($"Feed(s) for {author.FirstName} {author.LastName} is null or empty"); if (author is IAmAYoutuber youtuber) { _output.WriteLine("Auhtor is a YouTuber, and will at max have 15 items in feed, ignore empty feed"); return; } throw; } }
async Task Author_Has_Secure_And_Parseable_Feed(IAmACommunityMember author) { try { foreach (var feedUri in author.FeedUris) { Assert.Equal("https", feedUri.Scheme); } var authors = new IAmACommunityMember[] { author }; var feedSource = new CombinedFeedSource(authors); var allFeeds = await feedSource.LoadAllFeedsAsync(authors).ConfigureAwait(false); Assert.NotNull(allFeeds); var allItems = allFeeds.SelectMany(f => f?.Feed?.Items).Where(i => i != null).ToList(); Assert.True(allItems?.Count() > 0); } catch (Exception) { _output.WriteLine($"Feed(s) for {author.FirstName} {author.LastName} is null or empty"); throw; } }
public static Pin ToPin(this IAmACommunityMember membro) { var avatarUri = new Uri($"{Constantes.Gravatar.URL_BASE}{membro.GravatarHash}"); var avatar = ImageSource.FromUri(avatarUri); var localizacao = membro.Localizacao; return(new Pin(localizacao.Latitude, localizacao.Longitude, avatar)); }
private static Func <SyndicationItem, bool> GetFilterFunction(IAmACommunityMember tamarin) { if (tamarin is IFilterMyBlogPosts filterMyBlogPosts) { return(filterMyBlogPosts.Filter); } return(null); }
internal static Func <SyndicationItem, bool> GetFilterFunction(IAmACommunityMember tamarin) { var iFilterMyBlogPosts = tamarin as IFilterMyBlogPosts; var filter = iFilterMyBlogPosts != null ? (Func <SyndicationItem, bool>)iFilterMyBlogPosts.Filter : (si => si.ApplyDefaultFilter()); return(filter); }
private static ImageSource PegarAvatar(IAmACommunityMember membro) { if (string.IsNullOrWhiteSpace(membro.GravatarHash)) { return(null); } var avatarUri = new Uri($"{Constantes.Gravatar.URL_BASE}{membro.GravatarHash}.jpg?s={Constantes.Gravatar.TAMANHO_PADRAO}&d=mm"); var avatar = ImageSource.FromUri(avatarUri); return(avatar); }
private async Task <IEnumerable <SyndicationItem> > TryReadFeed(IAmACommunityMember tamarin, string feedUri, Func <SyndicationItem, bool> filter) { try { return(await retryPolicy.ExecuteAsync(context => ReadFeed(feedUri, filter), new Context(feedUri)).ConfigureAwait(false)); } catch (FeedReadFailedException ex) { Logger.Error(ex, $"{tamarin.FirstName} {tamarin.LastName}'s feed of {ex.Data["FeedUri"]} failed to load."); } return(new SyndicationItem[0]); }
public static string GravatarImage(this IAmACommunityMember member) { const int size = 200; var hash = member.GravatarHash; if (string.IsNullOrWhiteSpace(hash)) { hash = member.EmailAddress.Trim().ToLowerInvariant().ToMd5Hash().ToLowerInvariant(); } var defaultImage = WebUtility.UrlEncode(ConfigurationManager.AppSettings["DefaultGravatarImage"]); return($"//www.gravatar.com/avatar/{hash}.jpg?s={size}&d={defaultImage}"); }
public void Author_Has_Valid_Coordinates(IAmACommunityMember author) { if (author.Position == null) { return; } if (author.Position == GeoPosition.Empty) { return; } Assert.InRange(author.Position.Lat, -90.0, 90); Assert.InRange(author.Position.Lng, -180.0, 180); }
private static ISyndicationFeedSource TryLoadFeed(IAmACommunityMember tamarin, Uri uri) { try { var iFilterMyBlogPosts = tamarin as IFilterMyBlogPosts; var filter = iFilterMyBlogPosts != null ? (Func <SyndicationItem, bool>)iFilterMyBlogPosts.Filter : (si => true); var feedSource = BlogMonsterBuilder .FromUrl(uri) .WithFilter(filter) .Grr(); // Poke it, to see if we can really reach it var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "HEAD"; var response = (HttpWebResponse)request.GetResponse(); // If return code is not success or redirect, it's no good if ((int)response.StatusCode < 200 || (int)response.StatusCode > 399) { throw new Exception("Feed says no"); } return(feedSource); } catch (Exception ex) { Logger.Error(ex, $"{tamarin.FirstName} {tamarin.LastName}'s feed of {uri} failed to load."); // Not my problem if your feed asplodes but we at least won't crash the app for all the other nice people :) return(null); } }
public void Author_Has_Website(IAmACommunityMember author) { Assert.NotNull(author.WebSite); Assert.True(author.WebSite.IsWellFormedOriginalString()); }
public void Author_Has_FirstName(IAmACommunityMember author) { Assert.NotEmpty(author.FirstName); }
public void Author_Specified_Valid_LanguageCode(IAmACommunityMember author) { var cultureNames = CultureInfo.GetCultures(CultureTypes.NeutralCultures).Select(c => c.Name); Assert.Contains(author.FeedLanguageCode, cultureNames); }
private IEnumerable <Task <IEnumerable <SyndicationItem> > > TryReadFeeds(IAmACommunityMember tamarin, Func <SyndicationItem, bool> filter) { return(tamarin.FeedUris.Select(uri => TryReadFeed(tamarin, uri.AbsoluteUri, filter))); }
private bool MatchesAuthorUrls(IAmACommunityMember author, IEnumerable <Uri> urls, SyndicationItem item) { var authorHosts = author.FeedUris.Select(au => au.Host.ToLowerInvariant()).Concat(new[] { author.WebSite.Host.ToLowerInvariant() }).ToArray(); var feedBurnerAuthors = author.FeedUris.Where(au => au.Host.Contains("feeds.feedburner")).ToList(); var mediumAuthors = author.FeedUris.Where(au => au.Host.Contains("medium.com")).ToList(); var youtubeAuthors = author.FeedUris.Where(au => au.Host.Contains("youtube.com")).ToList(); foreach (var itemUrl in urls) { var host = itemUrl.Host.ToLowerInvariant(); if (host.Contains("medium.com")) { if (itemUrl.Segments.Count() >= 3) { var mediumId = itemUrl.Segments[1].Trim('/'); return(mediumAuthors.Any(fba => fba.AbsoluteUri.Contains(mediumId))); } } if (host.Contains("feedproxy.google")) // feed burner is messed up :( { // url will look like: // feedproxy.google.com/~r/<feedburnerId>/~3/bgJNuDXwkU0/O if (itemUrl.Segments.Count() >= 5) { var feedBurnerId = itemUrl.Segments[2].Trim('/'); return(feedBurnerAuthors.Any(fba => fba.AbsoluteUri.Contains(feedBurnerId))); } } if (host.Contains("youtube.com")) //need to match youtube channel { var channel = item?.Authors?.FirstOrDefault()?.Uri; if (channel == null) { return(false); } var id = channel.Replace("https://www.youtube.com/channel/", string.Empty); return(youtubeAuthors.Any(yt => yt.AbsoluteUri.Contains(id))); } if (authorHosts.Contains(host)) { return(true); } if (authorHosts.Contains(host.Replace("www.", ""))) { return(true); } if (authorHosts.Contains(host.Insert(0, "www."))) { return(true); } } return(false); }
private Task <ISyndicationFeedSource> TryLoadFeedAsync(IAmACommunityMember tamarin, Uri uri) => TryLoadFeedAsync(tamarin, uri, true);
public void Author_Has_Website(IAmACommunityMember author) { Assert.NotNull(author.WebSite); }