public async Task<FindConnectedArticlesResponse> FindConnectedArticlesAsync(FindConnectedArticlesRequest request) { byte[] bytes = null; bytes = await HttpOperation .WithUrl(Urls.For.FindConnectedArticles(request.Relation, request.ArticleId, request.Query, request.PageNumber, request.PageSize, request.CurrentLocation, request.DebugEnabled, request.Verbosity, request.Fields)) .WithAppacitiveSession(request.SessionToken) .WithEnvironment(request.Environment) .WithUserToken(request.UserToken) .GetAsync(); var response = FindConnectedArticlesResponse.Parse(bytes); return response; }
public async static Task<PagedList<Connection>> GetConnectionsAsync(string relation, string articleId, string query = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20) { IConnectionService connService = ObjectFactory.Build<IConnectionService>(); var request = new FindConnectedArticlesRequest { Relation = relation, ArticleId = articleId, Query = query, PageNumber = pageNumber, PageSize = pageSize }; if (fields != null) request.Fields.AddRange(fields); var response = await connService.FindConnectedArticlesAsync(request); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var list = new PagedList<Connection> { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await GetConnectionsAsync(relation, articleId, query, fields, pageNumber + skip + 1, pageSize) }; list.AddRange(response.Connections); return list; }
public async static Task<PagedList<Article>> GetConnectedArticlesAsync(string relation, string articleId, string query = null, string label = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20) { var request = new FindConnectedArticlesRequest { Relation = relation, ArticleId = articleId, Label = label, Query = query, PageNumber = pageNumber, PageSize = pageSize }; if (fields != null) request.Fields.AddRange(fields); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); IEnumerable<Article> articles = null; // if label is specified, then get the labelled endpoint if (string.IsNullOrWhiteSpace(label) == false) articles = response.Connections.Select(c => c.Endpoints[label].Content); else articles = response.Connections.Select(c => { if (c.Endpoints.EndpointA.ArticleId == articleId) return c.Endpoints.EndpointB.Content; else return c.Endpoints.EndpointA.Content; }); var list = new PagedList<Article>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await GetConnectedArticlesAsync(relation, articleId, query, label, fields, pageNumber + skip + 1, pageSize) }; list.AddRange(articles); return list; }