Ejemplo n.º 1
0
            internal static ModelEventCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper    = new XmlElementHelper(element);
                Guid             modelGuid = helper.ReadGuid("ModelGuid");
                string           eventName = helper.ReadString("EventName");

                return(new ModelEventCommand(modelGuid, eventName));
            }
Ejemplo n.º 2
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context);
            var helper = new XmlElementHelper(element);
            var script = helper.ReadString("Script", string.Empty);

            this._script = script;
        }
Ejemplo n.º 3
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);

            this.GUID           = helper.ReadGuid("guid", this.GUID);
            this.annotationText = helper.ReadString("annotationText", Resources.GroupDefaultText);
            this.X               = helper.ReadDouble("left", DoubleValue);
            this.Y               = helper.ReadDouble("top", DoubleValue);
            this.width           = helper.ReadDouble("width", DoubleValue);
            this.height          = helper.ReadDouble("height", DoubleValue);
            this.background      = helper.ReadString("backgrouund", "");
            this.fontSize        = helper.ReadDouble("fontSize", fontSize);
            this.textBlockHeight = helper.ReadDouble("TextblockHeight", DoubleValue);
            this.InitialTop      = helper.ReadDouble("InitialTop", DoubleValue);
            this.InitialHeight   = helper.ReadDouble("InitialHeight", DoubleValue);
            //Deserialize Selected models
            if (element.HasChildNodes)
            {
                var listOfModels = new List <ModelBase>();
                if (SelectedModels != null)
                {
                    foreach (var childnode in element.ChildNodes)
                    {
                        var mhelper = new XmlElementHelper(childnode as XmlElement);
                        var result  = mhelper.ReadGuid("ModelGuid", new Guid());
                        var model   = ModelBaseRequested != null
                            ? ModelBaseRequested(result)
                            : SelectedModels.FirstOrDefault(x => x.GUID == result);

                        if (model != null)
                        {
                            listOfModels.Add(model);
                        }
                    }
                }

                SelectedModels = listOfModels;
            }

            //On any Undo Operation, current values are restored to previous values.
            //These properties should be Raised, so that they get the correct value on Undo.
            RaisePropertyChanged("Background");
            RaisePropertyChanged("FontSize");
            RaisePropertyChanged("AnnotationText");
            RaisePropertyChanged("SelectedModels");
        }
Ejemplo n.º 4
0
 protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
 {
     var helper = new XmlElementHelper(nodeElement);
     GUID = helper.ReadGuid("guid", GUID);
     Text = helper.ReadString("text", "New Note");
     X = helper.ReadDouble("x", 0.0);
     Y = helper.ReadDouble("y", 0.0);
 }
Ejemplo n.º 5
0
 protected override void DeserializeCore(XmlElement element, SaveContext context)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     this.GUID = helper.ReadGuid("guid", this.GUID);
     this.Text = helper.ReadString("text", "New Note");
     this.X = helper.ReadDouble("x", 0.0);
     this.Y = helper.ReadDouble("y", 0.0);
 }
Ejemplo n.º 6
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called.
            var helper                       = new XmlElementHelper(element);
            var metricConversion             = helper.ReadString("conversionMetric");
            var selectedMetricConversionFrom = helper.ReadString("conversionFrom");
            var selectedMetricConversionTo   = helper.ReadString("conversionTo");

            SelectedMetricConversion = Enum.Parse(typeof(ConversionMetricUnit), metricConversion) is ConversionMetricUnit ?
                                       (ConversionMetricUnit)Enum.Parse(typeof(ConversionMetricUnit), metricConversion) : ConversionMetricUnit.Length;

            SelectedFromConversion = Enum.Parse(typeof(ConversionUnit), selectedMetricConversionFrom) is ConversionUnit ?
                                     (ConversionUnit)Enum.Parse(typeof(ConversionUnit), selectedMetricConversionFrom) : ConversionUnit.Meters;

            SelectedToConversion = Enum.Parse(typeof(ConversionUnit), selectedMetricConversionTo) is ConversionUnit ?
                                   (ConversionUnit)Enum.Parse(typeof(ConversionUnit), selectedMetricConversionTo) : ConversionUnit.Meters;
        }
Ejemplo n.º 7
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called.
            var helper       = new XmlElementHelper(element);
            var exportedUnit = helper.ReadString("UINodeExample");

            //valueofslider = int.Parse(exportedUnit) is int ? int.Parse(exportedUnit) : 0;
        }
Ejemplo n.º 8
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);

            this.GUID = helper.ReadGuid("guid", this.GUID);
            this.Text = helper.ReadString("text", "New Note");
            this.X    = helper.ReadDouble("x", 0.0);
            this.Y    = helper.ReadDouble("y", 0.0);
        }
Ejemplo n.º 9
0
        protected override void LoadNode(XmlNode nodeElement)
        {
            base.LoadNode(nodeElement);
            var helper = new XmlElementHelper(nodeElement as XmlElement);

            code = helper.ReadString("CodeText");
            ProcessCodeDirect();
            shouldFocus = helper.ReadBoolean("ShouldFocus");
        }
Ejemplo n.º 10
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called.
            var helper       = new XmlElementHelper(element);
            var exportedUnit = helper.ReadString("exportedUnit");

            SelectedExportedUnit = Enum.Parse(typeof(ConversionUnit), exportedUnit) is ConversionUnit ?
                                   (ConversionUnit)Enum.Parse(typeof(ConversionUnit), exportedUnit) : ConversionUnit.Feet;
        }
Ejemplo n.º 11
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            base.DeserializeCore(nodeElement, context);
            var helper = new XmlElementHelper(nodeElement);

            shouldFocus = helper.ReadBoolean("ShouldFocus");
            code        = helper.ReadString("CodeText");
            ProcessCodeDirect();
        }
Ejemplo n.º 12
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement);

            GUID = helper.ReadGuid("guid", GUID);
            Text = helper.ReadString("text", "New Note");
            X    = helper.ReadDouble("x", 0.0);
            Y    = helper.ReadDouble("y", 0.0);
        }
Ejemplo n.º 13
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context == SaveContext.Undo)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                FormulaString = helper.ReadString("formulaString");
            }
        }
