private void DeserializeNodeComponentTo(object serializedNodeComponent, INodeComponent serializeTo, ISerializer serializer)
        {
            if (serializedNodeComponent is SerializedNodeField serializedNodeField && serializeTo is INodeField nodeField)
            {
                nodeField.Name.Value = serializedNodeField.Name;
                foreach (var kvp in serializedNodeField.Values)
                {
                    object deserializedValue = serializer.TryDeserializeObject(kvp.Value, nodeField.GetValue(kvp.Key).TypeDefinition?.ValueType, null);
                    nodeField[kvp.Key] = deserializedValue;
                }
            }

            if (serializedNodeComponent is SerializedNodeLabel serializedNodeLabel && serializeTo is INodeLabel nodeLabel)
            {
                nodeLabel.Name.Value = serializedNodeLabel.LabelText;
            }

            if (serializedNodeComponent is SerializedNodeComponentCollection serializedNodeComponentCollection && serializeTo is INodeComponentCollection nodeComponentCollection)
            {
                foreach ((object serializedChildComponent, INodeComponent childSerializeTo) in serializedNodeComponentCollection.SerializedChildComponents.Zip(nodeComponentCollection))
                {
                    DeserializeNodeComponentTo(serializedChildComponent, childSerializeTo, serializer);
                }
            }
        }
Exemple #2
0
        public void FindNextNodes(INodeComponent nodeComposite)
        {
            bool foundNodeChild = false;

            // Loop through all children to Show English description of all Nodes
            foreach (var child in nodeComposite.Children)
            {
                // If child is Node, show English description
                if (child.CanCalculate())
                {
                    ConsoleWriterSingleton.Instance.ShowNextNode();
                    child.Accept(_nodeEnglishDescriptionVisitor);
                    ConsoleWriterSingleton.Instance.ShowEmptyLine();

                    foundNodeChild = true;
                }
            }

            // Find next Node in children
            if (!foundNodeChild)
            {
                foreach (var child in nodeComposite.Children)
                {
                    FindNextNodes(child);
                }
            }
        }
        public static INodeComponentAutoCloner NodeComponentAutoCloner(INodeComponent originalClone, int minimumFieldCount, Func <int, string> nameRule)
        {
            INodeComponentAutoCloner output = Laminar.New <INodeComponentAutoCloner>();

            output.ResetWith(originalClone, minimumFieldCount, nameRule);

            return(output);
        }
 protected override IVisualNodeComponent CloneTo(INodeComponent nodeField)
 {
     base.CloneTo(nodeField);
     (nodeField as IVisualNodeComponent).Name.Value = Name.Value;
     (nodeField as IVisualNodeComponent).SetFlowOutput(this.GetFlowOutput().Value);
     (nodeField as IVisualNodeComponent).SetFlowInput(this.GetFlowInput().Value);
     return(nodeField as IVisualNodeComponent);
 }
Exemple #5
0
 protected override IVisualNodeComponent CloneTo(INodeComponent nodeField)
 {
     base.CloneTo(nodeField);
     (nodeField as IVisualNodeComponent).Name.Value        = Name.Value;
     (nodeField as IVisualNodeComponent).FlowOutput.Exists = FlowOutput.Exists;
     (nodeField as IVisualNodeComponent).FlowInput.Exists  = FlowInput.Exists;
     return(nodeField as IVisualNodeComponent);
 }
        public void ResetWith(INodeComponent originalClone, int minimumFieldCount, Func <int, string> nameRule)
        {
            _originalClone     = originalClone;
            _minimumFieldCount = minimumFieldCount;
            _nameRule          = nameRule;

            _originalClone.ParentNode    = ParentNode;
            _originalClone.Opacity.Value = 0.5;
            _originalClone.RemoveAction  = (component) => ProtectedRemove(component);

            ProtectedReset();
        }
        public void CreateCircuit()
        {
            foreach (var edge in _edgeMapping)
            {
                // Check if entry is input (existing key in inputMapping)
                foreach (var input in _inputs)
                {
                    // If entry is input, add entry to input mapping
                    if (edge.Key == input._name)
                    {
                        INodeComponent edgeValuesWrapComposite = CreateNodeComponent(edge);
                        _inputMapping.Add(input, edgeValuesWrapComposite);
                    }
                }
            }

            _circuit.SetMappings(_inputMapping, _probeMapping);
        }
        private object SerializeNodeComponent(INodeComponent component, ISerializer serializer)
        {
            if (component is INodeField nodeField)
            {
                return(new SerializedNodeField(nodeField.Name.Value, nodeField.AllValues.ToDictionary(x => x.Key, x => serializer.TrySerializeObject(x.Value.Value))));
            }

            if (component is INodeLabel nodeLabel)
            {
                return(new SerializedNodeLabel(nodeLabel.LabelText.Value));
            }

            if (component is INodeComponentCollection componentCollection)
            {
                return(new SerializedNodeComponentCollection(componentCollection.Select(x => SerializeNodeComponent(x, serializer)).ToList()));
            }

            return(null);
        }
