Added extra logic to work on some edge cases. Still broken

This commit is contained in:
Samuele Lorefice
2023-12-19 02:31:07 +01:00
parent 45392a3a8a
commit c248140572
4 changed files with 42 additions and 19 deletions

View File

@@ -29,12 +29,14 @@ public class ComfyClient {
Console.WriteLine(e); Console.WriteLine(e);
} }
finally { finally {
if (dbGenerator is null) {
ConversionSettings settings = new(); ConversionSettings settings = new();
settings.Save( "conv_config.json"); settings.Save( "conv_config.json");
dbGenerator = new(settings); dbGenerator = new(settings);
Console.WriteLine("created empty settings file"); Console.WriteLine("created empty settings file");
} }
} }
}
public async Task<string[]?> GetEmbeddings() { public async Task<string[]?> GetEmbeddings() {
string[]? embeddings = null; string[]? embeddings = null;

View File

@@ -12,4 +12,8 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="5.2.7" />
</ItemGroup>
</Project> </Project>

View File

@@ -9,6 +9,7 @@ public class ConversionSettings {
[DataMember(IsRequired = true)] public List<string> EnumConvertAsString = new(); [DataMember(IsRequired = true)] public List<string> EnumConvertAsString = new();
[DataMember(IsRequired = true)] public List<string> EnumConvertAsBool = new(); [DataMember(IsRequired = true)] public List<string> EnumConvertAsBool = new();
static JsonSerializerOptions jsonOpt = new() { WriteIndented = true, IncludeFields = true }; static JsonSerializerOptions jsonOpt = new() { WriteIndented = true, IncludeFields = true };
public static ConversionSettings FromFile(string path) { public static ConversionSettings FromFile(string path) {
if (!File.Exists(path)) throw new FileNotFoundException("Could not find settings file", path); if (!File.Exists(path)) throw new FileNotFoundException("Could not find settings file", path);
string json = File.ReadAllText(path); string json = File.ReadAllText(path);

View File

@@ -85,8 +85,10 @@ public class NodeDBGenerator {
} }
} }
public void GenerateClasses(JsonDocument document) { public void GenerateClasses(JsonDocument document) {
foreach (var node in document.RootElement.EnumerateObject()) ScanNode(node); foreach (var node in document.RootElement.EnumerateObject())
ScanNode(node);
Console.WriteLine("List of recognized Types:"); Console.WriteLine("List of recognized Types:");
foreach (var knownType in knownTypes) { foreach (var knownType in knownTypes) {
@@ -108,11 +110,14 @@ public class NodeDBGenerator {
/// executed for a single node, progresses through the properties of the node /// executed for a single node, progresses through the properties of the node
/// </summary> /// </summary>
private void ScanNode(JsonProperty node) { private void ScanNode(JsonProperty node) {
#if DEBUG
Console.WriteLine("Scanning node: {0}", node.Name);
#endif
// each of this are top level properties of the node // each of this are top level properties of the node
foreach (var property in node.Value.EnumerateObject()) { foreach (var property in node.Value.EnumerateObject()) {
//if this is a list of input properties: //if this is a list of input properties:
if (property.Name == "input" && property.Value.ValueKind == JsonValueKind.Object) ScanInputs(property); if (property is { Name: "input", Value.ValueKind: JsonValueKind.Object }) ScanInputs(property);
else if (property.Name == "output" && property.Value.ValueKind == JsonValueKind.Array) ScanOutputs(property); else if (property is { Name: "output", Value.ValueKind: JsonValueKind.Array }) ScanOutputs(property);
} }
} }
@@ -120,6 +125,9 @@ public class NodeDBGenerator {
/// Executed on the input property inside a node /// Executed on the input property inside a node
/// </summary> /// </summary>
private void ScanInputs(JsonProperty input) { private void ScanInputs(JsonProperty input) {
#if DEBUG
Console.WriteLine("Scanning inputs of node: {0}", input.Name);
#endif
foreach (var inputType in input.Value.EnumerateObject()) { foreach (var inputType in input.Value.EnumerateObject()) {
//these are related to the nodes themselves and useless for us //these are related to the nodes themselves and useless for us
if (inputType.Name == "hidden") continue; if (inputType.Name == "hidden") continue;
@@ -133,13 +141,17 @@ public class NodeDBGenerator {
/// Executed for each of the elements inside a required or optional input /// Executed for each of the elements inside a required or optional input
/// </summary> /// </summary>
private void ScanInputField(JsonProperty inputProperty) { private void ScanInputField(JsonProperty inputProperty) {
#if DEBUG
Console.WriteLine("Scanning input field: {0}", inputProperty.Name);
#endif
// if element 0 is a string, this is a type // if element 0 is a string, this is a type
if (inputProperty.Value[0].ValueKind == JsonValueKind.String) if (inputProperty.Value[0].ValueKind == JsonValueKind.String)
AddKnownType(inputProperty.Value[0].ToString()); AddKnownType(inputProperty.Value[0].ToString());
// else, if element 0 is an array, this is an enum or a list. // else, if element 0 is an array, this is an enum or a list.
else if (inputProperty.Value[0].ValueKind == JsonValueKind.Array) { else if (inputProperty.Value[0].ValueKind == JsonValueKind.Array) {
if (inputProperty.Value[0][0].GetArrayLength() >= 0) {
//if the elements inside the array are not strings, this is a list of objects and might require special handling //if the elements inside the array are not strings, this is a list of objects and might require special handling
if (inputProperty.Value[0].EnumerateArray().Current.ValueKind != JsonValueKind.String) { if (inputProperty.Value[0][0].ValueKind != JsonValueKind.String) {
Console.WriteLine("Encountered a special case: {0}", inputProperty.Name); Console.WriteLine("Encountered a special case: {0}", inputProperty.Name);
return; return;
} }
@@ -153,6 +165,10 @@ public class NodeDBGenerator {
} else { } else {
AddKnownEnum(inputProperty.Name, enumValues); AddKnownEnum(inputProperty.Name, enumValues);
} }
} else {
//if the array is empty, this is a list of unknown and might require special handling later on, for now, skip it
return;
}
} }
} }