Ejemplo n.º 14
0
            internal static CreateNoteCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper   = new XmlElementHelper(element);
                Guid             nodeId   = helper.ReadGuid("NodeId");
                string           noteText = helper.ReadString("NoteText");
                double           x        = helper.ReadDouble("X");
                double           y        = helper.ReadDouble("Y");

                return(new CreateNoteCommand(nodeId, noteText, x, y,
                                             helper.ReadBoolean("DefaultPosition")));
            }
Ejemplo n.º 15
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement);
            GUID = helper.ReadGuid("guid", GUID);
            Text = helper.ReadString("text", "New Note");
            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);

            // Notify listeners that the position of the note has changed, 
            // then parent group will also redraw itself.
            ReportPosition();
        }
Ejemplo n.º 16
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement);

            GUID = helper.ReadGuid("guid", GUID);
            Text = helper.ReadString("text", "New Note");
            X    = helper.ReadDouble("x", 0.0);
            Y    = helper.ReadDouble("y", 0.0);

            // Notify listeners that the position of the note has changed,
            // then parent group will also redraw itself.
            ReportPosition();
        }
Ejemplo n.º 17
0
        public void CreateModel(XmlElement modelData)
        {
            XmlElementHelper helper   = new XmlElementHelper(modelData);
            string           typeName = helper.ReadString("type", String.Empty);

            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto
                // the name of the XmlElement itself, which is usually the type
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                              string.Format("No type information: {0}", guid));
                }
            }

            if (typeName.StartsWith("Dynamo.Nodes"))
            {
                NodeModel nodeModel = DynamoModel.CreateNodeInstance(typeName);
                nodeModel.WorkSpace = this;
                nodeModel.Deserialize(modelData, SaveContext.Undo);
                Nodes.Add(nodeModel);
            }
            else if (typeName.StartsWith("Dynamo.Models.ConnectorModel"))
            {
                ConnectorModel connector = ConnectorModel.Make();
                connector.Deserialize(modelData, SaveContext.Undo);
                Connectors.Add(connector);
            }
            else if (typeName.StartsWith("Dynamo.Models.NoteModel"))
            {
                NoteModel noteModel = new NoteModel(0.0, 0.0);
                noteModel.Deserialize(modelData, SaveContext.Undo);
                Notes.Add(noteModel);
            }
        }
Ejemplo n.º 18
0
        public override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context);

            var helper   = new XmlElementHelper(element);
            var nickname = helper.ReadString("functionName");

            Guid funcId;

            if (!Guid.TryParse(helper.ReadString("functionId"), out funcId))
            {
                funcId = GuidUtility.Create(GuidUtility.UrlNamespace, nickname);
            }

            if (!VerifyFuncId(ref funcId, nickname))
            {
                LoadProxyCustomNode(funcId, nickname);
                return;
            }

            Definition = this.dynamoModel.CustomNodeManager.GetFunctionDefinition(funcId);
        }
Ejemplo n.º 19
0
            internal static CreateNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);

                System.Guid nodeId   = helper.ReadGuid("NodeId");
                string      nodeName = helper.ReadString("NodeName");
                double      x        = helper.ReadDouble("X");
                double      y        = helper.ReadDouble("Y");

                return(new CreateNodeCommand(nodeId, nodeName, x, y,
                                             helper.ReadBoolean("DefaultPosition"),
                                             helper.ReadBoolean("TransformCoordinates")));
            }
Ejemplo n.º 20
0
        public void TestTypeAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            XmlElementHelper writer = new XmlElementHelper(element);

            writer.SetAttribute("ValidName", typeof(System.Environment));

            // Test reading of existing attribute.
            XmlElementHelper reader = new XmlElementHelper(element);

            Assert.AreEqual("System.Environment", reader.ReadString("ValidName"));
        }
Ejemplo n.º 21
0
        public void TestStringAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            XmlElementHelper writer = new XmlElementHelper(element);

            writer.SetAttribute("ValidName", "Abc123");

            // Test reading of existing attribute.
            XmlElementHelper reader = new XmlElementHelper(element);

            Assert.AreEqual("Abc123", reader.ReadString("ValidName"));

            // Test reading of non-existence attribute with default value.
            Assert.AreEqual("Xyz", reader.ReadString("InvalidName", "Xyz"));

            // Test reading of non-existence attribute without default value.
            Assert.Throws <InvalidOperationException>(() =>
            {
                reader.ReadString("InvalidName");
            });
        }
Ejemplo n.º 22
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            base.DeserializeCore(nodeElement, context);
            var helper = new XmlElementHelper(nodeElement);

            shouldFocus = helper.ReadBoolean("ShouldFocus");
            code        = helper.ReadString("CodeText");

            // Lookup namespace resolution map if available and initialize new instance of ElementResolver
            var resolutionMap = CodeBlockUtils.DeserializeElementResolver(nodeElement);

            ElementResolver = new ElementResolver(resolutionMap);

            ProcessCodeDirect();
        }
Ejemplo n.º 23
0
            internal static CreateNodeCommand DeserializeCore(XmlElement element)
            {
                var    helper          = new XmlElementHelper(element);
                double x               = helper.ReadDouble("X");
                double y               = helper.ReadDouble("Y");
                bool   defaultPos      = helper.ReadBoolean("DefaultPosition");
                bool   transformCoords = helper.ReadBoolean("TransformCoordinates");

                var nodeElement = element.ChildNodes.OfType <XmlElement>().FirstOrDefault();

                if (nodeElement == null)
                {
                    // Get the old NodeId and NodeName attributes
                    Guid   nodeId = helper.ReadGuid("NodeId");
                    string name   = helper.ReadString("NodeName");

                    return(new CreateNodeCommand(nodeId, name, x, y, defaultPos, transformCoords));
                }

                return(new CreateNodeCommand(nodeElement, x, y, defaultPos, transformCoords));
            }
