Ejemplo n.º 1
0
        static ChartPage LoadChartDocument(Version documentVersion, XmlElement node)
        {
            ChartPage chart     = null;
            ChartType chartType = ST.GetEnumValue(node.GetAttribute("type"), ChartType.MindMap);

            switch (chartType)
            {
            case ChartType.MindMap:
                chart = new MindMap();    // MindMapIO.LoadAsXml(chartElement);
                break;

            default:
                return(null);
            }

            if (chart != null)
            {
                chart.Deserialize(documentVersion, node);
            }

            return(chart);
        }
Ejemplo n.º 2
0
        public static Document Load(XmlDocument dom)
        {
            if (dom.DocumentElement == null)
            {
                return(null);
            }

            // version
            var documentVersion = Document.DocumentVersion;

            if (dom.DocumentElement.HasAttribute("document_version"))
            {
                documentVersion = new Version(dom.DocumentElement.GetAttribute("document_version"));
            }
            else if (dom.DocumentElement.HasAttribute("editor_version"))
            {
                documentVersion = new Version(dom.DocumentElement.GetAttribute("editor_version"));
                if (documentVersion.Major == 3) // 3.0早期的beta版本没有 documentVersion, 而其editor_version 可能略大 DocumentVersion
                {
                    documentVersion = Document.DV_3;
                }
            }
            if (documentVersion > DocumentVersion)
            {
                throw new Exception("Unsupport Document Version");
            }

            // old version document, one chart in a document, 1.5.0 or earlier
            if (dom.DocumentElement.Name == "map")
            {
                return(LoadSingleMindMap(documentVersion, dom));
            }

            // new document, multi-charts in a document
            if (dom.DocumentElement.Name != "document")
            {
                return(null);
            }

            //
            var doc = new Document();

            // information
            var infos = dom.DocumentElement.SelectSingleNode("information") as XmlElement;

            if (infos != null)
            {
                if (documentVersion < Document.DV_3) // 老式的写法
                {
                    doc.Author      = ST.ReadTextNode(infos, "Author");
                    doc.Company     = ST.ReadTextNode(infos, "Company");
                    doc.Version     = ST.ReadTextNode(infos, "Version");
                    doc.Description = ST.ReadTextNode(infos, "Description");
                }
                else
                {
                    doc.Author      = ST.ReadTextNode(infos, "author");
                    doc.Company     = ST.ReadTextNode(infos, "company");
                    doc.Version     = ST.ReadTextNode(infos, "version");
                    doc.Description = ST.ReadTextNode(infos, "description");
                }
            }

            // attributes
            var attrs = dom.DocumentElement.SelectSingleNode("attributes") as XmlElement;

            if (attrs != null)
            {
                foreach (XmlNode attr in attrs.ChildNodes)
                {
                    if (!(attr is XmlElement))
                    {
                        continue;
                    }
                    XmlElement attr_e = (XmlElement)attr;
                    if (attr_e.Name != "item")
                    {
                        continue;
                    }

                    doc.Attributes[attr_e.GetAttribute("name")] = attr_e.InnerText;
                }
            }

            // charts
            var charts = dom.DocumentElement.SelectSingleNode("charts") as XmlElement;

            if (charts != null)
            {
                foreach (XmlNode chart in charts)
                {
                    if (!(chart is XmlElement))
                    {
                        continue;
                    }
                    XmlElement chart_e = (XmlElement)chart;
                    if (chart_e.Name != "chart")
                    {
                        continue;
                    }

                    ChartPage cdoc = LoadChartDocument(documentVersion, chart_e);
                    if (cdoc != null)
                    {
                        doc.Charts.Add(cdoc);
                    }
                }

                doc.ActiveChartIndex = ST.GetIntDefault(charts.GetAttribute("active_chart"));
            }

            doc.Modified = false;
            return(doc);
        }