public async Task <IActionResult> UpdateStateSet([FromRoute] string name, [FromBody] StateSetDto stateSet, CancellationToken cancellationToken) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); // 400 } try { var result = await _historian.UpdateStateSet(User, name, stateSet.ToStateSetSettings(), cancellationToken).ConfigureAwait(false); return(Ok(result)); // 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 } }
/// <summary> /// Creates a new tag state set. Authorized using the <c>aika:managetags</c> authorization /// policy. /// </summary> /// <param name="stateSet">The state set definition.</param> /// <param name="cancellationToken">The cancellation token for the request.</param> /// <returns> /// A task that will return the new state set definition. /// </returns> public async Task <StateSetDto> CreateStateSet(StateSetDto stateSet, CancellationToken cancellationToken) { if (stateSet == null) { throw new ArgumentNullException(nameof(stateSet)); } const string url = "api/configuration/statesets"; var response = await _client.PostAsJsonAsync(url, stateSet, cancellationToken).ConfigureAwait(false); response.EnsureSuccessStatusCode(); return(await response.Content.ReadAsJsonAsync <StateSetDto>(cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Converts the object to the equivalent <see cref="StateSetSettings"/>. /// </summary> /// <param name="stateSet">The item to convert.</param> /// <returns> /// The equivalent <see cref="StateSetSettings"/>. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="stateSet"/> is <see langword="null"/>.</exception> internal static StateSetSettings ToStateSetSettings(this StateSetDto stateSet) { if (stateSet == null) { throw new ArgumentNullException(nameof(stateSet)); } return(new StateSetSettings() { Name = stateSet.Name, Description = stateSet.Description, States = stateSet.States?.Select(x => x.ToStateSetItem()).ToArray() ?? new StateSetItem[0] }); }
/// <summary> /// Updates a tag state set. Authorized using the <c>aika:managetags</c> authorization /// policy. /// </summary> /// <param name="stateSet">The updated state set.</param> /// <param name="cancellationToken">The cancellation token for the request.</param> /// <returns> /// A task that will return the updated state set. /// </returns> public async Task <StateSetDto> UpdateStateSet(StateSetDto stateSet, CancellationToken cancellationToken) { if (stateSet == null) { throw new ArgumentNullException(nameof(stateSet)); } if (String.IsNullOrWhiteSpace(stateSet.Name)) { throw new ArgumentException(Resources.Error_StateSetNameIsRequired, nameof(stateSet)); } var url = $"api/configuration/statesets/{Uri.EscapeDataString(stateSet?.Name)}"; var response = await _client.PutAsJsonAsync(url, new StateSetDto() { Description = stateSet.Description, States = stateSet.States }, cancellationToken).ConfigureAwait(false); response.EnsureSuccessStatusCode(); return(await response.Content.ReadAsJsonAsync <StateSetDto>(cancellationToken).ConfigureAwait(false)); }