Ejemplo n.º 24
0
        public void CreateModel(XmlElement modelData)
        {
            var helper = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);
            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto 
                // the name of the XmlElement itself, which is usually the type 
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                        string.Format("No type information: {0}", guid));
                }
            }

            /*
            if (typeName.Equals("Dynamo.Nodes.DSFunction") ||
                typeName.Equals("Dynamo.Nodes.DSVarArgFunction"))
            {
                // For DSFunction and DSVarArgFunction node types, the type name
                // is actually embedded within "name" attribute (for an example,
                // "UV.ByCoordinates@double,double").
                // 
                typeName = modelData.Attributes["name"].Value;
            }
            */

            if (typeName.StartsWith("Dynamo.Models.ConnectorModel"))
            {
                var connector = NodeGraph.LoadConnectorFromXml(modelData,
                    Nodes.ToDictionary(node => node.GUID));

                OnConnectorAdded(connector); // Update view-model and view.
            }
            else if (typeName.StartsWith("Dynamo.Models.NoteModel"))
            {
                var noteModel = NodeGraph.LoadNoteFromXml(modelData);
                Notes.Add(noteModel);

                //check whether this note belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this note "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == noteModel.GUID))
                    {
                        annotation.AddToSelectedModels(noteModel);
                    }
                }
            }
            else if (typeName.StartsWith("Dynamo.Models.AnnotationModel"))
            {
                var selectedNodes = this.Nodes == null ? null : this.Nodes.Where(s => s.IsSelected);
                var selectedNotes = this.Notes == null ? null : this.Notes.Where(s => s.IsSelected);

                var annotationModel = new AnnotationModel(selectedNodes, selectedNotes);
                annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
                annotationModel.Disposed += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
                annotationModel.Deserialize(modelData, SaveContext.Undo);                
                Annotations.Add(annotationModel);
            }
            else // Other node types.
            {
                NodeModel nodeModel = NodeFactory.CreateNodeFromXml(modelData, SaveContext.Undo);
                Nodes.Add(nodeModel);
                RegisterNode(nodeModel);
                
                //check whether this node belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this node "was" in a group
                    if (annotation.DeletedModelBases.Any(m=>m.GUID == nodeModel.GUID))
                    {
                        annotation.AddToSelectedModels(nodeModel);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public ModelBase GetModelForElement(XmlElement modelData)
        {
            // TODO(Ben): This may or may not be true, but I guess we should be 
            // using "System.Type" (given the "type" information in "modelData"),
            // and determine the matching category (e.g. is this a Node, or a 
            // Connector?) instead of checking in each and every collections we
            // have in the workspace.
            // 
            // System.Type type = System.Type.GetType(helper.ReadString("type"));
            // if (typeof(Dynamo.Models.NodeModel).IsAssignableFrom(type))
            //     return Nodes.First((x) => (x.GUID == modelGuid));

            var helper = new XmlElementHelper(modelData);
            Guid modelGuid = helper.ReadGuid("guid");

            ModelBase foundModel = GetModelInternal(modelGuid);
            if (null != foundModel)
                return foundModel;

            throw new ArgumentException(
                string.Format("Unhandled model type: {0}", helper.ReadString("type", modelData.Name)));
        }
Ejemplo n.º 26
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context == SaveContext.Undo)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                FormulaString = helper.ReadString("formulaString");
            }
        }
Ejemplo n.º 27
0
 internal static ModelEventCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid modelGuid = helper.ReadGuid("ModelGuid");
     string eventName = helper.ReadString("EventName");
     return new ModelEventCommand(modelGuid, eventName);
 }
Ejemplo n.º 28
0
            internal static CreateCustomNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);

                return new CreateCustomNodeCommand(
                    helper.ReadGuid("NodeId"),
                    helper.ReadString("Name"),
                    helper.ReadString("Category"),
                    helper.ReadString("Description"),
                    helper.ReadBoolean("MakeCurrent"));
            }
Ejemplo n.º 29
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            XmlElementHelper helper = new XmlElementHelper(element);
            this.GUID = helper.ReadGuid("guid", Guid.NewGuid());

            // Resolve node nick name.
            string nickName = helper.ReadString("nickname", string.Empty);
            if (!string.IsNullOrEmpty(nickName))
                this.nickName = nickName;
            else
            {
                System.Type type = this.GetType();
                var attribs = type.GetCustomAttributes(typeof(NodeNameAttribute), true);
                NodeNameAttribute attrib = attribs[0] as NodeNameAttribute;
                if (null != attrib)
                    this.nickName = attrib.Name;
            }

            this.X = helper.ReadDouble("x", 0.0);
            this.Y = helper.ReadDouble("y", 0.0);
            this.isVisible = helper.ReadBoolean("isVisible", true);
            this.isUpstreamVisible = helper.ReadBoolean("isUpstreamVisible", true);
            this.argumentLacing = helper.ReadEnum("lacing", LacingStrategy.Disabled);

            if (context == SaveContext.Undo)
            {
                // Fix: MAGN-159 (nodes are not editable after undo/redo).
                interactionEnabled = helper.ReadBoolean("interactionEnabled", true);
                this.state = helper.ReadEnum("nodeState", ElementState.ACTIVE);

                // We only notify property changes in an undo/redo operation. Normal
                // operations like file loading or copy-paste have the models created
                // in different ways and their views will always be up-to-date with
                // respect to their models.
                RaisePropertyChanged("InteractionEnabled");
                RaisePropertyChanged("State");
                RaisePropertyChanged("NickName");
                RaisePropertyChanged("ArgumentLacing");
                RaisePropertyChanged("IsVisible");
                RaisePropertyChanged("IsUpstreamVisible");

                // Notify listeners that the position of the node has changed,
                // then all connected connectors will also redraw themselves.
                this.ReportPosition();
            }
        }
Ejemplo n.º 30
0
            internal static CreateNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                Guid nodeId = helper.ReadGuid("NodeId");
                string nodeName = helper.ReadString("NodeName");
                double x = helper.ReadDouble("X");
                double y = helper.ReadDouble("Y");

                return new CreateNodeCommand(nodeId, nodeName, x, y,
                    helper.ReadBoolean("DefaultPosition"),
                    helper.ReadBoolean("TransformCoordinates"));
            }
Ejemplo n.º 31
0
            internal static CreateNodeCommand DeserializeCore(XmlElement element)
            {
                var helper = new XmlElementHelper(element);
                double x = helper.ReadDouble("X");
                double y = helper.ReadDouble("Y");
                bool defaultPos = helper.ReadBoolean("DefaultPosition");
                bool transformCoords = helper.ReadBoolean("TransformCoordinates");

                var nodeElement = element.ChildNodes.OfType<XmlElement>().FirstOrDefault(el => el.Name != "ModelGuid");

                if (nodeElement == null)
                {
                    // Get the old NodeId and NodeName attributes
                    var nodeId = DeserializeGuid(element, helper);
                    string name = helper.ReadString("NodeName");

                    return new CreateNodeCommand(nodeId, name, x, y, defaultPos, transformCoords);
                }

                return new CreateNodeCommand(nodeElement, x, y, defaultPos, transformCoords);
            }
