示例#1
0
        public override void RaisePropertyChanged(string propertyName)
        {
            base.RaisePropertyChanged(propertyName);

            NodePropertyPort port = NodeGraphManager.FindNodePropertyPort(this, propertyName);

            if (null != port)
            {
                Type nodeType = GetType();

                PropertyInfo propertyInfo = nodeType.GetProperty(propertyName);
                if (null != propertyInfo)
                {
                    port.Value = propertyInfo.GetValue(this);
                }
                else
                {
                    FieldInfo fieldInfo = nodeType.GetField(propertyName);
                    if (null != fieldInfo)
                    {
                        port.Value = fieldInfo.GetValue(this);
                    }
                }
            }
        }
示例#2
0
        public override void ReadXml(XmlReader reader)
        {
            base.ReadXml(reader);

            Header = reader.GetAttribute("Header");
            HeaderBackgroundColor = new SolidColorBrush(
                ( Color )ColorConverter.ConvertFromString(reader.GetAttribute("HeaderBackgroundColor")));
            HeaderFontColor = new SolidColorBrush(( Color )ColorConverter.ConvertFromString(
                                                      reader.GetAttribute("HeaderFontColor")));
            AllowEditingHeader = bool.Parse(reader.GetAttribute("AllowEditingHeader"));

            AllowCircularConnection = bool.Parse(reader.GetAttribute("AllowCircularConnection"));

            X      = double.Parse(reader.GetAttribute("X"));
            Y      = double.Parse(reader.GetAttribute("Y"));
            ZIndex = int.Parse(reader.GetAttribute("ZIndex"));

            bool isInputFlowPortsEnd      = false;
            bool isOutputFlowPortsEnd     = false;
            bool isInputPropertyPortsEnd  = false;
            bool isOutputPropertyPortsEnd = false;

            while (reader.Read())
            {
                if (XmlNodeType.Element == reader.NodeType)
                {
                    if (("PropertyPort" == reader.Name) ||
                        ("FlowPort" == reader.Name))
                    {
                        string prevReaderName = reader.Name;

                        Guid guid    = Guid.Parse(reader.GetAttribute("Guid"));
                        Type type    = Type.GetType(reader.GetAttribute("Type"));
                        Type vmType  = Type.GetType(reader.GetAttribute("ViewModelType"));
                        bool isInput = bool.Parse(reader.GetAttribute("IsInput"));

                        string ownerGuidString = reader.GetAttribute("Owner");
                        Node   node            = NodeGraphManager.FindNode(Guid.Parse(ownerGuidString));

                        if ("PropertyPort" == prevReaderName)
                        {
                            string name      = reader.GetAttribute("Name");
                            Type   valueType = Type.GetType(reader.GetAttribute("ValueType"));
                            bool   hasEditor = bool.Parse(reader.GetAttribute("HasEditor"));

                            NodePropertyPort port = NodeGraphManager.CreateNodePropertyPort(
                                true, guid, node, isInput, valueType, null, name, hasEditor, vmType);
                            port.ReadXml(reader);
                        }
                        else
                        {
                            NodeFlowPort port = NodeGraphManager.CreateNodeFlowPort(
                                true, guid, node, isInput, vmType);
                            port.ReadXml(reader);
                        }
                    }
                }

                if (reader.IsEmptyElement || (XmlNodeType.EndElement == reader.NodeType))
                {
                    if ("InputFlowPorts" == reader.Name)
                    {
                        isInputFlowPortsEnd = true;
                    }
                    else if ("OutputFlowPorts" == reader.Name)
                    {
                        isOutputFlowPortsEnd = true;
                    }
                    else if ("InputPropertyPorts" == reader.Name)
                    {
                        isInputPropertyPortsEnd = true;
                    }
                    else if ("OutputPropertyPorts" == reader.Name)
                    {
                        isOutputPropertyPortsEnd = true;
                    }
                }

                if (isInputFlowPortsEnd && isOutputFlowPortsEnd &&
                    isInputPropertyPortsEnd && isOutputPropertyPortsEnd)
                {
                    break;
                }
            }
        }