예제 #1
0
 public async static Task<PagedList<Article>> FindAllAsync(string type, string query = null, IEnumerable<string> fields = null, int page = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending )
 {
     var service = ObjectFactory.Build<IArticleService>();
     var request = new FindAllArticleRequest()
     {
         Type = type,
         Query = query,
         PageNumber = page,
         PageSize = pageSize,
         OrderBy = orderBy,
         SortOrder = sortOrder
     };
     var response = await service.FindAllAsync(request);
     if (response.Status.IsSuccessful == false)
         throw response.Status.ToFault();
     var articles = new PagedList<Article>()
     {
         PageNumber = response.PagingInfo.PageNumber,
         PageSize = response.PagingInfo.PageSize,
         TotalRecords = response.PagingInfo.TotalRecords,
         GetNextPage = async skip => await FindAllAsync(type, query, fields, page+skip+1, pageSize)
     };
     articles.AddRange(response.Articles);
     return articles;
     
 }
예제 #2
0
        public async static Task <PagedList <Article> > FindAllAsync(string type, string query = null, IEnumerable <string> fields = null, int page = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending)
        {
            var request = new FindAllArticleRequest()
            {
                Type       = type,
                Query      = query,
                PageNumber = page,
                PageSize   = pageSize,
                OrderBy    = orderBy,
                SortOrder  = sortOrder
            };

            if (fields != null)
            {
                request.Fields.AddRange(fields);
            }
            var response = await request.ExecuteAsync();

            if (response.Status.IsSuccessful == false)
            {
                throw response.Status.ToFault();
            }
            var articles = new PagedList <Article>()
            {
                PageNumber   = response.PagingInfo.PageNumber,
                PageSize     = response.PagingInfo.PageSize,
                TotalRecords = response.PagingInfo.TotalRecords,
                GetNextPage  = async skip => await FindAllAsync(type, query, fields, page + skip + 1, pageSize, orderBy, sortOrder)
            };

            articles.AddRange(response.Articles);
            return(articles);
        }
 public async Task<FindAllArticleResponse> FindAllAsync(FindAllArticleRequest request)
 {
     byte[] bytes = null;
     bytes = await HttpOperation
                 .WithUrl(Urls.For.FindAllArticles(request.Type, request.Query, request.PageNumber, request.PageSize, request.OrderBy,request.SortOrder, request.CurrentLocation, request.DebugEnabled, request.Verbosity, request.Fields))
                 .WithAppacitiveSession(request.SessionToken)
                 .WithEnvironment(request.Environment)
                 .WithUserToken(request.UserToken)
                 .GetAsync();
     var response = FindAllArticleResponse.Parse(bytes);
     return response;
 }
        public async Task FindAllArticleAsyncFixture()
        {
            // Create atleast one article
            var     now = DateTime.Now;
            dynamic obj = new Article("object");

            obj.intfield      = 66666;
            obj.decimalfield  = 98765.0m;
            obj.datefield     = "2012-12-20";
            obj.datetimefield = now.ToString("o");
            obj.stringfield   = "Frank";
            obj.textfield     = "Frand Sinatra was an amazing singer.";
            obj.boolfield     = false;
            obj.geofield      = "11.5,12.5";
            obj.listfield     = "a";


            CreateArticleResponse response = null;

            response = await(new CreateArticleRequest()
            {
                Article = obj
            }).ExecuteAsync();

            ApiHelper.EnsureValidResponse(response);

            // Find all articles
            var findRequest = new FindAllArticleRequest()
            {
                Type = "object"
            };
            var findResponse = await findRequest.ExecuteAsync();

            ApiHelper.EnsureValidResponse(findResponse);
            findResponse.Articles.ForEach(x => Console.WriteLine("Found article id {0}.", x.Id));
            Assert.IsNotNull(findResponse.PagingInfo);
            Assert.IsTrue(findResponse.PagingInfo.PageNumber == 1);
            Assert.IsTrue(findResponse.PagingInfo.TotalRecords > 0);
            Console.WriteLine("Paging info => pageNumber: {0}, pageSize: {1}, totalRecords: {2}",
                              findResponse.PagingInfo.PageNumber,
                              findResponse.PagingInfo.PageSize,
                              findResponse.PagingInfo.TotalRecords);
        }
        public async Task FindAllArticleAsyncFixture()
        {
            // Create atleast one article
            var now = DateTime.Now;
            dynamic obj = new Article("object");
            obj.intfield = 66666;
            obj.decimalfield = 98765.0m;
            obj.datefield = "2012-12-20";
            obj.datetimefield = now.ToString("o");
            obj.stringfield = "Frank";
            obj.textfield = "Frand Sinatra was an amazing singer.";
            obj.boolfield = false;
            obj.geofield = "11.5,12.5";
            obj.listfield = "a";


            var service = ObjectFactory.Build<IArticleService>();
            CreateArticleResponse response = null;
            response = await service.CreateArticleAsync(new CreateArticleRequest()
            {
                Article = obj
            });

            ApiHelper.EnsureValidResponse(response);

            // Find all articles
            var findRequest = new FindAllArticleRequest() { Type = "object" };
            var findResponse = await service.FindAllAsync(findRequest);
            ApiHelper.EnsureValidResponse(findResponse);
            findResponse.Articles.ForEach(x => Console.WriteLine("Found article id {0}.", x.Id));
            Assert.IsNotNull(findResponse.PagingInfo);
            Assert.IsTrue(findResponse.PagingInfo.PageNumber == 1);
            Assert.IsTrue(findResponse.PagingInfo.TotalRecords > 0);
            Console.WriteLine("Paging info => pageNumber: {0}, pageSize: {1}, totalRecords: {2}",
                findResponse.PagingInfo.PageNumber,
                findResponse.PagingInfo.PageSize,
                findResponse.PagingInfo.TotalRecords);
        }