Ejemplo n.º 32
0
 internal static OpenFileCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     string xmlFilePath = TryFindFile(helper.ReadString("XmlFilePath"), element.OwnerDocument.BaseURI);
     return new OpenFileCommand(xmlFilePath);
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Gets model by GUID which is contained in given Xml data.
        /// </summary>
        /// <param name="modelData">Xml data to find model.</param>
        /// <returns>Found <see cref="ModelBase"/> object.</returns>
        public ModelBase GetModelForElement(XmlElement modelData)
        {
            // TODO(Ben): This may or may not be true, but I guess we should be
            // using "System.Type" (given the "type" information in "modelData"),
            // and determine the matching category (e.g. is this a Node, or a
            // Connector?) instead of checking in each and every collections we
            // have in the workspace.
            //
            // System.Type type = System.Type.GetType(helper.ReadString("type"));
            // if (typeof(Dynamo.Models.NodeModel).IsAssignableFrom(type))
            //     return Nodes.First((x) => (x.GUID == modelGuid));

            var  helper    = new XmlElementHelper(modelData);
            Guid modelGuid = helper.ReadGuid("guid");

            ModelBase foundModel = GetModelInternal(modelGuid);

            if (null != foundModel)
            {
                return(foundModel);
            }

            //if we could not find a matching model
            this.Log(string.Format("Please Report: Unhandled model type: {0}, could not find a matching model with given id", helper.ReadString("type", modelData.Name)), Logging.WarningLevel.Error);
            return(null);
        }
Ejemplo n.º 34
0
            internal static CreateAndConnectNodeCommand DeserializeCore(XmlElement element)
            {
                var helper = new XmlElementHelper(element);
                string newNodeName = helper.ReadString("NewNodeName");
                double x = helper.ReadDouble("X");
                double y = helper.ReadDouble("Y");
                bool createAsDownstreamNode = helper.ReadBoolean("CreateAsDownstreamNode");
                bool addNewNodeToSelection = helper.ReadBoolean("AddNewNodeToSelection");

                var guids = DeserializeGuid(element, helper).ToList();
                var newNodeGuid = guids.ElementAt(0);
                var existingNodeGuid = guids.ElementAt(1);

                int outPortIndex = helper.ReadInteger("OutPortIndex");
                int inPortIndex = helper.ReadInteger("InPortIndex");

                return new CreateAndConnectNodeCommand(newNodeGuid, existingNodeGuid, newNodeName, outPortIndex, inPortIndex,
                    x, y, createAsDownstreamNode, addNewNodeToSelection);
            }
Ejemplo n.º 35
0
            internal static CreateProxyNodeCommand DeserializeCore(XmlElement element)
            {
                var baseCommand = CreateNodeCommand.DeserializeCore(element);
                var helper = new XmlElementHelper(element);
                string nickName = helper.ReadString("NickName");
                int inputs = helper.ReadInteger("Inputs");
                int outputs = helper.ReadInteger("Outputs");

                return new CreateProxyNodeCommand(
                    baseCommand.ModelGuids.First().ToString(),
                    baseCommand.Name,
                    baseCommand.X,
                    baseCommand.Y,
                    baseCommand.DefaultPosition,
                    baseCommand.TransformCoordinates,
                    nickName,
                    inputs,
                    outputs);
            }
Ejemplo n.º 36
0
 protected override void DeserializeCore(XmlElement element, SaveContext context)
 {
     base.DeserializeCore(element, context);
     if (context == SaveContext.Undo)
     {
         var helper = new XmlElementHelper(element);
         shouldFocus = helper.ReadBoolean("ShouldFocus");
         code = helper.ReadString("CodeText");
         ProcessCodeDirect();
     }
 }
Ejemplo n.º 37
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context);

            var helper = new XmlElementHelper(element);
            var script = helper.ReadString("Script", string.Empty);
            this._script = script;
        }
Ejemplo n.º 38
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            base.DeserializeCore(nodeElement, context);
            var helper = new XmlElementHelper(nodeElement);
            shouldFocus = helper.ReadBoolean("ShouldFocus");
            code = helper.ReadString("CodeText");

            // Lookup namespace resolution map if available and initialize new instance of ElementResolver
            var resolutionMap = CodeBlockUtils.DeserializeElementResolver(nodeElement);
            ElementResolver = new ElementResolver(resolutionMap);

            ProcessCodeDirect();
        }
Ejemplo n.º 39
0
            internal static AddPresetCommand DeserializeCore(XmlElement element)
            {
                var helper = new XmlElementHelper(element);
                var modelGuids = DeserializeGuid(element, helper);
                if (modelGuids.Count()<1)
                {
                    throw new ArgumentNullException("No IDs were deserialized during load of preset creation command");
                }

                return new AddPresetCommand(helper.ReadString("name"), helper.ReadString("description"),modelGuids);
            }
Ejemplo n.º 40
0
        public override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context);

            var helper = new XmlElementHelper(element);
            var nickname = helper.ReadString("functionName");

            Guid funcId;
            if (!Guid.TryParse(helper.ReadString("functionId"), out funcId))
                funcId = GuidUtility.Create(GuidUtility.UrlNamespace, nickname);

            if (!VerifyFuncId(ref funcId, nickname))
            {
                LoadProxyCustomNode(funcId, nickname);
                return;
            }

            Definition = dynSettings.Controller.CustomNodeManager.GetFunctionDefinition(funcId);
        }
