-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removing a few variants on invokekustoquery. broken shit.
- Loading branch information
Showing
2 changed files
with
70 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace PowerShellKusto; | ||
|
||
internal static class Extensions | ||
{ | ||
internal static PSObject ToPSObject(this JObject entries) | ||
{ | ||
PSObject result = new(entries.Count); | ||
foreach (KeyValuePair<string, JToken?> entry in entries) | ||
{ | ||
switch (entry.Value) | ||
{ | ||
case JArray jArray: | ||
object?[] collection = PopulateFromJArray(jArray); | ||
result.Properties.Add(new PSNoteProperty(entry.Key, collection)); | ||
break; | ||
|
||
case JObject jObject: | ||
PSObject psobject = ToPSObject(jObject); | ||
result.Properties.Add(new PSNoteProperty(entry.Key, psobject)); | ||
break; | ||
|
||
case JValue jValue: | ||
result.Properties.Add(new PSNoteProperty(entry.Key, jValue.Value)); | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private static object?[] PopulateFromJArray(JArray jArray) | ||
{ | ||
object?[] result = new object[jArray.Count]; | ||
for (int index = 0; index < jArray.Count; index++) | ||
{ | ||
JToken? element = jArray[index]; | ||
switch (element) | ||
{ | ||
case JArray subJArray: | ||
object?[] subCollection = PopulateFromJArray(subJArray); | ||
result[index] = subCollection; | ||
break; | ||
|
||
case JObject jObject: | ||
PSObject psobject = ToPSObject(jObject); | ||
result[index] = psobject; | ||
break; | ||
|
||
case JValue jValue: | ||
result[index] = jValue.Value; | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters