public Either <DomainError, ImmutableList <FeedInfo> > GetFeed(Resolution resolution)
        {
            try
            {
                var sources = new List <LinkType> {
                    LinkType.TorrentFile, LinkType.Magnet
                }
                .SelectMany(type => GetFeedInformation(Resolution.Hd, type))
                .Where(f => f.PublicationDate >= DateTime.Today)
                .GroupBy(i => i.AnimeTitle);

                var resultList =
                    from source in sources
                    let links = source.Select(x => new TorrentLink(x.Type, x.Link)).ToImmutableList()
                                let baseElement = source.First()
                                                  select new FeedInfo(
                        NonEmptyString.FromString(baseElement.AnimeTitle),
                        NonEmptyString.FromString(baseElement.FeedTitle),
                        baseElement.PublicationDate,
                        links,
                        baseElement.EpisodeInfo);
                return(resultList.ToImmutableList());
            }
            catch (Exception e)
            {
                return(Left <DomainError, ImmutableList <FeedInfo> >(
                           ExceptionError.FromException(e, $"Erai_Feed_Exception")));
            }
        }
示例#2
0
        private Either <DomainError, IImmutableList <string> > Mapper(IEnumerable <TitlesStorage> source)
        {
            try
            {
                if (!source.Any())
                {
                    return(ImmutableList <string> .Empty);
                }
                var item = source.Single();
                if (item == null || string.IsNullOrWhiteSpace(item.Titles))
                {
                    return(BasicError.Create(nameof(FeedTitlesRepository), "Title source contains more than one record"));
                }

                return(item
                       .Titles
                       .Split(',')
                       .Select(x => x.Trim())
                       .ToImmutableList());
            }
            catch (Exception e)
            {
                return(ExceptionError.FromException(e));
            }
        }
        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"));
            }
        }
示例#4
0
        internal static async Task <Either <DomainError, Unit> > BatchDelete <T>(CloudTable tableClient, IImmutableList <T> entities) where T : TableEntity
        {
            try
            {
                var offset = 0;
                while (offset < entities.Count)
                {
                    var batch = new TableBatchOperation();
                    var rows  = entities.Skip(offset).Take(100).ToList();
                    foreach (var row in rows)
                    {
                        batch.Delete(row);
                    }

                    await tableClient.ExecuteBatchAsync(batch);

                    offset += rows.Count;
                }

                return(Right(unit));
            }
            catch (Exception e)
            {
                return(Left <DomainError, Unit>(ExceptionError.FromException(e, "BatchDelete")));
            }
        }
示例#5
0
 internal static async Task <Either <DomainError, T> > TryExecute <T>(Func <Task <T> > action)
 {
     try
     {
         return(await action());
     }
     catch (Exception e)
     {
         return(e.Message == "Not Found" ?
                Left <DomainError, T>(NotFoundError.Create("TableOperation", "The entity was not found")) :
                Left <DomainError, T>(ExceptionError.FromException(e, "TableOperation")));
     }
 }
示例#6
0
        internal static async Task <Either <DomainError, IEnumerable <T> > > TryExecuteSimpleQuery <T>(
            Func <Task <TableQuerySegment <T> > > query) where T : TableEntity
        {
            try
            {
                var result = await query();

                return(Right <DomainError, IEnumerable <T> >(result.Results.AsEnumerable()));
            }
            catch (Exception e)
            {
                return(Left <DomainError, IEnumerable <T> >(ExceptionError.FromException(e, "TableQuery")));
            }
        }
示例#7
0
        internal static async Task <Either <DomainError, IImmutableList <T> > > TryGetAllTableElements <T>(CloudTable client, TableQuery <T> tableQuery) where T : TableEntity, new()
        {
            try
            {
                TableContinuationToken?token;
                var resultList = ImmutableList <T> .Empty;
                do
                {
                    var result = await client.ExecuteQuerySegmentedAsync(tableQuery, null);

                    resultList = resultList.AddRange(result.Results.AsEnumerable());
                    token      = result.ContinuationToken;
                } while (token != null);


                return(Right <DomainError, IImmutableList <T> >(resultList));
            }
            catch (Exception e)
            {
                return(Left <DomainError, IImmutableList <T> >(ExceptionError.FromException(e, "TableQuery")));
            }
        }
        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"));
            }
        }