Ejemplo n.º 41
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context == SaveContext.Undo)
            {
                var helper = new XmlElementHelper(element);
                NickName = helper.ReadString("functionName");

                Guid funcId;
                if (!Guid.TryParse(helper.ReadString("functionId"), out funcId))
                    funcId = GuidUtility.Create(GuidUtility.UrlNamespace, NickName);

                if (!VerifyFuncId(ref funcId))
                {
                    LoadProxyCustomNode(funcId);
                    return;
                }

                Definition = Workspace.DynamoModel.CustomNodeManager.GetFunctionDefinition(funcId);

                XmlNodeList inNodes = element.SelectNodes("functionInput");
                XmlNodeList outNodes = element.SelectNodes("functionOutput");

                var inData =
                    inNodes.Cast<XmlNode>()
                        .Select(
                            (inputNode, i) =>
                                new
                                {
                                    data = new PortData(inputNode.Attributes[0].Value, "Input #" + (i + 1)),
                                    idx = i
                                });

                foreach (var dataAndIdx in inData)
                {
                    if (InPortData.Count > dataAndIdx.idx)
                        InPortData[dataAndIdx.idx] = dataAndIdx.data;
                    else
                        InPortData.Add(dataAndIdx.data);
                }

                var outData =
                    outNodes.Cast<XmlNode>()
                        .Select(
                            (outputNode, i) =>
                                new
                                {
                                    data = new PortData(outputNode.Attributes[0].Value, "Output #" + (i + 1)),
                                    idx = i
                                });

                foreach (var dataAndIdx in outData)
                {
                    if (OutPortData.Count > dataAndIdx.idx)
                        OutPortData[dataAndIdx.idx] = dataAndIdx.data;
                    else
                        OutPortData.Add(dataAndIdx.data);
                }

                //Added it the same way as LoadNode. But unsure of when 'Output' ChildNodes will
                //be added to element. As of now I dont think it is added during serialize

                #region Legacy output support

                foreach (var portData in 
                    from XmlNode subNode in element.ChildNodes
                    where subNode.Name.Equals("Output")
                    select new PortData(subNode.Attributes[0].Value, "function output"))
                {
                    if (OutPortData.Any())
                        OutPortData[0] = portData;
                    else
                        OutPortData.Add(portData);
                }

                #endregion

                RegisterAllPorts();

                Description = helper.ReadString("functionDesc");
            }
        }
Ejemplo n.º 42
0
            internal static OpenFileCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                string xmlFilePath = helper.ReadString("XmlFilePath");
                if (File.Exists(xmlFilePath) == false)
                {
                    // Try to find the file right next to the command XML file.
                    string xmlFileName = Path.GetFileName(xmlFilePath);
                    Uri uri = new Uri(element.OwnerDocument.BaseURI);
                    string directory = Path.GetDirectoryName(uri.AbsolutePath);
                    xmlFilePath = Path.Combine(directory, xmlFileName);

                    // If it still cannot be resolved, fall back to system search.
                    if (File.Exists(xmlFilePath) == false)
                        xmlFilePath = Path.GetFullPath(xmlFileName);

                    if (File.Exists(xmlFilePath) == false) // When all else fail.
                    {
                        var message = "Target file cannot be found!";
                        throw new FileNotFoundException(message, xmlFileName);
                    }
                }

                return new OpenFileCommand(xmlFilePath);
            }
Ejemplo n.º 43
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context == SaveContext.Undo)
            {
                var helper = new XmlElementHelper(element);
                NickName = helper.ReadString("functionName");

                Guid funcId;
                if (!Guid.TryParse(helper.ReadString("functionId"), out funcId))
                {
                    funcId = GuidUtility.Create(GuidUtility.UrlNamespace, NickName);
                }

                if (!VerifyFuncId(ref funcId))
                {
                    LoadProxyCustomNode(funcId);
                    return;
                }

                Definition = Workspace.DynamoModel.CustomNodeManager.GetFunctionDefinition(funcId);

                XmlNodeList inNodes  = element.SelectNodes("functionInput");
                XmlNodeList outNodes = element.SelectNodes("functionOutput");

                var inData =
                    inNodes.Cast <XmlNode>()
                    .Select(
                        (inputNode, i) =>
                        new
                {
                    data = new PortData(inputNode.Attributes[0].Value, "Input #" + (i + 1)),
                    idx  = i
                });

                foreach (var dataAndIdx in inData)
                {
                    if (InPortData.Count > dataAndIdx.idx)
                    {
                        InPortData[dataAndIdx.idx] = dataAndIdx.data;
                    }
                    else
                    {
                        InPortData.Add(dataAndIdx.data);
                    }
                }

                var outData =
                    outNodes.Cast <XmlNode>()
                    .Select(
                        (outputNode, i) =>
                        new
                {
                    data = new PortData(outputNode.Attributes[0].Value, "Output #" + (i + 1)),
                    idx  = i
                });

                foreach (var dataAndIdx in outData)
                {
                    if (OutPortData.Count > dataAndIdx.idx)
                    {
                        OutPortData[dataAndIdx.idx] = dataAndIdx.data;
                    }
                    else
                    {
                        OutPortData.Add(dataAndIdx.data);
                    }
                }

                //Added it the same way as LoadNode. But unsure of when 'Output' ChildNodes will
                //be added to element. As of now I dont think it is added during serialize

                #region Legacy output support

                foreach (var portData in
                         from XmlNode subNode in element.ChildNodes
                         where subNode.Name.Equals("Output")
                         select new PortData(subNode.Attributes[0].Value, "function output"))
                {
                    if (OutPortData.Any())
                    {
                        OutPortData[0] = portData;
                    }
                    else
                    {
                        OutPortData.Add(portData);
                    }
                }

                #endregion

                RegisterAllPorts();

                Description = helper.ReadString("functionDesc");
            }
        }
Ejemplo n.º 44
0
            internal static CreateNoteCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                Guid nodeId = helper.ReadGuid("NodeId");
                string noteText = helper.ReadString("NoteText");
                double x = helper.ReadDouble("X");
                double y = helper.ReadDouble("Y");

                return new CreateNoteCommand(nodeId, noteText, x, y,
                    helper.ReadBoolean("DefaultPosition"));
            }
Ejemplo n.º 45
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called.
            var helper = new XmlElementHelper(element);
            var metricConversion = helper.ReadString("conversionMetric");
            var selectedMetricConversionFrom = helper.ReadString("conversionFrom");
            var selectedMetricConversionTo = helper.ReadString("conversionTo");

            SelectedMetricConversion = Enum.Parse(typeof(ConversionMetricUnit), metricConversion) is ConversionMetricUnit ?
                                (ConversionMetricUnit)Enum.Parse(typeof(ConversionMetricUnit), metricConversion) : ConversionMetricUnit.Length;

            SelectedFromConversion = Enum.Parse(typeof(ConversionUnit), selectedMetricConversionFrom) is ConversionUnit ?
                             (ConversionUnit)Enum.Parse(typeof(ConversionUnit), selectedMetricConversionFrom) : ConversionUnit.Meters;

            SelectedToConversion = Enum.Parse(typeof(ConversionUnit), selectedMetricConversionTo) is ConversionUnit ?
                                (ConversionUnit)Enum.Parse(typeof(ConversionUnit), selectedMetricConversionTo) : ConversionUnit.Meters;

        }