Exemple #9
0
        private void CheckGrandChildIsProbe(INodeComponent grandChild, ProbeValue result)
        {
            if (_probesCircuitMapping.ContainsKey(grandChild))
            {
                // Show next (is probe)
                ConsoleWriterSingleton.Instance.ShowNextProbe(_probesCircuitMapping[grandChild]._name);

                // Set result of probe
                _probesCircuitMapping[grandChild]._value = result;

                // Add probe to final probes mapping
                _finalProbes.Add(grandChild, _probesCircuitMapping[grandChild]);

                // Show probe (intermediate) result
                ConsoleWriterSingleton.Instance.ShowProbeResult(_probesCircuitMapping[grandChild]._name, _probesCircuitMapping[grandChild].ToInt());

                // Add probe as circuit result
                AddResult(_probesCircuitMapping[grandChild]);
            }
        }
        public INodeComponent CreateNodeComponent(KeyValuePair <string, string[]> edge)
        {
            // this is array to wrap edgeMapping values
            NodeComposite edgeValuesWrapComposite = new NodeComposite();

            foreach (var value in edge.Value)
            {
                NodeComposite nodeComposite = new NodeComposite();

                if (_nodeMapping.ContainsKey(value))
                {
                    // add Node object to composite
                    nodeComposite.AddChild(_nodeMapping[value]);
                }
                else
                {
                    foreach (var probe in _probes)
                    {
                        if (probe._name == value)
                        {
                            _probeMapping.Add(nodeComposite, probe);
                            break;
                        }
                    }
                }


                // add child composite
                if (_edgeMapping.ContainsKey(value))
                {
                    KeyValuePair <string, string[]> childEdge   = new KeyValuePair <string, string[]>(value, _edgeMapping[value]);
                    INodeComponent childEdgeValuesWrapComposite = CreateNodeComponent(childEdge);
                    nodeComposite.AddChild(childEdgeValuesWrapComposite);
                }

                edgeValuesWrapComposite.AddChild(nodeComposite);
            }

            return(edgeValuesWrapComposite);
        }
Exemple #11
0
        public void RunINodeComponent(INodeComponent nodeComposite, InputValue inputValue)
        {
            bool foundNodeChild = false;

            foreach (var child in nodeComposite.Children)
            {
                // Check whether child is Node
                if (child.CanCalculate())
                {
                    child.AddInput(inputValue);
                    foundNodeChild = true;
                }
            }

            // If no nodeChild is found, run children folder
            if (!foundNodeChild)
            {
                foreach (var child in nodeComposite.Children)
                {
                    RunINodeComponent(child, inputValue);
                }
            }
        }
Exemple #12
0
 public void AddChild(INodeComponent child)
 {
     child.Parent = this;
     _children.Add(child);
 }
 public void removeChildren()
 {
     this.leftChild  = null;
     this.rightChild = null;
 }
Exemple #14
0
 public int AddComponet(INodeComponent component) => m_ComManager.AddComponet(component);
Exemple #15
0
 public RequestTypeError(ERequest type, INodeComponent connect = null)
     :
     base("Error Request Type: " + type + ", Connect:" + connect)
 {
 }
Exemple #16
0
 public void addChildren(INodeComponent a, INodeComponent b)
 {
     throw new NotImplementedException();
 }
 public static TComponent WithElement <TComponent>(this TComponent builder, object key, INodeComponent value) where TComponent : INodeComponentDictionary
 {
     builder.Add(key, value);
     return(builder);
 }
 public void addChildren(INodeComponent leftChild, INodeComponent rightChild)
 {
     this.leftChild  = leftChild;
     this.rightChild = rightChild;
 }