示例#1
0
        public static SocketInformation Construct(FieldInfo field, InputMap socket)
        {
            var socketInformation = new SocketInformation
            {
                Type = socket.ConnectionType.Name
            };

            return(socketInformation);
        }
示例#2
0
        public static NodeInformation Construct(Type nodeType)
        {
            var nodeInformation = new NodeInformation();

            var nodeTemplate     = (NodeTemplate)Activator.CreateInstance(nodeType);
            var metadataInstance = (NodeInstanceBase)nodeTemplate.CreateInstance();

            var instanceType = metadataInstance.GetType();

            var singleNodeGraph = new ManifestCaptureGraphInstance(nodeTemplate);

            int inputId            = 0;
            int outputId           = 0;
            var inputSocketFields  = new List <FieldInfo>();
            var outputSocketFields = new List <FieldInfo>();
            var fieldInfos         = new Dictionary <string, FieldInformation>();

            foreach (var field in nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(OutputSocket))
                {
                    field.SetValue(nodeTemplate, new OutputSocket(outputId));
                    outputId++;
                    outputSocketFields.Add(field);
                }
                else
                {
                    if (field.FieldType == typeof(InputSocket))
                    {
                        field.SetValue(nodeTemplate, new InputSocket(inputId));
                        inputId++;
                        inputSocketFields.Add(field);
                    }
                    fieldInfos.Add(field.Name, FieldInformation.ConstructFieldInformation(field, nodeTemplate));
                }
            }
            nodeInformation.Fields = fieldInfos;

            var nodeProperty = instanceType.GetProperty("Template");

            nodeProperty.SetValue(metadataInstance, nodeTemplate);

            var connectionMapper = new ConnectionMapper(metadataInstance, singleNodeGraph);

            var inputsArray  = metadataInstance.Inputs(connectionMapper);
            var outputsArray = metadataInstance.Outputs(connectionMapper);

            if (inputsArray != null)
            {
                nodeInformation.Inputs = new Dictionary <string, SocketInformation>(inputsArray.Length);

                for (int i = 0; i < inputsArray.Length; i++)
                {
                    var map   = inputsArray[i];
                    var field = inputSocketFields[map.ConnectionId];
                    nodeInformation.Inputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Inputs = null;
            }

            if (outputsArray != null)
            {
                nodeInformation.Outputs = new Dictionary <string, SocketInformation>(outputsArray.Length);

                for (int i = 0; i < outputsArray.Length; i++)
                {
                    var map   = outputsArray[i];
                    var field = outputSocketFields[map.ConnectionId];
                    nodeInformation.Outputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Outputs = null;
            }

            return(nodeInformation);
        }
示例#3
0
        public static NodeInformation Construct(Type nodeType)
        {
            var nodeInformation = new NodeInformation
            {
                Name = nodeType.Name
            };

            var typeDefinition  = new Type[] { typeof(IGraphInstance), nodeType.BaseType.GenericTypeArguments[0] };
            var inputsProperty  = nodeType.GetMethod("Inputs", typeDefinition);
            var outputsProperty = nodeType.GetMethod("Outputs", typeDefinition);

            var    nodeTemplate     = (Node)Activator.CreateInstance(nodeType);
            object metadataInstance = Activator.CreateInstance(typeDefinition[1]);
            var    singleNodeGraph  = new ManifestCaptureGraphInstance(nodeTemplate);

            int inputId            = 0;
            int outputId           = 0;
            var inputSocketFields  = new List <FieldInfo> ();
            var outputSocketFields = new List <FieldInfo> ();
            var fieldInfos         = new List <FieldInformation> ();

            foreach (var field in nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(InputSocket))
                {
                    field.SetValue(nodeTemplate, new InputSocket(inputId));
                    inputId++;
                    inputSocketFields.Add(field);
                }
                else if (field.FieldType == typeof(OutputSocket))
                {
                    field.SetValue(nodeTemplate, new OutputSocket(outputId));
                    outputId++;
                    outputSocketFields.Add(field);
                }
                else
                {
                    fieldInfos.Add(FieldInformation.Construct(field));
                }
            }
            nodeInformation.Fields = fieldInfos.ToArray();

            object[] connectParameters = { singleNodeGraph, metadataInstance };
            var      inputsArray       = (InputMap[])inputsProperty.Invoke(nodeTemplate, connectParameters);
            var      outputsArray      = (OutputMap[])outputsProperty.Invoke(nodeTemplate, connectParameters);

            if (inputsArray != null)
            {
                nodeInformation.Inputs = new SocketInformation[inputsArray.Length];

                for (int i = 0; i < inputsArray.Length; i++)
                {
                    var map   = inputsArray[i];
                    var field = inputSocketFields[map.Source.TargetId];
                    nodeInformation.Inputs[i] = SocketInformation.Construct(field, map);
                }
            }
            else
            {
                nodeInformation.Inputs = null;
            }

            if (outputsArray != null)
            {
                nodeInformation.Outputs = new SocketInformation[outputsArray.Length];

                for (int i = 0; i < outputsArray.Length; i++)
                {
                    var map   = outputsArray[i];
                    var field = outputSocketFields[map.Source.Id];
                    nodeInformation.Outputs[i] = SocketInformation.Construct(field, map);
                }
            }
            else
            {
                nodeInformation.Outputs = null;
            }

            return(nodeInformation);
        }
