using System.Globalization; using NodePipeline.Abstractions; using NodePipeline.Abstractions.Exceptions.NodeFactory; using NodePipeline.Abstractions.Interfaces; using NodePipeline.Abstractions.Interfaces.Nodes; using NodePipeline.Configuration.Abstractions.Models.Execute; using NodePipeline.Engine.Abstractions; using NodePipeline.Engine.NodeFields; using NodePipeline.Engine.Utils; using NodePipeline.Engine.Abstractions.Validation; // ReSharper disable CheckNamespace // ReSharper disable ConvertTypeCheckPatternToNullCheck // ReSharper disable RedundantCast // ReSharper disable RedundantNameQualifier // ReSharper disable ReturnTypeCanBeNotNullable // ReSharper disable UnusedMember.Local // ReSharper disable UnusedParameter.Local #nullable enable namespace NodePipeline.Engine.Generated; public sealed class GeneratedNodeFactory : INodeFactory { public Dictionary> NodeFactories { get; set; } = new(); public IPipelineLocalizationProvider PipelineLocalizationProvider { get; set; } = new PipelineLocalizationProvider(); public INode CreateNode(string pipelineId, NodeConfig config) { INode? node; if (NodeFactories.TryGetValue(config.Type, out var f)) { node = f(); InitializeNodeFields(pipelineId, node, config.Id); return node; } switch (config.Type) { case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource2"): throw new NodeCanNotBeInitializedWithoutFactoryException(pipelineId, config.Type, config.Id); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource"): node = new global::NodePipeline.Application.Nodes.FileImageSourceNode(); break; case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.GaussianBlur"): node = new global::NodePipeline.Application.Nodes.GaussianBlurNode(); break; case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.MaskApply"): node = new global::NodePipeline.Application.Nodes.MaskApplyNode(); break; case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.SaveImage2"): throw new NodeCanNotBeInitializedWithoutFactoryException(pipelineId, config.Type, config.Id); case "FileImageDestination": node = new global::NodePipeline.Application.Nodes.SaveImageNode(); break; default: throw new NodeNotFoundException(pipelineId, config.Type, config.Id); } InitializeNodeFields(pipelineId, node, config.Id); return node ?? throw new NodeWasNotInitializedException(pipelineId, config.Type, config.Id); } private void InitializeNodeFields(string pipelineId, INode node, string nodeId) { switch (node) { case global::NodePipeline.Application.Nodes.FileImageSource2Node t1: Initialize__NodePipeline_Application_Nodes_FileImageSource2Node__NodeFields(t1, nodeId); break; case global::NodePipeline.Application.Nodes.FileImageSourceNode t2: Initialize__NodePipeline_Application_Nodes_FileImageSourceNode__NodeFields(t2, nodeId); break; case global::NodePipeline.Application.Nodes.GaussianBlurNode t3: Initialize__NodePipeline_Application_Nodes_GaussianBlurNode__NodeFields(t3, nodeId); break; case global::NodePipeline.Application.Nodes.MaskApplyNode t4: Initialize__NodePipeline_Application_Nodes_MaskApplyNode__NodeFields(t4, nodeId); break; case global::NodePipeline.Application.Nodes.SaveImage2Node t5: Initialize__NodePipeline_Application_Nodes_SaveImage2Node__NodeFields(t5, nodeId); break; case global::NodePipeline.Application.Nodes.SaveImageNode t6: Initialize__NodePipeline_Application_Nodes_SaveImageNode__NodeFields(t6, nodeId); break; default: throw new NodeNotFoundException(pipelineId, node.GetType().Name, nodeId); } } private static void Initialize__NodePipeline_Application_Nodes_FileImageSource2Node__NodeFields(global::NodePipeline.Application.Nodes.FileImageSource2Node node, string nodeId) { node.Output = new NodeField() { Name = "Output", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Output", FieldDirection.Output), Direction = FieldDirection.Output, // Description intentionally omitted for runtime }; } private static void Initialize__NodePipeline_Application_Nodes_FileImageSourceNode__NodeFields(global::NodePipeline.Application.Nodes.FileImageSourceNode node, string nodeId) { node.FileName = new NodeField() { Name = "FileName", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "FileName", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; node.Extension = new NodeField() { Name = "Extension", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Extension", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; node.Directory = new NodeField() { Name = "Directory", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Directory", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; node.Output = new NodeField() { Name = "Output", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Output", FieldDirection.Output), Direction = FieldDirection.Output, // Description intentionally omitted for runtime }; node.ImageLoaded = new NodeField() { Name = "ImageLoaded", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "ImageLoaded", FieldDirection.Output), Direction = FieldDirection.Output, // Description intentionally omitted for runtime }; } private static void Initialize__NodePipeline_Application_Nodes_GaussianBlurNode__NodeFields(global::NodePipeline.Application.Nodes.GaussianBlurNode node, string nodeId) { node.Input = new NodeField() { Name = "Input", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Input", FieldDirection.Input), Direction = FieldDirection.Input, // Description intentionally omitted for runtime }; node.Radius = new NodeField() { Name = "Radius", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Radius", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; node.Output = new NodeField() { Name = "Output", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Output", FieldDirection.Output), Direction = FieldDirection.Output, // Description intentionally omitted for runtime }; } private static void Initialize__NodePipeline_Application_Nodes_MaskApplyNode__NodeFields(global::NodePipeline.Application.Nodes.MaskApplyNode node, string nodeId) { node.InputImage = new NodeField() { Name = "InputImage", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "InputImage", FieldDirection.Input), Direction = FieldDirection.Input, // Description intentionally omitted for runtime }; node.Mask = new NodeField() { Name = "Mask", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Mask", FieldDirection.Input), Direction = FieldDirection.Input, // Description intentionally omitted for runtime }; node.HasMask = new NodeField() { Name = "HasMask", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "HasMask", FieldDirection.Input), Direction = FieldDirection.Input, // Description intentionally omitted for runtime }; node.Mode = new NodeField() { Name = "Mode", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Mode", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; node.OutputImage = new NodeField() { Name = "OutputImage", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "OutputImage", FieldDirection.Output), Direction = FieldDirection.Output, // Description intentionally omitted for runtime }; } private static void Initialize__NodePipeline_Application_Nodes_SaveImage2Node__NodeFields(global::NodePipeline.Application.Nodes.SaveImage2Node node, string nodeId) { node.Input = new NodeField() { Name = "Input", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Input", FieldDirection.Input), Direction = FieldDirection.Input, // Description intentionally omitted for runtime }; } private static void Initialize__NodePipeline_Application_Nodes_SaveImageNode__NodeFields(global::NodePipeline.Application.Nodes.SaveImageNode node, string nodeId) { node.Input = new NodeField() { Name = "input", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "input", FieldDirection.Input), Direction = FieldDirection.Input, // Description intentionally omitted for runtime }; node.FileName = new NodeField() { Name = "FileName", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "FileName", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; node.Extension = new NodeField() { Name = "Extension", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Extension", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; node.Directory = new NodeField() { Name = "Directory", Code = NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Directory", FieldDirection.Parameter), Direction = FieldDirection.Parameter, // Description intentionally omitted for runtime }; } public IEnumerable GetParameterCodes(string nodeType) { switch (nodeType) { case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource2"): return GetParameterCodesFor__NodePipeline_Application_Nodes_FileImageSource2Node__Node(); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource"): return GetParameterCodesFor__NodePipeline_Application_Nodes_FileImageSourceNode__Node(); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.GaussianBlur"): return GetParameterCodesFor__NodePipeline_Application_Nodes_GaussianBlurNode__Node(); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.MaskApply"): return GetParameterCodesFor__NodePipeline_Application_Nodes_MaskApplyNode__Node(); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.SaveImage2"): return GetParameterCodesFor__NodePipeline_Application_Nodes_SaveImage2Node__Node(); case "FileImageDestination": return GetParameterCodesFor__NodePipeline_Application_Nodes_SaveImageNode__Node(); default: throw new NodeTypeNotFoundException(nodeType); } } private IEnumerable GetParameterCodesFor__NodePipeline_Application_Nodes_FileImageSource2Node__Node() { return []; } private IEnumerable GetParameterCodesFor__NodePipeline_Application_Nodes_FileImageSourceNode__Node() { return [ "FileName", "Extension", "Directory", ]; } private IEnumerable GetParameterCodesFor__NodePipeline_Application_Nodes_GaussianBlurNode__Node() { return [ "Radius", ]; } private IEnumerable GetParameterCodesFor__NodePipeline_Application_Nodes_MaskApplyNode__Node() { return [ "Mode", ]; } private IEnumerable GetParameterCodesFor__NodePipeline_Application_Nodes_SaveImage2Node__Node() { return []; } private IEnumerable GetParameterCodesFor__NodePipeline_Application_Nodes_SaveImageNode__Node() { return [ "FileName", "Extension", "Directory", ]; } public object? ReadParameterValue(string pipelineId, string nodeId, string nodeType, string parameterName, string? valueString) { switch (nodeType) { case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource2"): return ReadParameterValueFrom__NodePipeline_Application_Nodes_FileImageSource2Node__Node(pipelineId, nodeType, nodeId, parameterName, valueString); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource"): return ReadParameterValueFrom__NodePipeline_Application_Nodes_FileImageSourceNode__Node(pipelineId, nodeType, nodeId, parameterName, valueString); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.GaussianBlur"): return ReadParameterValueFrom__NodePipeline_Application_Nodes_GaussianBlurNode__Node(pipelineId, nodeType, nodeId, parameterName, valueString); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.MaskApply"): return ReadParameterValueFrom__NodePipeline_Application_Nodes_MaskApplyNode__Node(pipelineId, nodeType, nodeId, parameterName, valueString); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.SaveImage2"): return ReadParameterValueFrom__NodePipeline_Application_Nodes_SaveImage2Node__Node(pipelineId, nodeType, nodeId, parameterName, valueString); case "FileImageDestination": return ReadParameterValueFrom__NodePipeline_Application_Nodes_SaveImageNode__Node(pipelineId, nodeType, nodeId, parameterName, valueString); default: throw new NodeTypeNotFoundException(nodeType); } } private static object? ReadParameterValueFrom__NodePipeline_Application_Nodes_FileImageSource2Node__Node(string pipelineId, string nodeType, string nodeId, string parameterName, string? valueString) { switch (parameterName) { default: throw new NodeParameterNotFoundException(pipelineId, parameterName, nodeType, nodeId); } } private static object? ReadParameterValueFrom__NodePipeline_Application_Nodes_FileImageSourceNode__Node(string pipelineId, string nodeType, string nodeId, string parameterName, string? valueString) { switch (parameterName) { case "FileName": return ParseParameter(valueString); case "Extension": return ParseParameter(valueString); case "Directory": return ParseParameter(valueString); default: throw new NodeParameterNotFoundException(pipelineId, parameterName, nodeType, nodeId); } } private static object? ReadParameterValueFrom__NodePipeline_Application_Nodes_GaussianBlurNode__Node(string pipelineId, string nodeType, string nodeId, string parameterName, string? valueString) { switch (parameterName) { case "Radius": return ParseParameter(valueString); default: throw new NodeParameterNotFoundException(pipelineId, parameterName, nodeType, nodeId); } } private static object? ReadParameterValueFrom__NodePipeline_Application_Nodes_MaskApplyNode__Node(string pipelineId, string nodeType, string nodeId, string parameterName, string? valueString) { switch (parameterName) { case "Mode": return ParseParameter(valueString); default: throw new NodeParameterNotFoundException(pipelineId, parameterName, nodeType, nodeId); } } private static object? ReadParameterValueFrom__NodePipeline_Application_Nodes_SaveImage2Node__Node(string pipelineId, string nodeType, string nodeId, string parameterName, string? valueString) { switch (parameterName) { default: throw new NodeParameterNotFoundException(pipelineId, parameterName, nodeType, nodeId); } } private static object? ReadParameterValueFrom__NodePipeline_Application_Nodes_SaveImageNode__Node(string pipelineId, string nodeType, string nodeId, string parameterName, string? valueString) { switch (parameterName) { case "FileName": return ParseParameter(valueString); case "Extension": return ParseParameter(valueString); case "Directory": return ParseParameter(valueString); default: throw new NodeParameterNotFoundException(pipelineId, parameterName, nodeType, nodeId); } } public Dictionary GetAllPorts(string pipelineId, HashSet nodeTypes, Dictionary> nodeList) { var result = new Dictionary(); foreach (var nodeType in nodeTypes) { if (!nodeList.TryGetValue(nodeType, out var ids)) continue; foreach (var nodeId in ids) { var ports = GetNodePorts(pipelineId, nodeType, nodeId); foreach (var kv in ports) result.Add(kv.Key, kv.Value); } } return result; } public IEnumerable GetNodeInputPorts(string pipelineId, string nodeType, string nodeId) { var ports = GetNodePorts(pipelineId, nodeType, nodeId); foreach (var kv in ports) if (kv.Key.Input) yield return kv.Value; } private Dictionary GetNodePorts(string pipelineId, string nodeType, string nodeId) { switch (nodeType) { case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource2"): return Get__NodePipeline_Application_Nodes_FileImageSource2Node__NodePorts(nodeId); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource"): return Get__NodePipeline_Application_Nodes_FileImageSourceNode__NodePorts(nodeId); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.GaussianBlur"): return Get__NodePipeline_Application_Nodes_GaussianBlurNode__NodePorts(nodeId); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.MaskApply"): return Get__NodePipeline_Application_Nodes_MaskApplyNode__NodePorts(nodeId); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.SaveImage2"): return Get__NodePipeline_Application_Nodes_SaveImage2Node__NodePorts(nodeId); case "FileImageDestination": return Get__NodePipeline_Application_Nodes_SaveImageNode__NodePorts(nodeId); default: throw new NodeNotFoundException(pipelineId, nodeType, nodeId); } } private static Dictionary Get__NodePipeline_Application_Nodes_FileImageSource2Node__NodePorts(string nodeId) { return new Dictionary() { { new NodePortKey(nodeId, "Output", false), new NodePortInfo("Output", typeof(global::NodePipeline.Application.ImageBuffer), false, false, false, false) }, }; } private static Dictionary Get__NodePipeline_Application_Nodes_FileImageSourceNode__NodePorts(string nodeId) { return new Dictionary() { { new NodePortKey(nodeId, "Output", false), new NodePortInfo("Output", typeof(global::NodePipeline.Application.ImageBuffer), true, false, false, false) }, { new NodePortKey(nodeId, "ImageLoaded", false), new NodePortInfo("ImageLoaded", typeof(bool), false, false, false, false) }, }; } private static Dictionary Get__NodePipeline_Application_Nodes_GaussianBlurNode__NodePorts(string nodeId) { return new Dictionary() { { new NodePortKey(nodeId, "Input", true), new NodePortInfo("Input", typeof(global::NodePipeline.Application.ImageBuffer), false, false, false, true) }, { new NodePortKey(nodeId, "Output", false), new NodePortInfo("Output", typeof(global::NodePipeline.Application.ImageBuffer), false, false, false, false) }, }; } private static Dictionary Get__NodePipeline_Application_Nodes_MaskApplyNode__NodePorts(string nodeId) { return new Dictionary() { { new NodePortKey(nodeId, "InputImage", true), new NodePortInfo("InputImage", typeof(global::NodePipeline.Application.ImageBuffer), false, true, false, true) }, { new NodePortKey(nodeId, "Mask", true), new NodePortInfo("Mask", typeof(global::NodePipeline.Application.ImageBuffer), false, true, false, true) }, { new NodePortKey(nodeId, "HasMask", true), new NodePortInfo("HasMask", typeof(bool), false, true, true, true) }, { new NodePortKey(nodeId, "OutputImage", false), new NodePortInfo("OutputImage", typeof(global::NodePipeline.Application.ImageBuffer), false, false, false, false) }, }; } private static Dictionary Get__NodePipeline_Application_Nodes_SaveImage2Node__NodePorts(string nodeId) { return new Dictionary() { { new NodePortKey(nodeId, "Input", true), new NodePortInfo("Input", typeof(global::NodePipeline.Application.ImageBuffer), false, false, false, true) }, }; } private static Dictionary Get__NodePipeline_Application_Nodes_SaveImageNode__NodePorts(string nodeId) { return new Dictionary() { { new NodePortKey(nodeId, "input", true), new NodePortInfo("input", typeof(global::NodePipeline.Application.ImageBuffer), false, false, false, true) }, }; } private IReadOnlyDictionary GetNodeOutputs(string pipelineId, string nodeId, INode node) { switch (node) { case global::NodePipeline.Application.Nodes.FileImageSource2Node t1: return Get__NodePipeline_Application_Nodes_FileImageSource2Node__NodeOutputs(nodeId, t1); case global::NodePipeline.Application.Nodes.FileImageSourceNode t2: return Get__NodePipeline_Application_Nodes_FileImageSourceNode__NodeOutputs(nodeId, t2); case global::NodePipeline.Application.Nodes.GaussianBlurNode t3: return Get__NodePipeline_Application_Nodes_GaussianBlurNode__NodeOutputs(nodeId, t3); case global::NodePipeline.Application.Nodes.MaskApplyNode t4: return Get__NodePipeline_Application_Nodes_MaskApplyNode__NodeOutputs(nodeId, t4); case global::NodePipeline.Application.Nodes.SaveImage2Node t5: return Get__NodePipeline_Application_Nodes_SaveImage2Node__NodeOutputs(nodeId, t5); case global::NodePipeline.Application.Nodes.SaveImageNode t6: return Get__NodePipeline_Application_Nodes_SaveImageNode__NodeOutputs(nodeId, t6); default: throw new NodeNotFoundException(pipelineId, node.GetType().Name, nodeId); } } private IReadOnlyDictionary Get__NodePipeline_Application_Nodes_FileImageSource2Node__NodeOutputs(string nodeId, global::NodePipeline.Application.Nodes.FileImageSource2Node node) { return new Dictionary { { NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Output", FieldDirection.Output), node.Output }, }; } private IReadOnlyDictionary Get__NodePipeline_Application_Nodes_FileImageSourceNode__NodeOutputs(string nodeId, global::NodePipeline.Application.Nodes.FileImageSourceNode node) { return new Dictionary { { NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Output", FieldDirection.Output), node.Output }, { NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "ImageLoaded", FieldDirection.Output), node.ImageLoaded }, }; } private IReadOnlyDictionary Get__NodePipeline_Application_Nodes_GaussianBlurNode__NodeOutputs(string nodeId, global::NodePipeline.Application.Nodes.GaussianBlurNode node) { return new Dictionary { { NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "Output", FieldDirection.Output), node.Output }, }; } private IReadOnlyDictionary Get__NodePipeline_Application_Nodes_MaskApplyNode__NodeOutputs(string nodeId, global::NodePipeline.Application.Nodes.MaskApplyNode node) { return new Dictionary { { NodeFieldCodeGenerator.GenerateFieldCode(nodeId, "OutputImage", FieldDirection.Output), node.OutputImage }, }; } private IReadOnlyDictionary Get__NodePipeline_Application_Nodes_SaveImage2Node__NodeOutputs(string nodeId, global::NodePipeline.Application.Nodes.SaveImage2Node node) { return new Dictionary(); } private IReadOnlyDictionary Get__NodePipeline_Application_Nodes_SaveImageNode__NodeOutputs(string nodeId, global::NodePipeline.Application.Nodes.SaveImageNode node) { return new Dictionary(); } public void ConnectPorts(string pipelineId, TNode node, string nodeId, Dictionary inputs, IReadOnlyDictionary createdNodes) where TNode : INode { switch (node) { case global::NodePipeline.Application.Nodes.FileImageSource2Node t1: Connect__NodePipeline_Application_Nodes_FileImageSource2Node__NodePorts(pipelineId, t1, nodeId, inputs, createdNodes); break; case global::NodePipeline.Application.Nodes.FileImageSourceNode t2: Connect__NodePipeline_Application_Nodes_FileImageSourceNode__NodePorts(pipelineId, t2, nodeId, inputs, createdNodes); break; case global::NodePipeline.Application.Nodes.GaussianBlurNode t3: Connect__NodePipeline_Application_Nodes_GaussianBlurNode__NodePorts(pipelineId, t3, nodeId, inputs, createdNodes); break; case global::NodePipeline.Application.Nodes.MaskApplyNode t4: Connect__NodePipeline_Application_Nodes_MaskApplyNode__NodePorts(pipelineId, t4, nodeId, inputs, createdNodes); break; case global::NodePipeline.Application.Nodes.SaveImage2Node t5: Connect__NodePipeline_Application_Nodes_SaveImage2Node__NodePorts(pipelineId, t5, nodeId, inputs, createdNodes); break; case global::NodePipeline.Application.Nodes.SaveImageNode t6: Connect__NodePipeline_Application_Nodes_SaveImageNode__NodePorts(pipelineId, t6, nodeId, inputs, createdNodes); break; default: throw new NodeNotFoundException(pipelineId, node.GetType().Name, nodeId); } } private PortConnectionInfo? TryConnectPorts(string pipelineId, string nodeId, string nodeType, INodeField? nodeInput, string nodeInputName, Dictionary inputs, string inputKey, IReadOnlyDictionary createdNodes, bool isRequired = false) where T : notnull { if (!inputs.TryGetValue(inputKey, out var connection)) return !isRequired ? null : throw new InputPortHasNoRequiredConnectionException(pipelineId, inputKey, nodeId, nodeType); var fromNodeId = connection.NodeId; var fromPortName = connection.OutputName; if (nodeInput == null) throw new InputPortNotFoundException(pipelineId, inputKey, nodeId, nodeType); if (!createdNodes.TryGetValue(fromNodeId, out var fromNode)) throw new OutputPortNodeNotFoundException(pipelineId, fromNodeId, nodeId); var outputs = GetNodeOutputs(pipelineId, fromNodeId, fromNode); var outputFieldKey = NodeFieldCodeGenerator.GenerateFieldCode(fromNodeId, fromPortName, FieldDirection.Output); if (!outputs.TryGetValue(outputFieldKey, out var outputFieldObj)) throw new OutputPortNotFoundException(pipelineId, fromPortName, fromNodeId, nodeId); var fromNodeType = GetNodeType(pipelineId, fromNodeId, fromNode); if (outputFieldObj is INodeField outStrict && nodeInput is INodeField inStrict) { PortConnector.ConnectStatic(outStrict, inStrict); return new PortConnectionInfo(true, outputFieldObj, fromPortName, fromNodeType, fromNodeId); } return new PortConnectionInfo(false, outputFieldObj, fromPortName, fromNodeType, fromNodeId); } private void Connect__NodePipeline_Application_Nodes_FileImageSource2Node__NodePorts(string pipelineId, global::NodePipeline.Application.Nodes.FileImageSource2Node node, string nodeId, Dictionary inputs, IReadOnlyDictionary createdNodes) { } private void Connect__NodePipeline_Application_Nodes_FileImageSourceNode__NodePorts(string pipelineId, global::NodePipeline.Application.Nodes.FileImageSourceNode node, string nodeId, Dictionary inputs, IReadOnlyDictionary createdNodes) { } private void Connect__NodePipeline_Application_Nodes_GaussianBlurNode__NodePorts(string pipelineId, global::NodePipeline.Application.Nodes.GaussianBlurNode node, string nodeId, Dictionary inputs, IReadOnlyDictionary createdNodes) { ConnectPortsStruct(pipelineId, nodeId, "NodePipeline.Application.Nodes.GaussianBlurNode", node.Input, nameof(node.Input), inputs, "Input", createdNodes, disallowNullableOutput: false, isRequired: true); } private void Connect__NodePipeline_Application_Nodes_MaskApplyNode__NodePorts(string pipelineId, global::NodePipeline.Application.Nodes.MaskApplyNode node, string nodeId, Dictionary inputs, IReadOnlyDictionary createdNodes) { ConnectPortsStruct(pipelineId, nodeId, "NodePipeline.Application.Nodes.MaskApplyNode", node.InputImage, nameof(node.InputImage), inputs, "InputImage", createdNodes, disallowNullableOutput: false, isRequired: true); ConnectPortsStruct(pipelineId, nodeId, "NodePipeline.Application.Nodes.MaskApplyNode", node.Mask, nameof(node.Mask), inputs, "Mask", createdNodes, disallowNullableOutput: false, isRequired: true); ConnectPortsStruct(pipelineId, nodeId, "NodePipeline.Application.Nodes.MaskApplyNode", node.HasMask, nameof(node.HasMask), inputs, "HasMask", createdNodes, disallowNullableOutput: true, isRequired: true); } private void Connect__NodePipeline_Application_Nodes_SaveImage2Node__NodePorts(string pipelineId, global::NodePipeline.Application.Nodes.SaveImage2Node node, string nodeId, Dictionary inputs, IReadOnlyDictionary createdNodes) { ConnectPortsStruct(pipelineId, nodeId, "NodePipeline.Application.Nodes.SaveImage2Node", node.Input, nameof(node.Input), inputs, "Input", createdNodes, disallowNullableOutput: false, isRequired: true); } private void Connect__NodePipeline_Application_Nodes_SaveImageNode__NodePorts(string pipelineId, global::NodePipeline.Application.Nodes.SaveImageNode node, string nodeId, Dictionary inputs, IReadOnlyDictionary createdNodes) { ConnectPortsStruct(pipelineId, nodeId, "NodePipeline.Application.Nodes.SaveImageNode", node.Input, nameof(node.Input), inputs, "input", createdNodes, disallowNullableOutput: false, isRequired: true); } private void ConnectPortsStruct(string pipelineId, string nodeId,string nodeType, INodeField? nodeInput, string nodeInputName, Dictionary inputs, string inputKey, IReadOnlyDictionary createdNodes, bool disallowNullableOutput = false, bool isRequired = false) where T : struct { var portConnectionInfo = TryConnectPorts(pipelineId, nodeId, nodeType, nodeInput, nodeInputName, inputs, inputKey, createdNodes, isRequired); if (portConnectionInfo is null || portConnectionInfo.Connected) return; if (typeof(T).IsValueType && portConnectionInfo.OutputFieldObj is INodeField outputField) { PortConnector.ConnectRuntimeFromNullableStruct(outputField, nodeInput!, nodeId, inputKey, portConnectionInfo.FromNodeId, portConnectionInfo.FromPortName); return; } if (portConnectionInfo.OutputFieldObj is INodeField outNullable && nodeInput is INodeField inNullable) { PortConnector.ConnectRuntimeBothNullable(outNullable, inNullable); return; } if (portConnectionInfo.OutputFieldObj is INodeField outNToStrict && nodeInput != null) { if (disallowNullableOutput) { throw new NonNullableInputRestrictsConnectionToNullableOutputException(pipelineId, nodeId, nodeType, inputKey, portConnectionInfo.FromPortName, portConnectionInfo.FromNodeId); } PortConnector.ConnectRuntimeFromNullableStruct(outNToStrict, nodeInput, currentNodeId: nodeId, inputPortName: inputKey, sourceNodeId: portConnectionInfo.FromNodeId, outputPortName: portConnectionInfo.FromPortName); return; } if (portConnectionInfo.OutputFieldObj is INodeField outStrictToN && nodeInput is INodeField inNullable2) { PortConnector.ConnectRuntimeToNullableStruct(outStrictToN, inNullable2); return; } throw new PortsTypeMismatchException(pipelineId, inputKey, nodeType, nodeId, portConnectionInfo.FromPortName, portConnectionInfo.FromNodeType, portConnectionInfo.FromNodeId); } private void ConnectPortsClass(string pipelineId, string nodeId,string nodeType, INodeField? nodeInput, string nodeInputName, Dictionary inputs, string inputKey, IReadOnlyDictionary createdNodes, bool disallowNullableOutput = false, bool isRequired = false) where T : class { var portConnectionInfo = TryConnectPorts(pipelineId, nodeId, nodeType, nodeInput, nodeInputName, inputs, inputKey, createdNodes, isRequired); if (portConnectionInfo is null || portConnectionInfo.Connected) return; if (!typeof(T).IsValueType && portConnectionInfo.OutputFieldObj is INodeField outputField) { PortConnector.ConnectRuntimeFromNullableClass(outputField, nodeInput!, nodeId, inputKey, portConnectionInfo.FromNodeId, portConnectionInfo.FromPortName); return; } if (portConnectionInfo.OutputFieldObj is INodeField outNullable && nodeInput is INodeField inNullable) { PortConnector.ConnectRuntimeBothNullable(outNullable, (INodeField)inNullable); return; } if (portConnectionInfo.OutputFieldObj is INodeField outNToStrict && nodeInput != null) { if (disallowNullableOutput) { throw new NonNullableInputRestrictsConnectionToNullableOutputException(pipelineId, nodeId, nodeType, inputKey, portConnectionInfo.FromPortName, portConnectionInfo.FromNodeId); } PortConnector.ConnectRuntimeFromNullableClass(outNToStrict, nodeInput, currentNodeId: nodeId, inputPortName: inputKey, sourceNodeId: portConnectionInfo.FromNodeId, outputPortName: portConnectionInfo.FromPortName); return; } if (portConnectionInfo.OutputFieldObj is INodeField outStrictToN && nodeInput is INodeField inNullable2) { PortConnector.ConnectRuntimeToNullableClass(outStrictToN, (INodeField)inNullable2); return; } throw new PortsTypeMismatchException(pipelineId, inputKey, nodeType, nodeId, portConnectionInfo.FromPortName, portConnectionInfo.FromNodeType, portConnectionInfo.FromNodeId); } private static T? ParseParameter(string? valueString) { var type = typeof(T); if (type == typeof(string)) return valueString is not null ? (T)(object)valueString : default; if (string.IsNullOrEmpty(valueString)) return default; if (type == typeof(int)) return (T)(object)int.Parse(valueString); if (type == typeof(double)) return (T)(object)double.Parse(valueString, CultureInfo.InvariantCulture); if (type == typeof(bool)) return (T)(object)bool.Parse(valueString); if (type == typeof(global::NodePipeline.Application.Nodes.MaskMode)) return (T)(object)Enum.Parse(valueString); throw new NotSupportedException(type.Name); } public object? GetParameterDefaultValue(string nodeType, string parameterName) { switch (nodeType) { case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource2"): return GetParameterDefaultValueFor__NodePipeline_Application_Nodes_FileImageSource2Node__Node(parameterName); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource"): return GetParameterDefaultValueFor__NodePipeline_Application_Nodes_FileImageSourceNode__Node(parameterName); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.GaussianBlur"): return GetParameterDefaultValueFor__NodePipeline_Application_Nodes_GaussianBlurNode__Node(parameterName); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.MaskApply"): return GetParameterDefaultValueFor__NodePipeline_Application_Nodes_MaskApplyNode__Node(parameterName); case var t when t == NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.SaveImage2"): return GetParameterDefaultValueFor__NodePipeline_Application_Nodes_SaveImage2Node__Node(parameterName); case "FileImageDestination": return GetParameterDefaultValueFor__NodePipeline_Application_Nodes_SaveImageNode__Node(parameterName); default: throw new NodeParameterNotFoundException(parameterName, nodeType); } } private static object? GetParameterDefaultValueFor__NodePipeline_Application_Nodes_FileImageSource2Node__Node(string parameterName) { switch (parameterName) { default: throw new NodeParameterNotFoundException(parameterName, "NodePipeline.Application.Nodes.FileImageSource2"); } } private static object? GetParameterDefaultValueFor__NodePipeline_Application_Nodes_FileImageSourceNode__Node(string parameterName) { switch (parameterName) { case "FileName": return GetDefaultValue(); case "Extension": return GetDefaultValue(); case "Directory": return GetDefaultValue(); default: throw new NodeParameterNotFoundException(parameterName, "NodePipeline.Application.Nodes.FileImageSource"); } } private static object? GetParameterDefaultValueFor__NodePipeline_Application_Nodes_GaussianBlurNode__Node(string parameterName) { switch (parameterName) { case "Radius": return GetDefaultValue(); default: throw new NodeParameterNotFoundException(parameterName, "NodePipeline.Application.Nodes.GaussianBlur"); } } private static object? GetParameterDefaultValueFor__NodePipeline_Application_Nodes_MaskApplyNode__Node(string parameterName) { switch (parameterName) { case "Mode": return GetDefaultValue(); default: throw new NodeParameterNotFoundException(parameterName, "NodePipeline.Application.Nodes.MaskApply"); } } private static object? GetParameterDefaultValueFor__NodePipeline_Application_Nodes_SaveImage2Node__Node(string parameterName) { switch (parameterName) { default: throw new NodeParameterNotFoundException(parameterName, "NodePipeline.Application.Nodes.SaveImage2"); } } private static object? GetParameterDefaultValueFor__NodePipeline_Application_Nodes_SaveImageNode__Node(string parameterName) { switch (parameterName) { case "FileName": return GetDefaultValue(); case "Extension": return ".jpg"; case "Directory": return GetDefaultValue(); default: throw new NodeParameterNotFoundException(parameterName, "FileImageDestination"); } } private static T? GetDefaultValue() { var type = typeof(T); if (type == typeof(string)) return (T)(object)string.Empty; if (type == typeof(int)) return (T)(object)0; if (type == typeof(double)) return (T)(object)0d; if (type == typeof(decimal)) return (T)(object)0m; if (type == typeof(bool)) return (T)(object)false; if (type == typeof(Guid)) return (T)(object)Guid.Empty; if (type.IsEnum) return default; throw new NotSupportedException(type.Name); } public void SetNodeParametersValues(string pipelineId, TNode node, string nodeId, Dictionary parameters) where TNode : INode { switch (node) { case global::NodePipeline.Application.Nodes.FileImageSource2Node t1: Set__NodePipeline_Application_Nodes_FileImageSource2Node__NodeParametersValues(t1, nodeId, parameters); break; case global::NodePipeline.Application.Nodes.FileImageSourceNode t2: Set__NodePipeline_Application_Nodes_FileImageSourceNode__NodeParametersValues(t2, nodeId, parameters); break; case global::NodePipeline.Application.Nodes.GaussianBlurNode t3: Set__NodePipeline_Application_Nodes_GaussianBlurNode__NodeParametersValues(t3, nodeId, parameters); break; case global::NodePipeline.Application.Nodes.MaskApplyNode t4: Set__NodePipeline_Application_Nodes_MaskApplyNode__NodeParametersValues(t4, nodeId, parameters); break; case global::NodePipeline.Application.Nodes.SaveImage2Node t5: Set__NodePipeline_Application_Nodes_SaveImage2Node__NodeParametersValues(t5, nodeId, parameters); break; case global::NodePipeline.Application.Nodes.SaveImageNode t6: Set__NodePipeline_Application_Nodes_SaveImageNode__NodeParametersValues(t6, nodeId, parameters); break; default: throw new NodeNotFoundException(pipelineId, node.GetType().Name, nodeId); } } private static void Set__NodePipeline_Application_Nodes_FileImageSource2Node__NodeParametersValues(global::NodePipeline.Application.Nodes.FileImageSource2Node node, string nodeId, Dictionary parameters) { } private static void Set__NodePipeline_Application_Nodes_FileImageSourceNode__NodeParametersValues(global::NodePipeline.Application.Nodes.FileImageSourceNode node, string nodeId, Dictionary parameters) { if (parameters.TryGetValue("FileName", out var val1) && val1 is string typedVal1) node.FileName.Value = typedVal1; if (parameters.TryGetValue("Extension", out var val2) && val2 is string typedVal2) node.Extension.Value = typedVal2; if (parameters.TryGetValue("Directory", out var val3) && val3 is string typedVal3) node.Directory.Value = typedVal3; } private static void Set__NodePipeline_Application_Nodes_GaussianBlurNode__NodeParametersValues(global::NodePipeline.Application.Nodes.GaussianBlurNode node, string nodeId, Dictionary parameters) { if (parameters.TryGetValue("Radius", out var val1) && val1 is int typedVal1) node.Radius.Value = typedVal1; } private static void Set__NodePipeline_Application_Nodes_MaskApplyNode__NodeParametersValues(global::NodePipeline.Application.Nodes.MaskApplyNode node, string nodeId, Dictionary parameters) { if (parameters.TryGetValue("Mode", out var val1) && val1 is global::NodePipeline.Application.Nodes.MaskMode typedVal1) node.Mode.Value = typedVal1; } private static void Set__NodePipeline_Application_Nodes_SaveImage2Node__NodeParametersValues(global::NodePipeline.Application.Nodes.SaveImage2Node node, string nodeId, Dictionary parameters) { } private static void Set__NodePipeline_Application_Nodes_SaveImageNode__NodeParametersValues(global::NodePipeline.Application.Nodes.SaveImageNode node, string nodeId, Dictionary parameters) { if (parameters.TryGetValue("FileName", out var val1) && val1 is string typedVal1) node.FileName.Value = typedVal1; if (parameters.TryGetValue("Extension", out var val2) && val2 is string typedVal2) node.Extension.Value = typedVal2; if (parameters.TryGetValue("Directory", out var val3) && val3 is string typedVal3) node.Directory.Value = typedVal3; } private static string GetNodeType(string pipelineId, string nodeId, INode node) { switch (node) { case global::NodePipeline.Application.Nodes.FileImageSource2Node: return NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource2"); case global::NodePipeline.Application.Nodes.FileImageSourceNode: return NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.FileImageSource"); case global::NodePipeline.Application.Nodes.GaussianBlurNode: return NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.GaussianBlur"); case global::NodePipeline.Application.Nodes.MaskApplyNode: return NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.MaskApply"); case global::NodePipeline.Application.Nodes.SaveImage2Node: return NodeNamePrefixSettings.TrimNodeName("NodePipeline.Application.Nodes.SaveImage2"); case global::NodePipeline.Application.Nodes.SaveImageNode: return "FileImageDestination"; default: throw new NodeNotFoundException(pipelineId, node.GetType().Name, nodeId); } } private record PortConnectionInfo(bool Connected, object? OutputFieldObj, string FromPortName, string FromNodeType, string FromNodeId); } #nullable restore