Ejemplo n.º 1
0
        public static NodeManifest Construct(Type[] types)
        {
            var manifest = new NodeManifest();

            var information = new Dictionary <string, NodeInformation>();

            foreach (var type in types)
            {
                information.Add(type.FullName, NodeInformation.Construct(type));
            }
            manifest.Nodes = information;
            return(manifest);
        }
Ejemplo n.º 2
0
        public static BehaviourManifest CreateFromAppDomain(AppDomain appDomain)
        {
            var manifest = new BehaviourManifest();

            var objectTypes = new Dictionary <string, TypeInformation>();

            foreach (var type in frameworkTypes)
            {
                objectTypes.Add(type.Name, TypeInformation.Construct(type));
            }

            var nodeTypes = new Dictionary <string, NodeInformation>();

            foreach (var assembly in GetDependentAssemblies(appDomain, typeof(NodeTemplate).Assembly))
            {
                Type[] types;
                try
                {
                    types = assembly.GetTypes();
                }
                catch
                {
                    continue;
                }

                foreach (var type in types)
                {
                    ConstructType(type, objectTypes);

                    if (type.IsAbstract)
                    {
                        continue;
                    }

                    if (typeof(NodeTemplate).IsAssignableFrom(type))
                    {
                        nodeTypes.Add(type.FullName, NodeInformation.Construct(type));
                    }
                }
            }

            manifest.Types = new TypeManifest()
            {
                ObjectTypes = objectTypes,
                NodeTypes   = nodeTypes,
            };

            return(manifest);
        }
Ejemplo n.º 3
0
        public static NodeManifest Construct()
        {
            var manifest = new NodeManifest();

            var information = new Dictionary <string, NodeInformation>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }

                    if (typeof(NodeTemplate).IsAssignableFrom(type))
                    {
                        information.Add(type.FullName, NodeInformation.Construct(type));
                    }
                }
            }
            manifest.Nodes = information;
            return(manifest);
        }
Ejemplo n.º 4
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);
        }