示例#4
0
        public static NodeInformation ConstructNodeInformation(Type nodeType)
        {
            var nodeInformation = new NodeInformation();

            var    typeDefinition   = new Type[] { typeof(IGraphConnections) };
            var    nodeTemplate     = (Node)Activator.CreateInstance(nodeType);
            object metadataInstance = nodeTemplate.CreateInstance();

            var instanceType = metadataInstance.GetType();

            var inputsProperty  = instanceType.GetMethod("Inputs", typeDefinition);
            var outputsProperty = instanceType.GetMethod("Outputs", typeDefinition);

            var singleNodeGraph = new ManifestCaptureGraphInstance(nodeTemplate);

            int inputId            = 0;
            int outputId           = 0;
            var inputSocketFields  = new List <FieldInfo> ();
            var outputSocketFields = new List <FieldInfo> ();
            var fieldInfos         = new Dictionary <string, FieldInformation> ();

            foreach (var field in nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(OutputSocket))
                {
                    field.SetValue(nodeTemplate, new OutputSocket(outputId));
                    outputId++;
                    outputSocketFields.Add(field);
                }
                else
                {
                    if (field.FieldType == typeof(InputSocket))
                    {
                        field.SetValue(nodeTemplate, new InputSocket(inputId));
                        inputId++;
                        inputSocketFields.Add(field);
                    }
                    fieldInfos.Add(field.Name, FieldInformation.ConstructFieldInformation(field, nodeTemplate));
                }
            }
            nodeInformation.Fields = fieldInfos;

            var nodeProperty = instanceType.GetProperty("Node");

            nodeProperty.SetValue(metadataInstance, nodeTemplate);

            object[] connectParameters = { singleNodeGraph };
            var      inputsArray       = (InputMap[])inputsProperty.Invoke(metadataInstance, connectParameters);
            var      outputsArray      = (OutputMap[])outputsProperty.Invoke(metadataInstance, connectParameters);

            if (inputsArray != null)
            {
                nodeInformation.Inputs = new Dictionary <string, SocketInformation> (inputsArray.Length);

                for (int i = 0; i < inputsArray.Length; i++)
                {
                    var map   = inputsArray[i];
                    var field = inputSocketFields[map.ConnectionId];
                    nodeInformation.Inputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Inputs = null;
            }

            if (outputsArray != null)
            {
                nodeInformation.Outputs = new Dictionary <string, SocketInformation> (outputsArray.Length);

                for (int i = 0; i < outputsArray.Length; i++)
                {
                    var map   = outputsArray[i];
                    var field = outputSocketFields[map.ConnectionId];
                    nodeInformation.Outputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Outputs = null;
            }

            return(nodeInformation);
        }