/// <summary> /// Deletes Time Series instances from the environment by Time Series Ids synchronously. /// </summary> /// <param name="timeSeriesTypeIds">List of Ids of the Time Series instances to delete.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// List of error objects corresponding by position to the input array in the request. null when the operation is successful. /// </returns> /// <seealso cref="DeleteByIdAsync(IEnumerable{string}, CancellationToken)"> /// See the asynchronous version of this method for examples. /// </seealso> /// <exception cref="ArgumentNullException"> /// The exception is thrown when <paramref name="timeSeriesTypeIds"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// The exception is thrown when <paramref name="timeSeriesTypeIds"/> is empty. /// </exception> public virtual Response <TimeSeriesOperationError[]> DeleteById( IEnumerable <string> timeSeriesTypeIds, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(DeleteById)}"); scope.Start(); try { Argument.AssertNotNullOrEmpty(timeSeriesTypeIds, nameof(timeSeriesTypeIds)); var batchRequest = new TypesBatchRequest { Delete = new TypesRequestBatchGetOrDelete() }; foreach (string typeId in timeSeriesTypeIds ?? Enumerable.Empty <string>()) { batchRequest.Delete.TypeIds.Add(typeId); } Response <TypesBatchResponse> executeBatchResponse = _typesRestClient .ExecuteBatch(batchRequest, null, cancellationToken); return(Response.FromValue(executeBatchResponse.Value.Delete.ToArray(), executeBatchResponse.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Creates Time Series Insights types synchronously. If a provided type is already in use, then this will attempt to replace the existing type with the provided Time Series type. /// </summary> /// <param name="timeSeriesTypes">The Time Series Insights types to be created or replaced.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// List of types or error objects corresponding by position to the <paramref name="timeSeriesTypes"/> array in the request. /// Type object is set when operation is successful and error object is set when operation is unsuccessful. /// </returns> /// <seealso cref="CreateOrReplaceAsync(IEnumerable{TimeSeriesType}, CancellationToken)"> /// See the asynchronous version of this method for examples. /// </seealso> /// <exception cref="ArgumentNullException"> /// The exception is thrown when <paramref name="timeSeriesTypes"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// The exception is thrown when <paramref name="timeSeriesTypes"/> is empty. /// </exception> public virtual Response <TimeSeriesTypeOperationResult[]> CreateOrReplace( IEnumerable <TimeSeriesType> timeSeriesTypes, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(CreateOrReplace)}"); scope.Start(); try { Argument.AssertNotNullOrEmpty(timeSeriesTypes, nameof(timeSeriesTypes)); var batchRequest = new TypesBatchRequest(); foreach (TimeSeriesType type in timeSeriesTypes) { batchRequest.Put.Add(type); } Response <TypesBatchResponse> executeBatchResponse = _typesRestClient .ExecuteBatch(batchRequest, null, cancellationToken); IEnumerable <TimeSeriesOperationError> errorResults = executeBatchResponse.Value.Put.Select((result) => result.Error); return(Response.FromValue(executeBatchResponse.Value.Put.ToArray(), executeBatchResponse.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Deletes Time Series Insights types by type names asynchronously. /// </summary> /// <param name="timeSeriesTypeNames">List of names of the Time Series types to delete.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// List of error objects corresponding by position to the input array in the request. null when the operation is successful. /// </returns> /// <remarks> /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/timeseriesinsights/Azure.IoT.TimeSeriesInsights/samples">our repo samples</see>. /// </remarks> /// <exception cref="ArgumentNullException"> /// The exception is thrown when <paramref name="timeSeriesTypeNames"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// The exception is thrown when <paramref name="timeSeriesTypeNames"/> is empty. /// </exception> public virtual async Task <Response <TimeSeriesOperationError[]> > DeleteByNameAsync( IEnumerable <string> timeSeriesTypeNames, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(DeleteByName)}"); scope.Start(); try { Argument.AssertNotNullOrEmpty(timeSeriesTypeNames, nameof(timeSeriesTypeNames)); var batchRequest = new TypesBatchRequest { Delete = new TypesRequestBatchGetOrDelete() }; foreach (string timeSeriesName in timeSeriesTypeNames) { batchRequest.Delete.Names.Add(timeSeriesName); } Response <TypesBatchResponse> executeBatchResponse = await _typesRestClient .ExecuteBatchAsync(batchRequest, null, cancellationToken) .ConfigureAwait(false); return(Response.FromValue(executeBatchResponse.Value.Delete.ToArray(), executeBatchResponse.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Gets Time Series Insights types by type names synchronously. /// </summary> /// <param name="timeSeriesTypeNames">List of names of the Time Series types to return.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// List of type or error objects corresponding by position to the array in the request. /// Type object is set when operation is successful and error object is set when operation is unsuccessful. /// </returns> /// <seealso cref="GetByNameAsync(IEnumerable{string}, CancellationToken)"> /// See the asynchronous version of this method for examples. /// </seealso> /// <exception cref="ArgumentNullException"> /// The exception is thrown when <paramref name="timeSeriesTypeNames"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// The exception is thrown when <paramref name="timeSeriesTypeNames"/> is empty. /// </exception> public virtual Response <TimeSeriesTypeOperationResult[]> GetByName( IEnumerable <string> timeSeriesTypeNames, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetByName)}"); scope.Start(); try { Argument.AssertNotNullOrEmpty(timeSeriesTypeNames, nameof(timeSeriesTypeNames)); var batchRequest = new TypesBatchRequest() { Get = new TypesRequestBatchGetOrDelete() }; foreach (string timeSeriesName in timeSeriesTypeNames) { batchRequest.Get.Names.Add(timeSeriesName); } Response <TypesBatchResponse> executeBatchResponse = _typesRestClient .ExecuteBatch(batchRequest, null, cancellationToken); return(Response.FromValue(executeBatchResponse.Value.Get.ToArray(), executeBatchResponse.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } }