public async Task <Either <DomainError, ImmutableList <AnimeInfo> > > GetLibrary() { try { var web = new HtmlWeb(); var doc = await web.LoadFromWebAsync(AniChartLibrary); var seasonInfoString = HttpUtility.HtmlDecode(GetInnerTextOrEmpty(doc.DocumentNode, "//h1[@class='calendar']")); var(season, year, yearStr) = GetSeasonInformation(seasonInfoString); var feeTitles = await GetFeedTitles(); return(doc.DocumentNode .SelectNodes("//div[contains(@class,'g_bubblewrap') and contains(@class,'container')]/div[contains(@class,'g_bubble') and contains(@class,'box')]") .Select(n => MapFromCard(n, yearStr)) .Select(aic => new AnimeInfo( NonEmptyString.FromString(IdHelpers.GenerateAnimeId(season.Value, yearStr, aic.Title)), NonEmptyString.FromString(aic.Title), NonEmptyString.FromString(aic.Synopsis), NonEmptyString.FromString(Helpers.TryGetFeedTitle(feeTitles, aic.Title)), new SeasonInformation(season, year), aic.Date, false)) .ToImmutableList()); } catch (Exception e) { return(ExceptionError.FromException(e, "AnichartLibrary")); } }
public Task <Either <DomainError, IEnumerable <AnimeInfoWithImageStorage> > > GetBySeason(Season season, int year) { var partitionKey = IdHelpers.GenerateAnimePartitionKey(season, (ushort)year); var tableQuery = new TableQuery <AnimeInfoWithImageStorage>(). Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey)); return(TableUtils.TryExecuteSimpleQuery(() => _tableClient.ExecuteQuerySegmentedAsync(tableQuery, null))); }
public IDiff <TType> Compute(TType @base, TType changed) { if (this.aIsTheSame == null) { this.aIsTheSame = IdHelpers.CompileIsTheSame <TItemType>(this.aIDProperty); this.aItemDiff = this.aMergerImplementation.Partial.Algorithms.GetDiffAlgorithm <TItemType>(); this.aItemComparer = EqualityComparer <TItemType> .Default; } return(this.ComputeInternal((IEnumerable <TItemType>)@base, (IEnumerable <TItemType>)changed)); }
public TType Apply(TType source, IDiff <TType> patch) { if (this.aIdAccessor == null) { this.aIdAccessor = IdHelpers.CreateIdAccessor <TItemType, TIdType>(this.aIdProperty); this.aApplyItemDiff = this.aMergerImplementation.Partial.Algorithms.GetApplyPatchAlgorithm <TItemType>(); this.aConvertor = this.CompileConvertor(); } return(this.ApplyInternal((IEnumerable <TItemType>)source, patch)); }
private static BlobImageInfo CreateDomainInformation(ImageInfo imageInfo, Season season, int year) { var title = imageInfo.Title ?? string.Empty; var partition = IdHelpers.GenerateAnimePartitionKey(season, (ushort)year); var id = IdHelpers.GenerateAnimeId(season.ToString(), year.ToString(), title); var directory = $"{year.ToString()}/{season.Value}"; var blobName = IdHelpers.CleanAndFormatAnimeTitle(title); return(new BlobImageInfo(partition, id, directory, blobName, imageInfo.Url ?? string.Empty)); }
public IDiff <TType> MergeDiffs(IDiff <TType> left, IDiff <TType> right, IConflictContainer conflicts) { if (this.aIdAccessor == null) { if (this.aIdProperty == null) { ParameterExpression obj = Expression.Parameter(typeof(TItemType), "obj"); Expression <Func <TItemType, TIdType> > identityFunction = Expression.Lambda <Func <TItemType, TIdType> >( obj, obj ); this.aIdAccessor = identityFunction.Compile(); } else { this.aIdAccessor = IdHelpers.CreateIdAccessor <TItemType, TIdType>(this.aIdProperty); } this.aMergeItemsDiffs = this.aMergerImplementation.Partial.Algorithms.GetMergeDiffsAlgorithm <TItemType>(); } Dictionary <TIdType, IDiffUnorderedCollectionItem> rightIndex = new Dictionary <TIdType, IDiffUnorderedCollectionItem>(right.Count); foreach (IDiffItem item in right) { rightIndex[this.GetID(item)] = (IDiffUnorderedCollectionItem)item; } List <IDiffItem> ret = new List <IDiffItem>(left.Count + right.Count); foreach (var leftItem in left.Cast <IDiffUnorderedCollectionItem>()) { IDiffUnorderedCollectionItem rightItem; TIdType id = this.GetID(leftItem); if (rightIndex.TryGetValue(id, out rightItem)) { rightIndex.Remove(id); this.ProcessConflict(id, leftItem, rightItem, ret, conflicts); } else { ret.Add(leftItem); } } ret.AddRange(rightIndex.Values); return(new Diff <TType>(ret)); }
public async Task <ActionResult <ClubInfo> > GetByID(string id) { if (!IdHelpers.IsValid(id)) { return(BadRequest(new { message = "Invalid club number" })); //NotFound()? } string formattedId = IdHelpers.FormatId(id); var clubResp = await _entityService.ClubReqHandler(formattedId); if (!clubResp.Info.Exists) { return(BadRequest(new { message = "Club does not exist" })); } return(clubResp); }
internal static AnimeInfoStorage ProjectToStorageModel(AnimeInfo source) { var year = OptionUtils.UnpackOption <ushort>(source.SeasonInformation.Year.Value, 0); return(new AnimeInfoStorage { RowKey = OptionUtils.UnpackOption(source.Id.Value, string.Empty), PartitionKey = IdHelpers.GenerateAnimePartitionKey(source.SeasonInformation.Season, year), Season = source.SeasonInformation.Season.Value, Year = year, Synopsis = OptionUtils.UnpackOption(source.Synopsis.Value, string.Empty), FeedTitle = OptionUtils.UnpackOption(source.FeedTitle.Value, string.Empty), Date = MapDate(source.Date), Title = OptionUtils.UnpackOption(source.Title.Value, string.Empty), Completed = source.Completed }); }
public async Task <Either <DomainError, ImmutableList <AnimeInfo> > > GetLibrary() { try { var web = new HtmlWeb(); var doc = web.Load(LiveChartLibrary); var seasonInfoString = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//h1").InnerText); var(season, year) = GetSeasonInformation(seasonInfoString); var yearStr = OptionUtils.UnpackOption(year.Value, (ushort)DateTime.Today.Year).ToString(); var feeTitles = await GetFeedTitles(); var results = await Task.WhenAll(doc.DocumentNode .SelectNodes("//main[@class='chart']/article[@class='anime']/div[@class='anime-card']") .AsParallel() .Where(FilterLeftover) .Select(async x => await MapFromCard(x)) .Select(x => new AnimeInfo( NonEmptyString.FromString(IdHelpers.GenerateAnimeId(season.Value, yearStr, x.Item1)), NonEmptyString.FromString(x.Item1), NonEmptyString.FromString(x.Item2), NonEmptyString.FromString(Helpers.TryGetFeedTitle(feeTitles, x.Item1)), new SeasonInformation(season, year), x.Item3, false))); return(results.ToImmutableList()); } catch (Exception e) { return(ExceptionError.FromException(e, "Library")); } }