Пример #1
0
        /// <summary>
        /// Gets a paginated list of APObjects connected to this object via connections of the given type.
        /// </summary>
        /// <param name="connectionType">The type (relation name) of the connection.</param>
        /// <param name="query">Search query to further filter the list of connection objects.</param>
        /// <param name="label">Label of the endpoint to be queried. This is mandatory when the connection type being queried has endpoints with the same type but different labels.</param>
        /// <param name="fields">The fields to be returned for the matching objects.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The page size.</param>
        /// <param name="orderBy">The field on which to sort the results.</param>
        /// <param name="sortOrder">The sort order - Ascending or Descending.</param>
        /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param>
        /// <returns>A paginated list of APObjects.</returns>
        public async Task <PagedList <APObject> > GetConnectedObjectsAsync(string connectionType, string query = null, string label = null, IEnumerable <string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null)
        {
            var request = new FindConnectedObjectsRequest
            {
                Relation   = connectionType,
                ObjectId   = this.Id,
                Object     = this,
                Label      = label,
                Query      = query,
                Type       = this.Type,
                ReturnEdge = false,
                PageNumber = pageNumber,
                PageSize   = pageSize,
                SortOrder  = sortOrder,
                OrderBy    = orderBy
            };

            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();
            }

            IEnumerable <APObject> objects = response.Nodes.Select(n => n.Object);
            var list = new PagedList <APObject>()
            {
                PageNumber   = response.PagingInfo.PageNumber,
                PageSize     = response.PagingInfo.PageSize,
                TotalRecords = response.PagingInfo.TotalRecords,
                GetNextPage  = async skip => await this.GetConnectedObjectsAsync(connectionType, query, label, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options)
            };

            list.AddRange(objects);
            return(list);
        }
Пример #2
0
        /// <summary>
        /// Gets a paginated list of APConnections for the current object of the given connection type.
        /// </summary>
        /// <param name="connectionType">The type (relation name) of the connection.</param>
        /// <param name="query">Search query to further filter the list of connection objects.</param>
        /// <param name="label">Label of the endpoint to be queried. This is mandatory when the connection type being queried has endpoints with the same type but different labels.</param>
        /// <param name="fields">The fields to be returned for the matching objects.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The page size.</param>
        /// <param name="orderBy">The field on which to sort the results.</param>
        /// <param name="sortOrder">The sort order - Ascending or Descending.</param>
        /// <returns>A paginated list of APConnection objects.</returns>
        public async Task<PagedList<APConnection>> GetConnectionsAsync(string connectionType, string query = null, string label = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null)
        {
            var request = new FindConnectedObjectsRequest
            {
                Relation = connectionType,
                ObjectId = this.Id,
                Object = this,
                Query = query,
                Label = label,
                Type = this.Type,
                ReturnEdge = true,
                PageNumber = pageNumber,
                PageSize = pageSize,
                SortOrder = sortOrder,
                OrderBy = orderBy
            };
            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 list = new PagedList<APConnection>
            {
                PageNumber = response.PagingInfo.PageNumber,
                PageSize = response.PagingInfo.PageSize,
                TotalRecords = response.PagingInfo.TotalRecords,
                GetNextPage = async skip => await GetConnectionsAsync(connectionType, query, null, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options)
            };
            list.AddRange(response.Nodes.Select(n => n.Connection));
            return list;
        }