|
7 | 7 | using Microsoft.Graph; |
8 | 8 | using Microsoft.Graph.External.Connections.Item.Items.Item.MicrosoftGraphExternalConnectorsAddActivities; |
9 | 9 | using Microsoft.Graph.Models.ExternalConnectors; |
| 10 | +using Microsoft.Kiota.Abstractions.Serialization; |
10 | 11 | using Microsoft.Kiota.Authentication.Azure; |
11 | 12 |
|
12 | 13 | namespace GitHubConnector.Services; |
@@ -149,10 +150,7 @@ public SearchConnectorService(AppSettings settings) |
149 | 150 | { |
150 | 151 | Id = itemType == "issues" ? "issueDisplay" : "repoDisplay", |
151 | 152 | Priority = 1, |
152 | | - Layout = new() |
153 | | - { |
154 | | - AdditionalData = await GetResultTemplateAsync(resultCardJsonFile), |
155 | | - }, |
| 153 | + Layout = await GetResultTemplateAsync(resultCardJsonFile), |
156 | 154 | }, |
157 | 155 | ], |
158 | 156 | }, |
@@ -280,10 +278,32 @@ public Task<Identity> GetIdentityForGitHubUserAsync(string? gitHubLogin) |
280 | 278 | }); |
281 | 279 | } |
282 | 280 |
|
283 | | - private static async Task<Dictionary<string, object>> GetResultTemplateAsync(string resultCardJsonFile) |
| 281 | + private static async Task<UntypedNode> GetResultTemplateAsync(string resultCardJsonFile) |
284 | 282 | { |
285 | 283 | var cardContents = await File.ReadAllTextAsync(resultCardJsonFile); |
286 | | - return JsonSerializer.Deserialize<Dictionary<string, object>>(cardContents) ?? |
287 | | - throw new Exception($"Could not deserialize contents of {resultCardJsonFile}"); |
| 284 | + using var cardJson = JsonDocument.Parse(cardContents); |
| 285 | + return ToUntypedNode(cardJson.RootElement); |
| 286 | + } |
| 287 | + |
| 288 | + private static UntypedNode ToUntypedNode(JsonElement element) |
| 289 | + { |
| 290 | + return element.ValueKind switch |
| 291 | + { |
| 292 | + JsonValueKind.Object => new UntypedObject(element.EnumerateObject() |
| 293 | + .ToDictionary(property => property.Name, property => ToUntypedNode(property.Value))), |
| 294 | + JsonValueKind.Array => new UntypedArray(element.EnumerateArray().Select(ToUntypedNode)), |
| 295 | + JsonValueKind.String => new UntypedString(element.GetString()!), |
| 296 | + JsonValueKind.Number => element.TryGetInt32(out var intValue) ? |
| 297 | + new UntypedInteger(intValue) : |
| 298 | + element.TryGetInt64(out var longValue) ? |
| 299 | + new UntypedLong(longValue) : |
| 300 | + element.TryGetDecimal(out var decimalValue) ? |
| 301 | + new UntypedDecimal(decimalValue) : |
| 302 | + new UntypedDouble(element.GetDouble()), |
| 303 | + JsonValueKind.True => new UntypedBoolean(true), |
| 304 | + JsonValueKind.False => new UntypedBoolean(false), |
| 305 | + JsonValueKind.Null => new UntypedNull(), |
| 306 | + _ => throw new JsonException($"Unsupported JSON value: {element.ValueKind}"), |
| 307 | + }; |
288 | 308 | } |
289 | 309 | } |
0 commit comments