Пример #1
0
        public GraphInstance(Graph template, IDictionary <LocalId, JObject> data = null)
        {
            Template = template;

            int nodeCount = template.Nodes.Length;

            nodes = new GraphInstanceNode[nodeCount];

            var serializer = new JsonSerializer();

            serializer.Converters.Add(new OutputConverter());
            serializer.Converters.Add(new SerializedGraphInstanceProxyConverter(template));

            // Map and create tokens
            for (int i = 0; i < nodeCount; i++)
            {
                var node = template.Nodes[i];

                var instance = node.CreateInstance();

                if (data != null && data.TryGetValue(node.Id, out var instanceData))
                {
                    using var sr = instanceData.CreateReader();
                    serializer.Populate(sr, instance);
                }

                nodes[i].Instance = instance;
            }

            connections = new IConnection[template.ConnectionsCount];

            // Allow all outputs to make their output type visible
            for (int i = 0; i < nodeCount; i++)
            {
                var currentNode      = nodes[i].Instance;
                var connectionMapper = new ConnectionMapper(nodes[i].Instance, this);
                nodes[i].Outputs = template.Nodes[i].Outputs(connectionMapper, currentNode);
            }

            // Allow inputs to subscribe to those outputs.
            for (int i = 0; i < nodeCount; i++)
            {
                var currentNode      = nodes[i].Instance;
                var connectionMapper = new ConnectionMapper(currentNode, this);

                nodes[i].Inputs = template.Nodes[i].Inputs(connectionMapper, currentNode);
            }

            // Stop events from taking effect immediately.
            foreach (var connection in connections)
            {
                connection.BufferEvents = true;
            }
        }
Пример #2
0
 public abstract OutputMap[] Outputs(ConnectionMapper connections);
Пример #3
0
 public abstract InputMap[] Inputs(ConnectionMapper connections);
Пример #4
0
 public abstract OutputMap[] Outputs(ConnectionMapper connections, INodeInstance instance);
Пример #5
0
 internal abstract InputMap[] Inputs(ConnectionMapper connections, INodeInstance instance);