mirror of
https://github.com/SamueleLorefice/ComfySharp
synced 2026-01-15 06:53:41 +00:00
Added extra logic to work on some edge cases. Still broken
This commit is contained in:
@@ -29,10 +29,12 @@ public class ComfyClient {
|
|||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
ConversionSettings settings = new();
|
if (dbGenerator is null) {
|
||||||
settings.Save( "conv_config.json");
|
ConversionSettings settings = new();
|
||||||
dbGenerator = new(settings);
|
settings.Save( "conv_config.json");
|
||||||
Console.WriteLine("created empty settings file");
|
dbGenerator = new(settings);
|
||||||
|
Console.WriteLine("created empty settings file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,4 +12,8 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="NLog" Version="5.2.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,25 +141,33 @@ 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 the elements inside the array are not strings, this is a list of objects and might require special handling
|
if (inputProperty.Value[0][0].GetArrayLength() >= 0) {
|
||||||
if (inputProperty.Value[0].EnumerateArray().Current.ValueKind != JsonValueKind.String) {
|
//if the elements inside the array are not strings, this is a list of objects and might require special handling
|
||||||
Console.WriteLine("Encountered a special case: {0}", inputProperty.Name);
|
if (inputProperty.Value[0][0].ValueKind != JsonValueKind.String) {
|
||||||
return;
|
Console.WriteLine("Encountered a special case: {0}", inputProperty.Name);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<string> enumValues = new(); //holds all the values of the enum, valid for both following cases
|
List<string> enumValues = new(); //holds all the values of the enum, valid for both following cases
|
||||||
inputProperty.Value[0].EnumerateArray().ToList().ForEach(value => enumValues.Add(value.ToString()));
|
inputProperty.Value[0].EnumerateArray().ToList().ForEach(value => enumValues.Add(value.ToString()));
|
||||||
|
|
||||||
// these are all lists of strings and not enums
|
// these are all lists of strings and not enums
|
||||||
if (settings.EnumConvertAsString.Contains(inputProperty.Name)) {
|
if (settings.EnumConvertAsString.Contains(inputProperty.Name)) {
|
||||||
AddKnownStringList(inputProperty.Name, enumValues);
|
AddKnownStringList(inputProperty.Name, enumValues);
|
||||||
|
} else {
|
||||||
|
AddKnownEnum(inputProperty.Name, enumValues);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
AddKnownEnum(inputProperty.Name, enumValues);
|
//if the array is empty, this is a list of unknown and might require special handling later on, for now, skip it
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user