예제 #1
0
        /// <summary>
        /// GetSupervisorListAsync
        /// </summary>
        /// <param name="previousPage"></param>
        /// <returns>SupervisorApiModel</returns>
        public async Task <PagedResult <SupervisorApiModel> > GetSupervisorListAsync(PagedResult <SupervisorApiModel> previousPage = null)
        {
            var pageResult = new PagedResult <SupervisorApiModel>();

            try {
                var model       = new SupervisorQueryApiModel();
                var supervisors = new SupervisorListApiModel();

                if (string.IsNullOrEmpty(previousPage?.ContinuationToken))
                {
                    supervisors = await _registryService.QuerySupervisorsAsync(model, null, _commonHelper.PageLength);

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

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

                if (supervisors != null)
                {
                    foreach (var sup in supervisors.Items)
                    {
                        var supervisor = await _registryService.GetSupervisorAsync(sup.Id);

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

                pageResult.ContinuationToken = supervisors.ContinuationToken;
                pageResult.PageSize          = _commonHelper.PageLength;
                pageResult.RowCount          = pageResult.Results.Count;
            }
            catch (UnauthorizedAccessException) {
                pageResult.Error = "Unauthorized access: Bad User Access Denied.";
            }
            catch (Exception e) {
                var message = "Cannot get supervisor list";
                _logger.Warning(e, message);
                pageResult.Error = message;
            }
            return(pageResult);
        }
예제 #2
0
        /// <summary>
        /// GetSupervisorListAsync
        /// </summary>
        /// <returns>SupervisorApiModel</returns>
        public async Task <PagedResult <SupervisorApiModel> > GetSupervisorListAsync()
        {
            var pageResult = new PagedResult <SupervisorApiModel>();

            try {
                var model = new SupervisorQueryApiModel();

                var supervisors = await _registryService.QueryAllSupervisorsAsync(model);

                foreach (var supervisor in supervisors)
                {
                    pageResult.Results.Add(supervisor);
                }
            }
            catch (Exception e) {
                _logger.Warning("Can not get supervisor 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);
        }
예제 #3
0
 /// <summary>
 /// Convert to service model
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static SupervisorQueryModel ToServiceModel(
     this SupervisorQueryApiModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new SupervisorQueryModel {
         SiteId = model.SiteId,
         Connected = model.Connected
     });
 }
예제 #4
0
        /// <summary>
        /// Find supervisors
        /// </summary>
        /// <param name="service"></param>
        /// <param name="onlyServerState"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <SupervisorApiModel> > QueryAllSupervisorsAsync(
            this IRegistryServiceApi service, SupervisorQueryApiModel query, bool?onlyServerState = null)
        {
            var registrations = new List <SupervisorApiModel>();
            var result        = await service.QuerySupervisorsAsync(query, onlyServerState, null);

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

                registrations.AddRange(result.Items);
            }
            return(registrations);
        }
        public async Task<SupervisorListApiModel> QuerySupervisorsAsync(
            [FromBody] [Required] SupervisorQueryApiModel 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 _supervisors.QuerySupervisorsAsync(
                query.ToServiceModel(), onlyServerState ?? false, pageSize);

            // TODO: Filter results based on RBAC

            return new SupervisorListApiModel(result);
        }
        /// <inheritdoc/>
        public async Task <SupervisorListApiModel> QuerySupervisorsAsync(
            SupervisorQueryApiModel query, bool?onlyServerState, int?pageSize)
        {
            var uri = new UriBuilder($"{_serviceUri}/v2/supervisors/query");

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

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

            response.Validate();
            return(response.GetContent <SupervisorListApiModel>());
        }
예제 #7
0
        /// <inheritdoc/>
        public async Task <SupervisorListApiModel> QuerySupervisorsAsync(
            SupervisorQueryApiModel query, bool?onlyServerState, int?pageSize,
            CancellationToken ct)
        {
            var uri = new UriBuilder($"{_serviceUri}/v2/supervisors/query");

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

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

            response.Validate();
            return(_serializer.DeserializeResponse <SupervisorListApiModel>(response));
        }