public string Render(Type type, Type[] onlyTypes, string[] onlyMethods) { if (File.Exists(_sourcePath)) { var fileName = _sourcePath.Replace(".txt", ".xml"); if (File.Exists(fileName)) { File.Delete(fileName); } var dict = Parser.ParseText(_sourcePath); if (dict.Any()) { var model = new mxGraphModel { dx = ushort.Parse(AppConfig.DrawIOSettings["dx"]) , dy = ushort.Parse(AppConfig.DrawIOSettings["dy"]) , grid = byte.Parse(AppConfig.DrawIOSettings["grid"]) }; if (XmlHelper <mxGraphModel> .Save(fileName, model)) { return(fileName); } } } return(string.Empty); }
/// <summary> /// Encodes the given mxGraphModel by writing a (flat) XML sequence /// of cell nodes as produced by the mxCellCodec. The sequence is /// wrapped-up in a node with the name root. /// </summary> protected override void EncodeObject(mxCodec enc, Object obj, XmlNode node) { if (obj is mxGraphModel) { XmlNode rootNode = enc.Document.CreateElement("root"); mxGraphModel model = (mxGraphModel)obj; enc.EncodeCell((mxICell)model.Root, rootNode, true); node.AppendChild(rootNode); } }
/// <summary> /// Reads the cells into the graph model. All cells are children of the root /// element in the node. /// </summary> public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object into) { if (node is XmlElement) { XmlElement elt = (XmlElement)node; mxGraphModel model = null; if (into is mxGraphModel) { model = (mxGraphModel)into; } else { model = new mxGraphModel(); } // Reads the cells into the graph model. All cells // are children of the root element in the node. XmlNode root = elt.GetElementsByTagName("root")[0]; mxICell rootCell = null; if (root != null) { XmlNode tmp = root.FirstChild; while (tmp != null) { mxICell cell = dec.DecodeCell(tmp, true); if (cell != null && cell.Parent == null) { rootCell = cell; } tmp = tmp.NextSibling; } root.ParentNode.RemoveChild(root); } // Sets the root on the model if one has been decoded if (rootCell != null) { model.Root = rootCell; } } return(node); }
public void SaveDiagramXml(int assessmentId, mxGraphModel diagramXml) { using (var sww = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(sww)) { XmlSerializer serializer = new XmlSerializer(typeof(mxGraphModel)); serializer.Serialize(writer, diagramXml); string xml = sww.ToString(); var assessment = db.ASSESSMENTS.FirstOrDefault(x => x.Assessment_Id == assessmentId); var xDoc = new XmlDocument(); xDoc.LoadXml(xml); if (assessment != null) { SaveDiagram(assessmentId, xDoc, new DiagramRequest() { LastUsedComponentNumber = assessment.LastUsedComponentNumber, DiagramSvg = assessment.Diagram_Image }); } } } }