Ejemplo n.º 46
0
 internal static UpdateModelValueCommand DeserializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     Guid modelGuid = helper.ReadGuid("ModelGuid");
     string name = helper.ReadString("Name");
     string value = helper.ReadString("Value");
     return new UpdateModelValueCommand(modelGuid, name, value);
 }
Ejemplo n.º 47
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context == SaveContext.Undo)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                NickName = helper.ReadString("functionName");

                Symbol = helper.ReadString("functionId");
                Guid funcId;
                if (!VerifySymbol(out funcId))
                {
                    LoadProxyCustomNode(funcId);
                    return;
                }
                XmlNodeList inNodes  = element.SelectNodes("functionInput");
                XmlNodeList outNodes = element.SelectNodes("functionOutput");
                int         i        = 0;
                foreach (XmlNode inputNode in inNodes)
                {
                    string name = inputNode.Attributes[0].Value;
                    var    data = new PortData(name, "Input #" + (i + 1), typeof(object));
                    if (InPortData.Count > i)
                    {
                        InPortData[i] = data;
                    }
                    else
                    {
                        InPortData.Add(data);
                    }
                    i++;
                }
                i = 0;
                foreach (XmlNode outputNode in outNodes)
                {
                    string name = outputNode.Attributes[0].Value;
                    var    data = new PortData(name, "Output #" + (i + 1), typeof(object));
                    if (OutPortData.Count > i)
                    {
                        OutPortData[i] = data;
                    }
                    else
                    {
                        OutPortData.Add(data);
                    }
                    i++;
                }

                //Added it the same way as LoadNode. But unsure of when 'Output' ChildNodes will
                //be added to element. As of now I dont think it is added during serialize

                #region Legacy output support

                foreach (XmlNode subNode in element.ChildNodes)
                {
                    if (subNode.Name.Equals("Output"))
                    {
                        var data = new PortData(
                            subNode.Attributes[0].Value, "function output", typeof(object));

                        if (OutPortData.Any())
                        {
                            OutPortData[0] = data;
                        }
                        else
                        {
                            OutPortData.Add(data);
                        }
                    }
                }

                #endregion


                RegisterAllPorts();

                Guid funId;
                try
                {
                    funId = Guid.Parse(Symbol);
                }
                catch
                {
                    funId  = GuidUtility.Create(GuidUtility.UrlNamespace, NickName);
                    Symbol = funId.ToString();
                }

                Definition  = dynSettings.Controller.CustomNodeManager.GetFunctionDefinition(funId);
                Description = helper.ReadString("functionDesc");
            }
        }
Ejemplo n.º 48
0
        public void CreateModel(XmlElement modelData)
        {
            var helper = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);
            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto 
                // the name of the XmlElement itself, which is usually the type 
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                        string.Format("No type information: {0}", guid));
                }
            }

            /*
            if (typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSFunction") ||
                typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSVarArgFunction"))
            {
                // For DSFunction and DSVarArgFunction node types, the type name
                // is actually embedded within "name" attribute (for an example,
                // "UV.ByCoordinates@double,double").
                // 
                typeName = modelData.Attributes["name"].Value;
            }
            */

            if (typeName.Contains("ConnectorModel"))
            {
                var connector = NodeGraph.LoadConnectorFromXml(modelData,
                    Nodes.ToDictionary(node => node.GUID));

                // It is possible that in some cases connector can't be created,
                // for example, connector connects to a custom node instance
                // whose input ports have been changed, so connector can't find
                // its end port owner.
                if (connector == null)
                {
                    var guidAttribute = modelData.Attributes["guid"];
                    if (guidAttribute == null)
                    {
                        throw new InvalidOperationException("'guid' field missing from recorded model");
                    }
                    undoRecorder.RecordModelAsOffTrack(Guid.Parse(guidAttribute.Value)); 
                }
                else 
                {
                    OnConnectorAdded(connector); // Update view-model and view.
                }
            }
            else if (typeName.Contains("NoteModel"))
            {
                var noteModel = NodeGraph.LoadNoteFromXml(modelData);
                AddNote(noteModel);

                //check whether this note belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this note "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == noteModel.GUID))
                    {
                        annotation.AddToSelectedModels(noteModel);
                    }
                }
            }
            else if (typeName.Contains("AnnotationModel"))
            {
                var selectedNodes = this.Nodes == null ? null : this.Nodes.Where(s => s.IsSelected);
                var selectedNotes = this.Notes == null ? null : this.Notes.Where(s => s.IsSelected);

                var annotationModel = new AnnotationModel(selectedNodes, selectedNotes);
                annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
                annotationModel.Disposed += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
                annotationModel.Deserialize(modelData, SaveContext.Undo);
                AddNewAnnotation(annotationModel);
            }

            else if (typeName.Contains("PresetModel"))
            {
                var preset = new PresetModel(this.Nodes);
                preset.Deserialize(modelData, SaveContext.Undo);
                presets.Add(preset);
                //we raise this property change here so that this event bubbles up through
                //the model and to the DynamoViewModel so that presets show in the UI menu if our undo/redo
                //created the first preset
                RaisePropertyChanged("EnablePresetOptions");
               
            }
            else // Other node types.
            {
                NodeModel nodeModel = NodeFactory.CreateNodeFromXml(modelData, SaveContext.Undo, ElementResolver);
                
                AddAndRegisterNode(nodeModel);
                
                //check whether this node belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this node "was" in a group
                    if (annotation.DeletedModelBases.Any(m=>m.GUID == nodeModel.GUID))
                    {
                        annotation.AddToSelectedModels(nodeModel);
                    }
                }
            }
        }
