Exemplo n.º 1
0
        /// <summary>
        /// GetPublisherListAsync
        /// </summary>
        /// <returns>PublisherApiModel</returns>
        public async Task <PagedResult <PublisherApiModel> > GetPublisherListAsync()
        {
            var pageResult = new PagedResult <PublisherApiModel>();

            try {
                var publisherModel = new PublisherQueryApiModel();
                var publishers     = await _registryService.QueryAllPublishersAsync(publisherModel);

                if (publishers != null)
                {
                    foreach (var publisher in publishers)
                    {
                        pageResult.Results.Add(publisher);
                    }
                }
            }
            catch (Exception e) {
                _logger.Warning("Can not get publisher list");
                var errorMessage = string.Concat(e.Message, e.InnerException?.Message ?? "--", e?.StackTrace ?? "--");
                _logger.Warning(errorMessage);
                pageResult.Error = e.Message;
            }

            pageResult.PageSize  = 10;
            pageResult.RowCount  = pageResult.Results.Count;
            pageResult.PageCount = (int)Math.Ceiling((decimal)pageResult.RowCount / 10);
            return(pageResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// GetPublisherListAsync
        /// </summary>
        /// <param name="previousPage"></param>
        /// <returns>PublisherApiModel</returns>
        public async Task <PagedResult <PublisherApiModel> > GetPublisherListAsync(PagedResult <PublisherApiModel> previousPage = null)
        {
            var pageResult = new PagedResult <PublisherApiModel>();

            try {
                var publisherModel = new PublisherQueryApiModel();
                var publishers     = new PublisherListApiModel();

                if (string.IsNullOrEmpty(previousPage?.ContinuationToken))
                {
                    publishers = await _registryService.QueryPublishersAsync(publisherModel, null, _commonHelper.PageLengthSmall);

                    if (!string.IsNullOrEmpty(publishers.ContinuationToken))
                    {
                        pageResult.PageCount = 2;
                    }
                }
                else
                {
                    publishers = await _registryService.ListPublishersAsync(previousPage.ContinuationToken, null, _commonHelper.PageLengthSmall);

                    if (string.IsNullOrEmpty(publishers.ContinuationToken))
                    {
                        pageResult.PageCount = previousPage.PageCount;
                    }
                    else
                    {
                        pageResult.PageCount = previousPage.PageCount + 1;
                    }
                }

                if (publishers != null)
                {
                    foreach (var pub in publishers.Items)
                    {
                        var publisher = await _registryService.GetPublisherAsync(pub.Id);

                        pageResult.Results.Add(publisher);
                    }
                }
                if (previousPage != null)
                {
                    previousPage.Results.AddRange(pageResult.Results);
                    pageResult.Results = previousPage.Results;
                }

                pageResult.ContinuationToken = publishers.ContinuationToken;
                pageResult.PageSize          = _commonHelper.PageLengthSmall;
                pageResult.RowCount          = pageResult.Results.Count;
            }
            catch (UnauthorizedAccessException) {
                pageResult.Error = "Unauthorized access: Bad User Access Denied.";
            }
            catch (Exception e) {
                var message = "Cannot get publisher list";
                _logger.Warning(e, message);
                pageResult.Error = message;
            }
            return(pageResult);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Convert to service model
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static PublisherQueryModel ToServiceModel(
     this PublisherQueryApiModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new PublisherQueryModel {
         SiteId = model.SiteId,
         Connected = model.Connected
     });
 }
        /// <summary>
        /// Find publishers
        /// </summary>
        /// <param name="service"></param>
        /// <param name="onlyServerState"></param>
        /// <param name="query"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <PublisherApiModel> > QueryAllPublishersAsync(
            this IRegistryServiceApi service, PublisherQueryApiModel query, bool?onlyServerState = null,
            CancellationToken ct = default)
        {
            var registrations = new List <PublisherApiModel>();
            var result        = await service.QueryPublishersAsync(query, onlyServerState, null, ct);

            registrations.AddRange(result.Items);
            while (result.ContinuationToken != null)
            {
                result = await service.ListPublishersAsync(result.ContinuationToken,
                                                           onlyServerState, null, ct);

                registrations.AddRange(result.Items);
            }
            return(registrations);
        }
        public async Task <PublisherListApiModel> GetFilteredListOfPublisherAsync(
            [FromQuery][Required] PublisherQueryApiModel query,
            [FromQuery] bool?onlyServerState,
            [FromQuery] int?pageSize)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (Request.Headers.ContainsKey(HttpHeader.MaxItemCount))
            {
                pageSize = int.Parse(Request.Headers[HttpHeader.MaxItemCount]
                                     .FirstOrDefault());
            }
            var result = await _publishers.QueryPublishersAsync(
                query.ToServiceModel(), onlyServerState ?? false, pageSize);

            // TODO: Filter results based on RBAC

            return(result.ToApiModel());
        }
        /// <inheritdoc/>
        public async Task <PublisherListApiModel> QueryPublishersAsync(
            PublisherQueryApiModel query, bool?onlyServerState, int?pageSize,
            CancellationToken ct)
        {
            var uri = new UriBuilder($"{_serviceUri}/v2/publishers/query");

            if (onlyServerState ?? false)
            {
                uri.Query = "onlyServerState=true";
            }
            var request = _httpClient.NewRequest(uri.Uri, _resourceId);

            if (pageSize != null)
            {
                request.AddHeader(HttpHeader.MaxItemCount, pageSize.ToString());
            }
            request.SetContent(query);
            var response = await _httpClient.PostAsync(request, ct).ConfigureAwait(false);

            response.Validate();
            return(response.GetContent <PublisherListApiModel>());
        }