public DummyNode(int inputCount, int outputCount, string legacyName, XmlElement originalElement, string legacyAssembly, Nature nodeNature) { InputCount = inputCount; OutputCount = outputCount; LegacyNodeName = legacyName; NickName = legacyName; OriginalNodeContent = originalElement; LegacyAssembly = legacyAssembly; NodeNature = nodeNature; Description = GetDescription(); ShouldDisplayPreviewCore = false; UpdatePorts(); // Take the position from the old node (because a dummy node // should always be created at the location of the old node). var helper = new XmlElementHelper(originalElement); X = helper.ReadDouble("x", 0.0); Y = helper.ReadDouble("y", 0.0); //Take the GUID from the old node (dummy nodes should have their //GUID's. This will allow the Groups to work as expected. MAGN-7568) GUID = helper.ReadGuid("guid", this.GUID); }
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); }
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); }
protected override void SerializeCore(XmlElement element, SaveContext context) { var helper = new XmlElementHelper(element); helper.SetAttribute("guid", GUID); helper.SetAttribute("text", Text); helper.SetAttribute("x", X); helper.SetAttribute("y", Y); }
protected override void SerializeCore(XmlElement nodeElement, SaveContext context) { base.SerializeCore(nodeElement, context); XmlElement outEl = nodeElement.OwnerDocument.CreateElement(typeof(string).FullName); var helper = new XmlElementHelper(outEl); helper.SetAttribute("value", SerializeValue()); nodeElement.AppendChild(outEl); }
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(); }
public void TestDoubleAttributes() { XmlElement element = xmlDocument.CreateElement("element"); // Test attribute writing. XmlElementHelper writer = new XmlElementHelper(element); writer.SetAttribute("ValidName", -12.34); // Test reading of existing attribute. XmlElementHelper reader = new XmlElementHelper(element); Assert.AreEqual(-12.34, reader.ReadDouble("ValidName")); // Test reading of non-existence attribute with default value. Assert.AreEqual(56.78, reader.ReadDouble("InvalidName", 56.78)); // Test reading of non-existence attribute without default value. Assert.Throws<InvalidOperationException>(() => { reader.ReadDouble("InvalidName"); }); }
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"); }); }
/// <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"); //find the elements to connect NodeModel start; if (nodes.TryGetValue(guidStart, out start)) { NodeModel end; if (nodes.TryGetValue(guidEnd, out end)) { return ConnectorModel.Make(start, end, startIndex, endIndex, guid); } } return null; }
/// <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(nameof(ConnectorPinModel))) { var connectorPin = NodeGraph.LoadPinFromXml(modelData); var matchingConnector = Connectors.FirstOrDefault(c => c.GUID == connectorPin.ConnectorId); if (matchingConnector is null) { return; } matchingConnector.AddPin(connectorPin); } 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); } } } }
protected override void SerializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("CmdOperation", ((int)CmdOperation)); }
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; }
void SerializeCore(XmlElement element, SaveContext context) { XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("guid", this.GUID); helper.SetAttribute("annotationText", this.AnnotationText); helper.SetAttribute("left", this.X); helper.SetAttribute("top", this.Y); helper.SetAttribute("width", this.Width); helper.SetAttribute("height", this.Height); helper.SetAttribute("fontSize", this.FontSize); helper.SetAttribute("InitialTop", this.InitialTop); helper.SetAttribute("InitialHeight", this.InitialHeight); helper.SetAttribute("TextblockHeight", this.TextBlockHeight); helper.SetAttribute("backgrouund", (this.Background == null ? "" : this.Background.ToString())); //Serialize Selected models XmlDocument xmlDoc = element.OwnerDocument; foreach (var guids in this.SelectedModels.Select(x => x.GUID)) { if (xmlDoc != null) { var modelElement = xmlDoc.CreateElement("Models"); element.AppendChild(modelElement); XmlElementHelper mhelper = new XmlElementHelper(modelElement); modelElement.SetAttribute("ModelGuid", guids.ToString()); } } }
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); } } } }
protected override void SerializeCore(XmlElement element, SaveContext context) { base.SerializeCore(element, context); //Base implementation must be called if (context != SaveContext.Undo) return; var helper = new XmlElementHelper(element); helper.SetAttribute("functionId", Definition.FunctionId.ToString()); helper.SetAttribute("functionName", NickName); helper.SetAttribute("functionDesc", Description); XmlDocument xmlDoc = element.OwnerDocument; foreach (string input in InPortData.Select(x => x.NickName)) { XmlElement inputEl = xmlDoc.CreateElement("functionInput"); inputEl.SetAttribute("inputValue", input); element.AppendChild(inputEl); } foreach (string input in OutPortData.Select(x => x.NickName)) { XmlElement outputEl = xmlDoc.CreateElement("functionOutput"); outputEl.SetAttribute("outputValue", input); element.AppendChild(outputEl); } }
protected override void SerializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("ModelGuid", ModelGuid); helper.SetAttribute("Name", Name); helper.SetAttribute("Value", Value); }
protected override void SerializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("TabIndex", TabIndex); }
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 = dynSettings.Controller.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"); } }
protected override void SerializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("ModelGuid", ModelGuid); }
protected override void SerializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); }
protected override void SerializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("XmlFilePath", XmlFilePath); }
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); }
protected override void SerializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("NodeId", NodeId); }
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); }
internal static SwitchTabCommand DeserializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); return(new SwitchTabCommand(helper.ReadInteger("TabIndex"))); }
internal static ConvertNodesToCodeCommand DeserializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); Guid nodeId = helper.ReadGuid("NodeId"); return new ConvertNodesToCodeCommand(nodeId); }
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"); } }
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")); }
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)); }
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))); }
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(); } }
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"); }
protected override void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context) { base.SaveNode(xmlDoc, nodeElement, context); var helper = new XmlElementHelper(nodeElement); helper.SetAttribute("CodeText", code); helper.SetAttribute("ShouldFocus", shouldFocus); }
protected override void SerializeCore(XmlElement element, SaveContext context) { base.SerializeCore(element, context); var helper = new XmlElementHelper(element); helper.SetAttribute("Script", this.Script); }
static void Main(string[] args) { //take in a dynamo file and a diffset file //iterate the diffs and then make annotations in the dyn //depending on the kind of diff we do something different...use different colors //for instance try { var dynpath = args[0]; var diffpath = args[1]; var doc = new XmlDocument(); doc.Load(dynpath); Console.WriteLine("now attempting to deserialze the diff file "); //deserialze the diffset DiffOnDyn.DiffSet diffFromFile; // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer mySerializer = new XmlSerializer(typeof(DiffOnDyn.DiffSet)); // To read the file, create a FileStream. FileStream myFileStream = new FileStream(diffpath, FileMode.Open); // Call the Deserialize method and cast to the object type. diffFromFile = (DiffOnDyn.DiffSet) mySerializer.Deserialize(myFileStream); Console.WriteLine("now attempting to generate annotations "); var annotationList = doc.GetElementsByTagName("Annotations")[0]; if (annotationList == null) { annotationList = doc.CreateElement("Annotations"); } ; doc.DocumentElement.AppendChild(annotationList); foreach (var change in diffFromFile.NodeChanges) { if (change is NodeChange) { if (change.Status == "added") { var tempdoc = new XmlDocument(); tempdoc.LoadXml(change.MetaData.Inspect); var elementsList = doc.GetElementsByTagName("Elements")[0]; //necessary for crossing XmlDocument contexts XmlNode importNode = elementsList.OwnerDocument.ImportNode(tempdoc.DocumentElement, true); //now the node is added... //lets add it to an annoation by its guid elementsList.AppendChild(importNode); //add a new node... we have to create the node from the change issues var element = doc.CreateElement("Dynamo.Models.AnnotationModel"); XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("guid", Guid.NewGuid()); helper.SetAttribute("annotationText", "a addition"); helper.SetAttribute("left", 1); helper.SetAttribute("top", 1); helper.SetAttribute("width", 100); helper.SetAttribute("height", 100); helper.SetAttribute("fontSize", 20); helper.SetAttribute("InitialTop", 100); helper.SetAttribute("InitialHeight", 100); helper.SetAttribute("TextblockHeight", 100); helper.SetAttribute("backgrouund", ("#00FF00")); var groupedElement = doc.CreateElement("Models"); groupedElement.SetAttribute("ModelGuid", change.InstanceGuid); element.AppendChild(groupedElement); annotationList.AppendChild(element); //add a new node and color it green...#00FF00 } if (change.Status == "removed") { //color an existing node red by adding to red group var element = doc.CreateElement("Dynamo.Models.AnnotationModel"); XmlElementHelper helper = new XmlElementHelper(element); helper.SetAttribute("guid", Guid.NewGuid()); helper.SetAttribute("annotationText", "a deletion"); helper.SetAttribute("left", 1); helper.SetAttribute("top", 1); helper.SetAttribute("width", 100); helper.SetAttribute("height", 100); helper.SetAttribute("fontSize", 20); helper.SetAttribute("InitialTop", 100); helper.SetAttribute("InitialHeight", 100); helper.SetAttribute("TextblockHeight", 100); helper.SetAttribute("backgrouund", ("#FF0000")); var groupedElement = doc.CreateElement("Models"); groupedElement.SetAttribute("ModelGuid", change.InstanceGuid); element.AppendChild(groupedElement); annotationList.AppendChild(element); } } } var outdoc = new XmlDocument(); doc.Save(dynpath + "diffview" + ".dyn"); //now apply the diff, this will create some groups for now } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }
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"); }
internal static UndoRedoCommand DeserializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); int operation = helper.ReadInteger("CmdOperation"); return new UndoRedoCommand((Operation)operation); }
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 DeleteModelCommand DeserializeCore(XmlElement element) { XmlElementHelper helper = new XmlElementHelper(element); Guid modelGuid = helper.ReadGuid("ModelGuid"); return new DeleteModelCommand(modelGuid); }
protected override void SerializeCore(XmlElement element, SaveContext context) { base.SerializeCore(element, context); var helper = new XmlElementHelper(element); helper.SetAttribute("CodeText", code); helper.SetAttribute("ShouldFocus", shouldFocus); }
protected override void SerializeCore(XmlElement element) { var helper = new XmlElementHelper(element); helper.SetAttribute("NodeId", NodeId); }