Example #1
0
        public async Task <IActionResult> GetStateSets([FromBody] StateSetSearchRequest filter, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); // 400
            }

            try {
                var result = await _historian.GetStateSets(User, filter.ToStateSetFilter(), cancellationToken).ConfigureAwait(false);

                return(Ok(result.Select(x => x.ToStateSetDto()).ToArray())); // 200
            }
            catch (ArgumentException) {
                return(BadRequest()); // 400
            }
            catch (OperationCanceledException) {
                return(StatusCode(204)); // 204
            }
            catch (SecurityException) {
                return(Forbid()); // 403
            }
            catch (NotSupportedException) {
                return(BadRequest()); // 400
            }
            catch (NotImplementedException) {
                return(BadRequest()); // 400
            }
        }
Example #2
0
        public Task <IActionResult> GetStateSets(CancellationToken cancellationToken, [FromQuery] string name = null, int pageSize = 50, int page = 1)
        {
            var filter = new StateSetSearchRequest()
            {
                Name     = name,
                PageSize = pageSize,
                Page     = page
            };

            TryValidateModel(filter);
            return(GetStateSets(filter, cancellationToken));
        }
Example #3
0
        /// <summary>
        /// Gets the available tag state sets.  State-based tags specify a state set that controls the
        /// possible values for the tag.  Authorized using the <c>aika:managetags</c> authorization
        /// policy.
        /// </summary>
        /// <param name="filter">The state set search filter.</param>
        /// <param name="cancellationToken">The cancellation token for the request.</param>
        /// <returns>
        /// A task that will return the matching state sets.
        /// </returns>
        public async Task <IEnumerable <StateSetDto> > GetStateSets(StateSetSearchRequest filter, CancellationToken cancellationToken)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            const string url      = "api/configuration/statesets";
            var          response = await _client.PostAsJsonAsync(url, filter, cancellationToken).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            return(await response.Content.ReadAsJsonAsync <IEnumerable <StateSetDto> >(cancellationToken).ConfigureAwait(false));
        }
Example #4
0
        internal static StateSetFilter ToStateSetFilter(this StateSetSearchRequest filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            return(new StateSetFilter()
            {
                PageSize = filter.PageSize,
                Page = filter.Page,
                Filter = filter.Name
            });
        }