internal GraphQuery FullAnimeQuery(int anilistMediaId)
        {
            _builder = new MediaQueryBuilder();

            _builder.AddArgument(_builder.MediaQueryArguments.IdQueryArgument(anilistMediaId));
            _builder.AddArgument(_builder.MediaQueryArguments.TypeArgument(MediaType.Anime));

            FullAnimeFields();

            return(_builder.BuildQuery());
        }
Beispiel #2
0
        public async Task <IEnumerable <MediaItem> > ListAsync(int Page = 1, int PerPage = 20, string Filter = "", int[] Include = null, DataSource DataSource = DataSource.Cloud)
        {
            IEnumerable <MediaItem> mediaitems = null;

            Filter = Filter.ToLower();

            if (DataSource == DataSource.Cloud)
            {
                MediaQueryBuilder QueryBuilder = new MediaQueryBuilder {
                    Page = Page, PerPage = PerPage, Search = Filter.ToLower(), Include = Include
                };

                mediaitems = await Query(QueryBuilder);

                if (mediaitems != null)
                {
                    foreach (var mediaitem in mediaitems)
                    {
                        var LocalMedia = LocalMediaItems.FirstOrDefault(p => p.Id == mediaitem.Id);
                        if (LocalMedia is MediaItem)
                        {
                            LocalMediaItems.Remove(LocalMedia);
                            LocalMediaItems.Add(mediaitem);
                        }
                        else
                        {
                            LocalMediaItems.Add(mediaitem);
                        }
                    }

                    try { File.WriteAllText(_cachedPath, JsonConvert.SerializeObject(LocalMediaItems)); } catch { }
                }
            }
            else
            {
                mediaitems = LocalMediaItems.AsEnumerable();
                if (Include != null)
                {
                    mediaitems = mediaitems.Where(u => Include.Any(x => x == u.Id));
                }
                if (!string.IsNullOrEmpty(Filter))
                {
                    mediaitems = mediaitems.Where(m => m.Title.Rendered.ToLower().Contains(Filter) || m.SourceUrl.ToLower().Contains(Filter));
                }
                mediaitems = mediaitems.Skip((Page - 1) * PerPage).Take(PerPage);
            }

            return(mediaitems);
        }
Beispiel #3
0
        public async Task Media_Query()
        {
            var queryBuilder = new MediaQueryBuilder()
            {
                Page    = 1,
                PerPage = 15,
                OrderBy = MediaOrderBy.Date,
                Order   = Order.ASC,
            };
            var queryresult = await _clientAuth.Media.Query(queryBuilder);

            Assert.AreEqual("?page=1&per_page=15&orderby=date&media_type=image&order=asc&context=view", queryBuilder.BuildQueryURL());
            Assert.IsNotNull(queryresult);
            Assert.AreNotSame(queryresult.Count(), 0);
        }
Beispiel #4
0
        public override async Task <IPagedResults <Models.Media> > ToList()
        {
            var builder     = new MediaQueryBuilder(this);
            var populateSql = builder.BuildSqlPopulate();
            var countSql    = builder.BuildSqlCount();
            var keywords    = Params.Keywords.Value ?? string.Empty;

            return(await _store.SelectAsync(new[]
            {
                new DbParam("PageIndex", DbType.Int32, PageIndex),
                new DbParam("PageSize", DbType.Int32, PageSize),
                new DbParam("SqlPopulate", DbType.String, populateSql),
                new DbParam("SqlCount", DbType.String, countSql),
                new DbParam("Keywords", DbType.String, keywords)
            }));
        }
Beispiel #5
0
        public async Task Media_Query()
        {
            var client = await ClientHelper.GetAuthenticatedWordPressClient();

            var queryBuilder = new MediaQueryBuilder()
            {
                Page    = 1,
                PerPage = 15,
                OrderBy = MediaOrderBy.Date,
                Order   = Order.DESC,
            };
            var queryresult = await client.Media.Query(queryBuilder);

            Assert.AreEqual(queryBuilder.BuildQueryURL(), "?page=1&per_page=15&order=desc");
            Assert.IsNotNull(queryresult);
            Assert.AreNotSame(queryresult.Count(), 0);
        }
Beispiel #6
0
 /// <summary>
 /// Create a parametrized query and get a result
 /// </summary>
 /// <param name="queryBuilder">Query builder with specific parameters</param>
 /// <param name="useAuth">Send request with authenication header</param>
 /// <returns>List of filtered result</returns>
 public async Task <IEnumerable <MediaItem> > Query(MediaQueryBuilder queryBuilder, bool useAuth = false)
 {
     return(await _httpHelper.GetRequest <IEnumerable <MediaItem> >($"{_defaultPath}{_methodPath}{queryBuilder.BuildQueryURL()}", false, useAuth).ConfigureAwait(false));
 }
Beispiel #7
0
 public async Task <IEnumerable <MediaItem> > Query(MediaQueryBuilder QueryBuilder)
 {
     return(await HttpHelper.GetRequests <IEnumerable <MediaItem> >(_methodPath + "/" + QueryBuilder.BuildQueryURL()));
 }