Ejemplo n.º 49
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context != SaveContext.Undo)
            {
                return;
            }

            var helper = new XmlElementHelper(element);

            NickName = helper.ReadString("functionName");

            Controller.DeserializeCore(element, context);

            XmlNodeList inNodes  = element.SelectNodes("functionInput");
            XmlNodeList outNodes = element.SelectNodes("functionOutput");

            var inData =
                inNodes.Cast <XmlNode>()
                .Select(
                    (inputNode, i) =>
                    new
            {
                data = new PortData(inputNode.Attributes[0].Value, "Input #" + (i + 1)),
                idx  = i
            });

            foreach (var dataAndIdx in inData)
            {
                if (InPortData.Count > dataAndIdx.idx)
                {
                    InPortData[dataAndIdx.idx] = dataAndIdx.data;
                }
                else
                {
                    InPortData.Add(dataAndIdx.data);
                }
            }

            var outData =
                outNodes.Cast <XmlNode>()
                .Select(
                    (outputNode, i) =>
                    new
            {
                data = new PortData(outputNode.Attributes[0].Value, "Output #" + (i + 1)),
                idx  = i
            });

            foreach (var dataAndIdx in outData)
            {
                if (OutPortData.Count > dataAndIdx.idx)
                {
                    OutPortData[dataAndIdx.idx] = dataAndIdx.data;
                }
                else
                {
                    OutPortData.Add(dataAndIdx.data);
                }
            }

            //Added it the same way as LoadNode. But unsure of when 'Output' ChildNodes will
            //be added to element. As of now I dont think it is added during serialize

            #region Legacy output support

            foreach (var portData in
                     from XmlNode subNode in element.ChildNodes
                     where subNode.Name.Equals("Output")
                     select new PortData(subNode.Attributes[0].Value, "function output"))
            {
                if (OutPortData.Any())
                {
                    OutPortData[0] = portData;
                }
                else
                {
                    OutPortData.Add(portData);
                }
            }

            #endregion

            RegisterAllPorts();

            Description = helper.ReadString("functionDesc");
        }
Ejemplo n.º 50
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context != SaveContext.Undo) return;

            var helper = new XmlElementHelper(element);
            NickName = helper.ReadString("functionName");

            Controller.DeserializeCore(element, context);

            XmlNodeList inNodes = element.SelectNodes("functionInput");
            XmlNodeList outNodes = element.SelectNodes("functionOutput");

            var inData =
                inNodes.Cast<XmlNode>()
                    .Select(
                        (inputNode, i) =>
                            new
                            {
                                data = new PortData(inputNode.Attributes[0].Value, "Input #" + (i + 1)),
                                idx = i
                            });

            foreach (var dataAndIdx in inData)
            {
                if (InPortData.Count > dataAndIdx.idx)
                    InPortData[dataAndIdx.idx] = dataAndIdx.data;
                else
                    InPortData.Add(dataAndIdx.data);
            }

            var outData =
                outNodes.Cast<XmlNode>()
                    .Select(
                        (outputNode, i) =>
                            new
                            {
                                data = new PortData(outputNode.Attributes[0].Value, "Output #" + (i + 1)),
                                idx = i
                            });

            foreach (var dataAndIdx in outData)
            {
                if (OutPortData.Count > dataAndIdx.idx)
                    OutPortData[dataAndIdx.idx] = dataAndIdx.data;
                else
                    OutPortData.Add(dataAndIdx.data);
            }

            //Added it the same way as LoadNode. But unsure of when 'Output' ChildNodes will
            //be added to element. As of now I dont think it is added during serialize

            #region Legacy output support

            foreach (var portData in 
                from XmlNode subNode in element.ChildNodes
                where subNode.Name.Equals("Output")
                select new PortData(subNode.Attributes[0].Value, "function output"))
            {
                if (OutPortData.Any())
                    OutPortData[0] = portData;
                else
                    OutPortData.Add(portData);
            }

            #endregion

            RegisterAllPorts();

            Description = helper.ReadString("functionDesc");
        }
Ejemplo n.º 51
0
        public void CreateModel(XmlElement modelData)
        {
            XmlElementHelper helper = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);
            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto 
                // the name of the XmlElement itself, which is usually the type 
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                        string.Format("No type information: {0}", guid));
                }
            }

#if USE_DSENGINE
            if (typeName.Equals("Dynamo.Nodes.DSFunction") ||
                typeName.Equals("Dynamo.Nodes.DSVarArgFunction"))
            {
                // For DSFunction and DSVarArgFunction node types, the type name
                // is actually embedded within "name" attribute (for an example,
                // "UV.ByCoordinates@double,double").
                // 
                typeName = modelData.Attributes["name"].Value;
            }
#endif

            if (typeName.StartsWith("Dynamo.Models.ConnectorModel"))
            {
                ConnectorModel connector = ConnectorModel.Make();
                connector.Deserialize(modelData, SaveContext.Undo);
                Connectors.Add(connector);
            }
            else if (typeName.StartsWith("Dynamo.Models.NoteModel"))
            {
                NoteModel noteModel = new NoteModel(0.0, 0.0);
                noteModel.Deserialize(modelData, SaveContext.Undo);
                Notes.Add(noteModel);
            }
            else // Other node types.
            {
                NodeModel nodeModel = DynamoModel.CreateNodeInstance(typeName);
                nodeModel.WorkSpace = this;
                nodeModel.Deserialize(modelData, SaveContext.Undo);
                Nodes.Add(nodeModel);
            }
        }
Ejemplo n.º 52
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {         
            XmlElementHelper helper = new XmlElementHelper(element);
            this.GUID = helper.ReadGuid("guid", this.GUID);
            this.annotationText = helper.ReadString("annotationText", Resources.GroupDefaultText);
            this.X = helper.ReadDouble("left", DoubleValue);
            this.Y = helper.ReadDouble("top", DoubleValue);
            this.width = helper.ReadDouble("width", DoubleValue);
            this.height = helper.ReadDouble("height", DoubleValue);
            this.background = helper.ReadString("backgrouund", "");
            this.fontSize = helper.ReadDouble("fontSize", fontSize);
            this.textBlockHeight = helper.ReadDouble("TextblockHeight", DoubleValue);
            this.InitialTop = helper.ReadDouble("InitialTop", DoubleValue);
            this.InitialHeight = helper.ReadDouble("InitialHeight", DoubleValue);
            //Deserialize Selected models
            if (element.HasChildNodes) 
            {
                var listOfModels = new List<ModelBase>();
                foreach (var childnode in element.ChildNodes)
                {
                    XmlElementHelper mhelper = new XmlElementHelper(childnode as XmlElement);
                     if (SelectedModels != null)
                     {
                         var result = mhelper.ReadGuid("ModelGuid", new Guid());
                         ModelBase model = null;
                         model = ModelBaseRequested != null ? ModelBaseRequested(result) : 
                             SelectedModels.FirstOrDefault(x => x.GUID == result);

                        listOfModels.Add(model);
                    }                  
                }
                SelectedModels = listOfModels;        
            }

            //On any Undo Operation, current values are restored to previous values.
            //These properties should be Raised, so that they get the correct value on Undo.
            RaisePropertyChanged("Background");
            RaisePropertyChanged("FontSize");
            RaisePropertyChanged("AnnotationText");
            RaisePropertyChanged("SelectedModels");
        }
