Esempio n. 1
0
        public async Task <IActionResult> UpdateTag([FromRoute] string id, [FromBody] TagDefinitionUpdateDto tag, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); // 400
            }

            try {
                var result = await _historian.UpdateTag(User, id, tag.ToTagDefinitionUpdate(), tag.ChangeDescription, cancellationToken).ConfigureAwait(false);

                return(Ok(result.ToTagDefinitionExtendedDto())); // 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
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new tag in the historian.  Authorized using the <c>aika:managetags</c>
        /// authorization policy.
        /// </summary>
        /// <param name="tagDefinition">The tag definition to create.</param>
        /// <param name="cancellationToken">The cancellation token for the request.</param>
        /// <returns>
        /// A task that will return the extended definition for the new tag.
        /// </returns>
        public async Task <TagDefinitionExtendedDto> CreateTag(TagDefinitionUpdateDto tagDefinition, CancellationToken cancellationToken)
        {
            if (tagDefinition == null)
            {
                throw new ArgumentNullException(nameof(tagDefinition));
            }

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

            response.EnsureSuccessStatusCode();

            return(await response.Content.ReadAsJsonAsync <TagDefinitionExtendedDto>(cancellationToken).ConfigureAwait(false));
        }
Esempio n. 3
0
        /// <summary>
        /// Converts the object into a <see cref="TagSettings"/> object.
        /// </summary>
        /// <returns>
        /// An equivalent <see cref="TagSettings"/> object.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="item"/> is <see langword="null"/>.</exception>
        internal static TagSettings ToTagDefinitionUpdate(this TagDefinitionUpdateDto item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return(new TagSettings()
            {
                Name = item.Name,
                Description = item.Description,
                Units = item.Units,
                DataType = Enum.TryParse <TagDataType>(item.DataType, out var dt) ? dt : TagDataType.FloatingPoint,
                StateSet = item.StateSet,
                ExceptionFilterSettings = item.ExceptionFilterSettings?.ToTagValueFilterSettingsUpdate(),
                CompressionFilterSettings = item.CompressionFilterSettings?.ToTagValueFilterSettingsUpdate()
            });
Esempio n. 4
0
        /// <summary>
        /// Updates an existing historian tag.  Authorized using the <c>aika:managetags</c>
        /// authorization policy.
        /// </summary>
        /// <param name="tagId">The ID of the tag to update.</param>
        /// <param name="tagDefinition">The updated tag definition.</param>
        /// <param name="cancellationToken">The cancellation token for the request.</param>
        /// <returns>
        /// A task that will return the extended definition for the updated tag.
        /// </returns>
        public async Task <TagDefinitionExtendedDto> UpdateTag(string tagId, TagDefinitionUpdateDto tagDefinition, CancellationToken cancellationToken)
        {
            if (tagId == null)
            {
                throw new ArgumentNullException(nameof(tagId));
            }
            if (tagDefinition == null)
            {
                throw new ArgumentNullException(nameof(tagDefinition));
            }

            var url      = $"api/configuration/tags/{Uri.EscapeDataString(tagId)}";
            var response = await _client.PutAsJsonAsync(url, tagDefinition, cancellationToken).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            return(await response.Content.ReadAsJsonAsync <TagDefinitionExtendedDto>(cancellationToken).ConfigureAwait(false));
        }