/// <summary> /// Gets a paginated list of APObjects matching the given search criteria. /// </summary> /// <param name="type">The object type.</param> /// <param name="query">The search query for objects to be found.</param> /// <param name="fields">The object fields to be returned for the matching list of objects.</param> /// <param name="pageNumber">The page number.</param> /// <param name="pageSize">The page size.</param> /// <param name="orderBy">The object field on which the results should be sorted.</param> /// <param name="sortOrder">The sort order.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> /// <returns>Paginated list of APObject objects matching the given search criteria.</returns> public async static Task <PagedList <APObject> > FindAllAsync(string type, IQuery query = null, IEnumerable <string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null) { query = query ?? Query.None; var request = new FindAllObjectsRequest() { Type = type, Query = query.AsString().Escape(), PageNumber = pageNumber, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; if (fields != null) { request.Fields.AddRange(fields); } ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) { throw response.Status.ToFault(); } var objects = new PagedList <APObject>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FindAllAsync(type, query, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options) }; objects.AddRange(response.Objects); return(objects); }
/// <summary> /// Gets a paginated list of APObjects matching the given search criteria. /// </summary> /// <param name="type">The object type.</param> /// <param name="query">The search query for objects to be found.</param> /// <param name="fields">The object fields to be returned for the matching list of objects.</param> /// <param name="pageNumber">The page number.</param> /// <param name="pageSize">The page size.</param> /// <param name="orderBy">The object field on which the results should be sorted.</param> /// <param name="sortOrder">The sort order.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> /// <returns>Paginated list of APObject objects matching the given search criteria.</returns> public async static Task<PagedList<APObject>> FindAllAsync(string type, IQuery query = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null) { query = query ?? Query.None; var request = new FindAllObjectsRequest() { Type = type, Query = query.AsString().Escape(), PageNumber = pageNumber, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; if( fields != null ) request.Fields.AddRange(fields); ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var objects = new PagedList<APObject>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FindAllAsync(type, query, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options) }; objects.AddRange(response.Objects); return objects; }
public async Task FindAllObjectAsyncFixture() { // Create atleast one apObject var now = DateTime.Now; dynamic obj = new APObject("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"; CreateObjectResponse response = null; response = await(new CreateObjectRequest() { Object = obj }).ExecuteAsync(); ApiHelper.EnsureValidResponse(response); // Find all objects var findRequest = new FindAllObjectsRequest() { Type = "object" }; var findResponse = await findRequest.ExecuteAsync(); ApiHelper.EnsureValidResponse(findResponse); findResponse.Objects.ForEach(x => Console.WriteLine("Found apObject 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 FindAllObjectAsyncFixture() { // Create atleast one apObject var now = DateTime.Now; dynamic obj = new APObject("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"; CreateObjectResponse response = null; response = await (new CreateObjectRequest() { Object = obj }).ExecuteAsync(); ApiHelper.EnsureValidResponse(response); // Find all objects var findRequest = new FindAllObjectsRequest() { Type = "object" }; var findResponse = await findRequest.ExecuteAsync(); ApiHelper.EnsureValidResponse(findResponse); findResponse.Objects.ForEach(x => Console.WriteLine("Found apObject 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); }