コード例 #1
0
        public async Task <IActionResult> GetSnapshotData([FromBody] SnapshotDataRequest request, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); // 400
            }

            try {
                var result = await _historian.ReadSnapshotData(User, request.Tags, cancellationToken).ConfigureAwait(false);

                return(Ok(result.ToDictionary(x => x.Key, x => x.Value.ToTagValueDto()))); // 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
            }
        }
コード例 #2
0
        public Task <IActionResult> GetSnapshotData([FromQuery] string[] tag, CancellationToken cancellationToken)
        {
            var model = new SnapshotDataRequest()
            {
                Tags = tag
            };

            TryValidateModel(model);
            return(GetSnapshotData(model, cancellationToken));
        }
コード例 #3
0
        /// <summary>
        /// Reads snapshot values for a set of tags.  Authorized using the <c>aika:readtagdata</c>
        /// authorization policy.
        /// </summary>
        /// <param name="request">The snapshot data request.</param>
        /// <param name="cancellationToken">The cancellation token for the request.</param>
        /// <returns>
        /// A task that will return the snapshot values for the tags, indexed by tag name.
        /// </returns>
        public async Task <IDictionary <string, TagValueDto> > ReadSnapshotValues(SnapshotDataRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            const string url      = "api/tags/data/snapshot";
            var          response = await _client.PostAsJsonAsync(url, request, cancellationToken).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            return(await response.Content.ReadAsJsonAsync <IDictionary <string, TagValueDto> >(cancellationToken).ConfigureAwait(false));
        }