internal static RunCancelCommand DeserializeCore(XmlElement element) { var helper = new XmlElementHelper(element); bool showErrors = helper.ReadBoolean("ShowErrors"); bool cancelRun = helper.ReadBoolean("CancelRun"); return(new RunCancelCommand(showErrors, cancelRun)); }
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"))); }
protected override void DeserializeCore(XmlElement nodeElement, SaveContext context) { var helper = new XmlElementHelper(nodeElement); IsHidden = helper.ReadBoolean(nameof(IsHidden)); //This is now handled via NodeGraph.LoadConnectorFromXml }
private bool LoadCommandFromFile(string commandFilePath) { if (string.IsNullOrEmpty(commandFilePath)) { return(false); } if (File.Exists(commandFilePath) == false) { return(false); } if (null != loadedCommands) { throw new InvalidOperationException( "Internal error: 'LoadCommandFromFile' called twice"); } try { // Attempt to load the XML from the specified path. XmlDocument document = new XmlDocument(); document.Load(commandFilePath); // Get to the root node of this Xml document. XmlElement commandRoot = document.FirstChild as XmlElement; if (null == commandRoot || (null == commandRoot.ChildNodes)) { return(false); } // Read in optional attributes from the command root element. XmlElementHelper helper = new XmlElementHelper(commandRoot); this.ExitAfterPlayback = helper.ReadBoolean(ExitAttribName, true); this.PauseAfterPlayback = helper.ReadInteger(PauseAttribName, 10); this.CommandInterval = helper.ReadInteger(IntervalAttribName, 20); loadedCommands = new List <DynCmd.RecordableCommand>(); foreach (XmlNode node in commandRoot.ChildNodes) { DynCmd.RecordableCommand command = null; command = DynCmd.RecordableCommand.Deserialize(node as XmlElement); if (null != command) { loadedCommands.Add(command); } } } catch (Exception) { // Something is wrong with the Xml file, invalidate the // data member that points to it, and return from here. return(false); } // Even though the Xml file can properly be loaded, it is still // possible that the loaded content did not result in any useful // commands. In this case simply return false, indicating failure. // return(null != loadedCommands && (loadedCommands.Count > 0)); }
/// <summary> /// Creates and initializes a ConnectorModel from its Xml representation. /// </summary> /// <param name="connEl">XmlElement for a ConnectorModel.</param> /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param> /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns> public static ConnectorModel LoadConnectorFromXml(XmlElement connEl, IDictionary <Guid, NodeModel> nodes) { var helper = new XmlElementHelper(connEl); var guid = helper.ReadGuid("guid", Guid.NewGuid()); var guidStart = helper.ReadGuid("start"); var guidEnd = helper.ReadGuid("end"); int startIndex = helper.ReadInteger("start_index"); int endIndex = helper.ReadInteger("end_index"); bool isHidden = helper.HasAttribute(nameof(ConnectorModel.IsHidden)) ? helper.ReadBoolean(nameof(ConnectorModel.IsHidden)) : false; //find the elements to connect NodeModel start; if (nodes.TryGetValue(guidStart, out start)) { NodeModel end; if (nodes.TryGetValue(guidEnd, out end)) { var connector = ConnectorModel.Make(start, end, startIndex, endIndex, guid); if (connector != null) { connector.IsHidden = isHidden; return(connector); } } } return(null); }
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(); }
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"); }
internal static CreateNoteCommand DeserializeCore(XmlElement element) { var 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"))); }
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"))); }
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)); }
internal static SelectInRegionCommand DeserializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); double x = helper.ReadDouble("X"); double y = helper.ReadDouble("Y"); double width = helper.ReadDouble("Width"); double height = helper.ReadDouble("Height"); Rect region = new Rect(x, y, width, height); bool isCrossSelection = helper.ReadBoolean("IsCrossSelection"); return(new SelectInRegionCommand(region, isCrossSelection)); }
public void TestBooleanAttributes() { XmlElement element = xmlDocument.CreateElement("element"); // Test attribute writing. XmlElementHelper writer = new XmlElementHelper(element); writer.SetAttribute("ValidName", true); // Test reading of existing attribute. XmlElementHelper reader = new XmlElementHelper(element); Assert.AreEqual(true, reader.ReadBoolean("ValidName")); // Test reading of non-existence attribute with default value. Assert.AreEqual(true, reader.ReadBoolean("InvalidName", true)); Assert.AreEqual(false, reader.ReadBoolean("InvalidName", false)); // Test reading of non-existence attribute without default value. Assert.Throws <InvalidOperationException>(() => { reader.ReadBoolean("InvalidName"); }); }
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(); }
public void TestBooleanAttributes() { XmlElement element = xmlDocument.CreateElement("element"); // Test attribute writing. XmlElementHelper writer = new XmlElementHelper(element); writer.SetAttribute("ValidName", true); // Test reading of existing attribute. XmlElementHelper reader = new XmlElementHelper(element); Assert.AreEqual(true, reader.ReadBoolean("ValidName")); // Test reading of non-existence attribute with default value. Assert.AreEqual(true, reader.ReadBoolean("InvalidName", true)); Assert.AreEqual(false, reader.ReadBoolean("InvalidName", false)); // Test reading of non-existence attribute without default value. Assert.Throws<InvalidOperationException>(() => { reader.ReadBoolean("InvalidName"); }); }
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(); } }
internal static SelectInRegionCommand DeserializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); double x = helper.ReadDouble("X"); double y = helper.ReadDouble("Y"); double width = helper.ReadDouble("Width"); double height = helper.ReadDouble("Height"); Rect region = new Rect(x, y, width, height); bool isCrossSelection = helper.ReadBoolean("IsCrossSelection"); return new SelectInRegionCommand(region, isCrossSelection); }
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")); }
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")); }
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")); }
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"); var childNodes = nodeElement.ChildNodes.Cast<XmlElement>().ToList(); var inputPortHelpers = childNodes.Where(node => node.Name.Equals("PortInfo")).Select(x => new XmlElementHelper(x)); // read and set input port info inputPortNames = inputPortHelpers.Select(x => x.ReadString("name", String.Empty)) .Where(y => !string.IsNullOrEmpty(y)) .ToList(); SetInputPorts(); // read and set ouput port info var outputPortHelpers = childNodes.Where(node => node.Name.Equals("OutPortInfo")).Select(x => new XmlElementHelper(x)); var lineNumbers = outputPortHelpers.Select(x => x.ReadInteger("LineIndex")).ToList(); foreach (var line in lineNumbers) { var tooltip = Formatting.TOOL_TIP_FOR_TEMP_VARIABLE; OutPorts.Add(new PortModel(PortType.Output, this, new PortData(string.Empty, tooltip) { LineIndex = line, // Logical line index. Height = Configurations.CodeBlockPortHeightInPixels })); } ProcessCodeDirect(); }
internal static RunCancelCommand DeserializeCore(XmlElement element) { var helper = new XmlElementHelper(element); bool showErrors = helper.ReadBoolean("ShowErrors"); bool cancelRun = helper.ReadBoolean("CancelRun"); return new RunCancelCommand(showErrors, cancelRun); }
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(); } }
private bool LoadCommandFromFile(string commandFilePath) { if (string.IsNullOrEmpty(commandFilePath)) return false; if (File.Exists(commandFilePath) == false) return false; if (null != loadedCommands) { throw new InvalidOperationException( "Internal error: 'LoadCommandFromFile' called twice"); } try { // Attempt to load the XML from the specified path. var document = new XmlDocument(); document.Load(commandFilePath); // Get to the root node of this Xml document. var commandRoot = document.FirstChild as XmlElement; if (null == commandRoot) return false; // Read in optional attributes from the command root element. var helper = new XmlElementHelper(commandRoot); ExitAfterPlayback = helper.ReadBoolean(EXIT_ATTRIB_NAME, true); PauseAfterPlayback = helper.ReadInteger(PAUSE_ATTRIB_NAME, 10); CommandInterval = helper.ReadInteger(INTERVAL_ATTRIB_NAME, 20); loadedCommands = new List<DynamoModel.RecordableCommand>(); foreach ( DynamoModel.RecordableCommand command in commandRoot.ChildNodes.Cast<XmlNode>() .Select( node => DynamoModel.RecordableCommand.Deserialize( node as XmlElement)) .Where(command => null != command)) { loadedCommands.Add(command); } } catch (Exception) { // Something is wrong with the Xml file, invalidate the // data member that points to it, and return from here. return false; } // Even though the Xml file can properly be loaded, it is still // possible that the loaded content did not result in any useful // commands. In this case simply return false, indicating failure. // return (null != loadedCommands && (loadedCommands.Count > 0)); }
internal static CreateAnnotationCommand DeserializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); var modelGuids = DeserializeGuid(element, helper); string annotationText = helper.ReadString("AnnotationText"); double x = helper.ReadDouble("X"); double y = helper.ReadDouble("Y"); return new CreateAnnotationCommand(modelGuids, annotationText, x, y, helper.ReadBoolean("DefaultPosition")); }
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); }
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); }
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(); } }