Skip to content

Commit 596091f

Browse files
author
Basel Rustum
authored
feat (TSI instances): Time Series Insights Instances client library implementation (Azure#19209)
1 parent a06853e commit 596091f

File tree

54 files changed

+3752
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3752
-564
lines changed

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/api/Azure.Iot.TimeSeriesInsights.netstandard2.0.cs

Lines changed: 79 additions & 55 deletions
Large diffs are not rendered by default.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using System.Text.Json;
6+
using Azure.Core;
7+
8+
namespace Azure.Iot.TimeSeriesInsights
9+
{
10+
/// <summary>
11+
/// This class definition overrides serialization implementation in order to turn a raw response
12+
/// from Time Series Insights into a InstancesBatchResponse object.
13+
/// </summary>
14+
[CodeGenModel("InstancesBatchResponse")]
15+
public partial class InstancesBatchResponse
16+
{
17+
// The purpose of overriding this method is to protect against an InvalidOperationException
18+
// that is being thrown by the generated code. More specifically, the exception is being thrown
19+
// when trying to deserialize the "delete" property. A coveration has started with the Time Series
20+
// Insights team on take a closer look on the thrown exception.
21+
22+
internal static InstancesBatchResponse DeserializeInstancesBatchResponse(JsonElement element)
23+
{
24+
Optional<IReadOnlyList<InstancesOperationResult>> @get = default;
25+
Optional<IReadOnlyList<InstancesOperationResult>> put = default;
26+
Optional<IReadOnlyList<InstancesOperationResult>> update = default;
27+
Optional<IReadOnlyList<InstancesOperationError>> delete = default;
28+
foreach (JsonProperty property in element.EnumerateObject())
29+
{
30+
if (property.NameEquals("get"))
31+
{
32+
if (property.Value.ValueKind == JsonValueKind.Null)
33+
{
34+
property.ThrowNonNullablePropertyIsNull();
35+
continue;
36+
}
37+
List<InstancesOperationResult> array = new List<InstancesOperationResult>();
38+
foreach (JsonElement item in property.Value.EnumerateArray())
39+
{
40+
array.Add(InstancesOperationResult.DeserializeInstancesOperationResult(item));
41+
}
42+
@get = array;
43+
continue;
44+
}
45+
if (property.NameEquals("put"))
46+
{
47+
if (property.Value.ValueKind == JsonValueKind.Null)
48+
{
49+
property.ThrowNonNullablePropertyIsNull();
50+
continue;
51+
}
52+
List<InstancesOperationResult> array = new List<InstancesOperationResult>();
53+
foreach (JsonElement item in property.Value.EnumerateArray())
54+
{
55+
array.Add(InstancesOperationResult.DeserializeInstancesOperationResult(item));
56+
}
57+
put = array;
58+
continue;
59+
}
60+
if (property.NameEquals("update"))
61+
{
62+
if (property.Value.ValueKind == JsonValueKind.Null)
63+
{
64+
property.ThrowNonNullablePropertyIsNull();
65+
continue;
66+
}
67+
List<InstancesOperationResult> array = new List<InstancesOperationResult>();
68+
foreach (JsonElement item in property.Value.EnumerateArray())
69+
{
70+
array.Add(InstancesOperationResult.DeserializeInstancesOperationResult(item));
71+
}
72+
update = array;
73+
continue;
74+
}
75+
if (property.NameEquals("delete"))
76+
{
77+
if (property.Value.ValueKind == JsonValueKind.Null)
78+
{
79+
property.ThrowNonNullablePropertyIsNull();
80+
continue;
81+
}
82+
List<InstancesOperationError> array = new List<InstancesOperationError>();
83+
foreach (JsonElement item in property.Value.EnumerateArray())
84+
{
85+
array.Add(item.ValueKind != JsonValueKind.Null ? InstancesOperationError.DeserializeInstancesOperationError(item) : null);
86+
}
87+
delete = array;
88+
continue;
89+
}
90+
}
91+
return new InstancesBatchResponse(Optional.ToList(@get), Optional.ToList(put), Optional.ToList(update), Optional.ToList(delete));
92+
}
93+
}
94+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.Iot.TimeSeriesInsights
7+
{
8+
/// <summary>
9+
/// A particular API error with an error code and a message.
10+
/// </summary>
11+
[CodeGenModel("TsiErrorBody")]
12+
public partial class InstancesOperationError
13+
{
14+
// This class declaration changes the class name; do not remove.
15+
// The class name change is to make it clearer to the user that this type represents
16+
// an instances operation error.
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.Iot.TimeSeriesInsights
7+
{
8+
/// <summary>
9+
/// Error details for Time Series Insights instances operations.
10+
/// </summary>
11+
[CodeGenModel("TsiErrorDetails")]
12+
public partial class InstancesOperationErrorDetails
13+
{
14+
// This class declaration changes the class name; do not remove.
15+
// The class name change is to make it clearer to the user that this type represents
16+
// error details for an instances operation.
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.Iot.TimeSeriesInsights
7+
{
8+
/// <summary>
9+
/// Result of an operation on a particular time series instance. Instance object is set when operation
10+
/// is successful and error object is set when operation is unsuccessful.
11+
/// </summary>
12+
[CodeGenModel("InstanceOrError")]
13+
public partial class InstancesOperationResult
14+
{
15+
// This class declaration changes the class name; do not remove.
16+
// The class name change is to make it clearer to the user that this type represents
17+
// an instances operation result.
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Text.Json;
5+
using Azure.Core;
6+
7+
namespace Azure.Iot.TimeSeriesInsights
8+
{
9+
/// <summary>
10+
/// This class definition overrides serialization implementation in order to turn Time
11+
/// Series Ids from a strongly typed object to an list of objects that the service can understand.
12+
/// </summary>
13+
public partial class InstancesRequestBatchGetOrDelete : IUtf8JsonSerializable
14+
{
15+
// This class declaration overrides the logic that serializes the object. More specifically, to
16+
// serialize "timeSeriesIds". Since TimeSeriesIds changed from a list of objects to a strongly
17+
// typed object, serialization is handled differently.
18+
19+
// The use of fully qualified name for IUtf8JsonSerializable is a work around until this
20+
// issue is fixed: https://github.com/Azure/autorest.csharp/issues/793
21+
void global::Azure.Core.IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
22+
{
23+
writer.WriteStartObject();
24+
if (Optional.IsCollectionDefined(TimeSeriesIds))
25+
{
26+
writer.WritePropertyName("timeSeriesIds");
27+
writer.WriteStartArray();
28+
foreach (TimeSeriesId item in TimeSeriesIds)
29+
{
30+
writer.WriteStartArray();
31+
foreach (var item0 in item.ToArray())
32+
{
33+
writer.WriteObjectValue(item0);
34+
}
35+
writer.WriteEndArray();
36+
}
37+
writer.WriteEndArray();
38+
}
39+
if (Optional.IsCollectionDefined(Names))
40+
{
41+
writer.WritePropertyName("names");
42+
writer.WriteStartArray();
43+
foreach (var item in Names)
44+
{
45+
writer.WriteStringValue(item);
46+
}
47+
writer.WriteEndArray();
48+
}
49+
writer.WriteEndObject();
50+
}
51+
}
52+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using Azure.Core;
6+
7+
namespace Azure.Iot.TimeSeriesInsights
8+
{
9+
/// <summary>
10+
/// Request to get or delete instances by time series Ids or time series names.
11+
/// Exactly one of &quot;timeSeriesIds&quot; or &quot;names&quot; must be set.
12+
/// </summary>
13+
[CodeGenModel("InstancesRequestBatchGetOrDelete")]
14+
public partial class InstancesRequestBatchGetOrDelete
15+
{
16+
// Autorest does not support changing type for properties. In order to turn TimeSeriesId
17+
// from a list of objects to a strongly typed object, TimeSeriesId has been renamed to
18+
// TimeSeriesIdInternal and a new property, TimeSeriesId, has been created with the proper type.
19+
20+
[CodeGenMember("TimeSeriesIds")]
21+
private IList<IList<object>> TimeSeriesIdsInternal { get; }
22+
23+
/// <summary>
24+
/// The list of Time Series Ids used to make the request.
25+
/// </summary>
26+
public IList<TimeSeriesId> TimeSeriesIds { get; }
27+
28+
/// <summary>
29+
/// Initializes a new instance of InstancesRequestBatchGetOrDelete.
30+
/// </summary>
31+
public InstancesRequestBatchGetOrDelete()
32+
{
33+
TimeSeriesIds = new ChangeTrackingList<TimeSeriesId>();
34+
Names = new ChangeTrackingList<string>();
35+
}
36+
}
37+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.Iot.TimeSeriesInsights
7+
{
8+
/// <summary>
9+
/// Suggested search string to be used for further search for time series instances.
10+
/// </summary>
11+
[CodeGenModel("InstancesSearchStringSuggestion")]
12+
public partial class SearchSuggestion
13+
{
14+
// This declaration is to simplify the class name; do not remove.
15+
}
16+
}

0 commit comments

Comments
 (0)