Ejemplo n.º 53
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement); 
            
            if (context != SaveContext.Copy)
                GUID = helper.ReadGuid("guid", GUID);

            // Resolve node nick name.
            string name = helper.ReadString("nickname", string.Empty);
            if (!string.IsNullOrEmpty(name))
                nickName = name;
            else
            {
                Type type = GetType();
                object[] attribs = type.GetCustomAttributes(typeof(NodeNameAttribute), true);
                var attrib = attribs[0] as NodeNameAttribute;
                if (null != attrib)
                    nickName = attrib.Name;
            }

            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);
            isVisible = helper.ReadBoolean("isVisible", true);
            isUpstreamVisible = helper.ReadBoolean("isUpstreamVisible", true);
            argumentLacing = helper.ReadEnum("lacing", LacingStrategy.Disabled);

            var portInfoProcessed = new HashSet<int>();

            //read port information
            foreach (XmlNode subNode in nodeElement.ChildNodes)
            {
                if (subNode.Name == "PortInfo")
                {
                    int index = int.Parse(subNode.Attributes["index"].Value);
                    if (index < InPorts.Count)
                    {
                        portInfoProcessed.Add(index);
                        bool def = bool.Parse(subNode.Attributes["default"].Value);
                        inPorts[index].UsingDefaultValue = def;
                    }
                }
            }

            //set defaults
            foreach (
                var port in
                    inPorts.Select((x, i) => new { x, i }).Where(x => !portInfoProcessed.Contains(x.i)))
                port.x.UsingDefaultValue = false;

            if (context == SaveContext.Undo)
            {
                // Fix: MAGN-159 (nodes are not editable after undo/redo).
                //interactionEnabled = helper.ReadBoolean("interactionEnabled", true);
                state = helper.ReadEnum("nodeState", ElementState.Active);

                // We only notify property changes in an undo/redo operation. Normal
                // operations like file loading or copy-paste have the models created
                // in different ways and their views will always be up-to-date with 
                // respect to their models.
                RaisePropertyChanged("InteractionEnabled");
                RaisePropertyChanged("State");
                RaisePropertyChanged("NickName");
                RaisePropertyChanged("ArgumentLacing");
                RaisePropertyChanged("IsVisible");
                RaisePropertyChanged("IsUpstreamVisible");

                // Notify listeners that the position of the node has changed,
                // then all connected connectors will also redraw themselves.
                ReportPosition();
            }
        }
Ejemplo n.º 54
0
 protected override void LoadNode(XmlNode nodeElement)
 {
     base.LoadNode(nodeElement);
     var helper = new XmlElementHelper(nodeElement as XmlElement);
     code = helper.ReadString("CodeText");
     ProcessCodeDirect();
     shouldFocus = helper.ReadBoolean("ShouldFocus");
 }
Ejemplo n.º 55
0
        /// <summary>
        /// Creates <see cref="ModelBase"/> object by given xml data and
        /// adds it to corresponding collection of the workspace.
        /// </summary>
        /// <param name="modelData">Xml data to create model</param>
        public void CreateModel(XmlElement modelData)
        {
            var    helper   = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);

            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto
                // the name of the XmlElement itself, which is usually the type
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                              string.Format("No type information: {0}", guid));
                }
            }

            if (typeName.Contains("ConnectorModel"))
            {
                var connector = NodeGraph.LoadConnectorFromXml(modelData,
                                                               Nodes.ToDictionary(node => node.GUID));

                // It is possible that in some cases connector can't be created,
                // for example, connector connects to a custom node instance
                // whose input ports have been changed, so connector can't find
                // its end port owner.
                if (connector == null)
                {
                    var guidAttribute = modelData.Attributes["guid"];
                    if (guidAttribute == null)
                    {
                        throw new InvalidOperationException("'guid' field missing from recorded model");
                    }
                }
                else
                {
                    OnConnectorAdded(connector); // Update view-model and view.
                }
            }
            else if (typeName.Contains("NoteModel"))
            {
                var noteModel = NodeGraph.LoadNoteFromXml(modelData);
                AddNote(noteModel);

                //check whether this note belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this note "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == noteModel.GUID))
                    {
                        annotation.AddToSelectedModels(noteModel);
                    }
                }
            }
            else if (typeName.Contains("AnnotationModel"))
            {
                var selectedNodes = this.Nodes == null ? null : this.Nodes.Where(s => s.IsSelected);
                var selectedNotes = this.Notes == null ? null : this.Notes.Where(s => s.IsSelected);

                var annotationModel = new AnnotationModel(selectedNodes, selectedNotes);
                annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
                annotationModel.Disposed           += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
                annotationModel.Deserialize(modelData, SaveContext.Undo);
                AddNewAnnotation(annotationModel);
            }

            else if (typeName.Contains("PresetModel"))
            {
                var preset = new PresetModel(this.Nodes);
                preset.Deserialize(modelData, SaveContext.Undo);
                presets.Add(preset);
                //we raise this property change here so that this event bubbles up through
                //the model and to the DynamoViewModel so that presets show in the UI menu if our undo/redo
                //created the first preset
                RaisePropertyChanged("EnablePresetOptions");
            }
            else // Other node types.
            {
                NodeModel nodeModel = NodeFactory.CreateNodeFromXml(modelData, SaveContext.Undo, ElementResolver);

                AddAndRegisterNode(nodeModel);

                //check whether this node belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this node "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == nodeModel.GUID))
                    {
                        annotation.AddToSelectedModels(nodeModel);
                    }
                }
            }
        }