Пример #1
0
        private void ExportElement(EATree element, bool includeElement, string parentId)
        {
            if (includeElement)
            {
                string heading = (element.Heading == null) ? string.Empty : element.Heading.Trim();
                string text    = (element.Text == null) ? string.Empty : element.Text.Trim();

                if (text != null)
                {
                    // Parse the text as HTML and strip all formatting
                    string convertedTitle = ConvertHtmlToPlainText(new HtmlFormatPlainText(HtmlFormatMode.None), heading);
                    string convertedText  = ConvertHtmlToPlainText(new HtmlFormatPlainText(HtmlFormatMode.None), text);
                    Write("{0};{1};", element.Id, parentId);
                    Write("\"");
                    if (convertedTitle != null)
                    {
                        WriteEscaped(convertedTitle);
                    }
                    Write("\";\"");
                    if (convertedText != null)
                    {
                        WriteEscaped(convertedText);
                    }
                    WriteLine("\"");
                }
            }

            foreach (EATree child in element.Children)
            {
                ExportElement(child, true, includeElement ? element.Id : string.Empty);
            }
        }
Пример #2
0
        private XmlNode CreateInfoNode(EATree node)
        {
            bool          hasField = false;
            StringBuilder infoText = new StringBuilder();

            AddField("Requirement", node.Alias, infoText, ref hasField);
            AddField("Author", node.Author, infoText, ref hasField);
            AddField("Stereotype", node.Stereotype, infoText, ref hasField);
            AddField("Status", node.Status, infoText, ref hasField);
            AddField("Version", node.Version, infoText, ref hasField);
            if (node.CreateTime.Ticks != 0)
            {
                AddField("Created", node.CreateTime.ToString("u"), infoText, ref hasField);
            }
            if (node.ModifiedTime.Ticks != 0)
            {
                AddField("Modified", node.ModifiedTime.ToString("u"), infoText, ref hasField);
            }
            if (!hasField)
            {
                return(null);
            }
            infoText.Append(".");

            XmlElement xmlPara     = m_XmlDocument.CreateElement("para");
            XmlElement xmlSuper    = m_XmlDocument.CreateElement("superscript");
            XmlElement xmlItalic   = m_XmlDocument.CreateElement("emphasis");
            XmlText    xmlInfoText = m_XmlDocument.CreateTextNode(infoText.ToString());

            xmlPara.AppendChild(xmlSuper);
            xmlSuper.AppendChild(xmlItalic);
            xmlItalic.AppendChild(xmlInfoText);
            return(xmlPara);
        }
Пример #3
0
        /// <summary>
        /// Exports the tree.
        /// </summary>
        /// <param name="root">The root element.</param>
        /// <param name="includeRoot">if set to <c>true</c> the also export the root element, else
        /// if set to <c>false</c>, then the children are exported.</param>
        public void ExportTree(EATree root, bool includeRoot)
        {
            m_XmlDocument = new XmlDocument()
            {
                XmlResolver = null
            };
            XmlDocumentFragment xmlFragment = m_XmlDocument.CreateDocumentFragment();

            DocBookFormat format = new DocBookFormat();

            if (includeRoot)
            {
                XmlNode xnode = ExportElement(root, format);
                xmlFragment.AppendChild(xnode);
            }
            else
            {
                foreach (EATree child in root.Children)
                {
                    XmlNode xnode = ExportElement(child, format);
                    xmlFragment.AppendChild(xnode);
                }
            }
            xmlFragment.WriteContentTo(m_XmlWriter);
        }
Пример #4
0
        /// <summary>
        /// Adds an element as a child to this element in sorted order.
        /// </summary>
        /// <param name="element">The element to add.</param>
        public void AddChild(EATree element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (m_Children.Count == 0)
            {
                m_Children.AddFirst(element);
                return;
            }

            LinkedListNode <EATree> node = m_Children.First;

            do
            {
                if (element.Pos < node.Value.Pos)
                {
                    m_Children.AddBefore(node, element);
                    return;
                }
                node = node.Next;
            } while (node != null);
            m_Children.AddLast(element);
        }
Пример #5
0
 private void AddElement(EATree element)
 {
     if (m_Elements.ContainsKey(element.Id))
     {
         FileFormatException("XMI malformed, XMI.ID {0} occurs multiple times", element.Id);
         return;
     }
     m_Elements.Add(element.Id, element);
 }
Пример #6
0
        private void LoadUmlModel(XmlReader xmlReader)
        {
            EATrace.XmiImport(xmlReader, TraceEventType.Verbose, "{0}", xmlReader.Name);

            EATree element;

            if (Root == null)
            {
                element = new EATree(xmlReader["xmi.id"], xmlReader["name"], string.Empty, 0);
                Root    = element;
                AddElement(element);
            }
            else
            {
                // We only support a single model in our XMI for now.
                xmlReader.Skip();
                return;
            }

            if (xmlReader.IsEmptyElement)
            {
                return;
            }
            string endElement = xmlReader.Name;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    // This is where you would add support for more fields in the configuration file
                    if (xmlReader.Name.Equals("UML:Namespace.ownedElement"))
                    {
                        LoadUmlNamespaceOwnedElement(xmlReader, element);
                    }
                    else
                    {
                        xmlReader.Skip();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (xmlReader.Name.Equals(endElement))
                    {
                        return;
                    }
                    FileFormatException(xmlReader, "Invalid XML format (expected </{0}>)", endElement);
                    return;
                }
            }

            FileFormatException(xmlReader, "Unexpected end of stream");
        }
Пример #7
0
        private XmlNode ExportElement(EATree element, DocBookFormat format)
        {
            XmlElement xmlSectionElement;

            if (format.SectionDepth == 0)
            {
                xmlSectionElement = m_XmlDocument.CreateElement("chapter");
            }
            else
            {
                xmlSectionElement = m_XmlDocument.CreateElement("section");
            }

            format.SectionDepth++;
            string     heading         = (element.Heading == null) ? string.Empty : element.Heading.Trim();
            XmlElement xmlTitleElement = m_XmlDocument.CreateElement("title");
            XmlText    xmlTitleText    = m_XmlDocument.CreateTextNode(HtmlEntity.DeEntitize(heading));

            xmlTitleElement.AppendChild(xmlTitleText);
            xmlSectionElement.AppendChild(xmlTitleElement);

            string  text     = (element.Text == null) ? string.Empty : element.Text.Trim();
            XmlNode infoNode = CreateInfoNode(element);

            if (infoNode != null)
            {
                xmlSectionElement.AppendChild(infoNode);
            }
            XmlNode textNode = ConvertHtmlToDocBook45(text, format);

            if (textNode != null)
            {
                xmlSectionElement.AppendChild(textNode);
            }

            if (textNode == null && infoNode == null)
            {
                if (element.Children.Count == 0)
                {
                    xmlSectionElement.AppendChild(m_XmlDocument.CreateElement("para"));
                }
            }

            foreach (EATree child in element.Children)
            {
                XmlNode xmlChild = ExportElement(child, format);
                xmlSectionElement.AppendChild(xmlChild);
            }

            format.SectionDepth--;
            return(xmlSectionElement);
        }
Пример #8
0
        private void LoadUmlPackage(XmlReader xmlReader, EATree parent)
        {
            EATrace.XmiImport(xmlReader, TraceEventType.Verbose, "{0}", xmlReader.Name);

            EATree package = new EATree(parent.Id, xmlReader["xmi.id"], xmlReader["name"], string.Empty, 0);

            AddElement(package);

            if (xmlReader.IsEmptyElement)
            {
                return;
            }
            string endElement = xmlReader.Name;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    // This is where you would add support for more fields in the configuration file
                    if (xmlReader.Name.Equals("UML:ModelElement.taggedValue"))
                    {
                        LoadUmlModelElementTaggedValue(xmlReader, package);
                    }
                    else if (xmlReader.Name.Equals("UML:ModelElement.stereotype"))
                    {
                        LoadUmlModelElementStereotype(xmlReader, package);
                    }
                    else if (xmlReader.Name.Equals("UML:Namespace.ownedElement"))
                    {
                        LoadUmlNamespaceOwnedElement(xmlReader, package);
                    }
                    else
                    {
                        xmlReader.Skip();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (xmlReader.Name.Equals(endElement))
                    {
                        return;
                    }
                    FileFormatException(xmlReader, "Invalid configuration XML format (expected </{0}>)", endElement);
                    return;
                }
            }

            FileFormatException(xmlReader, "Unexpected end of stream");
        }
Пример #9
0
        private void LoadUmlNamespaceOwnedElement(XmlReader xmlReader, EATree parent)
        {
            EATrace.XmiImport(xmlReader, TraceEventType.Verbose, "{0}", xmlReader.Name);

            if (xmlReader.IsEmptyElement)
            {
                return;
            }
            string endElement = xmlReader.Name;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    // This is where you would add support for more fields in the configuration file
                    if (xmlReader.Name.Equals("UML:Package"))
                    {
                        LoadUmlPackage(xmlReader, parent);
                    }
                    else if (xmlReader.Name.Equals("UML:Collaboration"))
                    {
                        LoadUmlCollaboration(xmlReader, parent);
                    }
                    else if (xmlReader.Name.Equals("UML:ClassifierRole"))
                    {
                        LoadUmlClassifierRole(xmlReader);
                    }
                    else
                    {
                        xmlReader.Skip();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (xmlReader.Name.Equals(endElement))
                    {
                        return;
                    }
                    FileFormatException(xmlReader, "Invalid configuration XML format (expected </{0}>)", endElement);
                    return;
                }
            }

            FileFormatException(xmlReader, "Unexpected end of stream");
        }
Пример #10
0
        private void ExportElement(EATree element, bool includeElement, string parentId)
        {
            if (includeElement)
            {
                string heading = (element.Heading == null) ? string.Empty : element.Heading.Trim();
                string text    = (element.Text == null) ? string.Empty : element.Text.Trim();
                m_Writer.WriteLine("{0};{1};\"{2}\";\"{3}\"",
                                   element.Id, parentId,
                                   StringUtilities.SearchAndReplace(heading, m_Conversions),
                                   StringUtilities.SearchAndReplace(text, m_Conversions));
            }

            foreach (EATree child in element.Children)
            {
                ExportElement(child, true, includeElement ? element.Id : string.Empty);
            }
        }
Пример #11
0
 public EATree FindGuid(EATree node, string guid)
 {
     if (node == null)
     {
         return(null);
     }
     if (node.Id.Equals(guid))
     {
         return(node);
     }
     foreach (EATree child in node.Children)
     {
         EATree found = FindGuid(child, guid);
         if (found != null)
         {
             return(found);
         }
     }
     return(null);
 }
Пример #12
0
        private void LoadUmlModelElementStereotype(XmlReader xmlReader, EATree parent)
        {
            EATrace.XmiImport(xmlReader, TraceEventType.Verbose, "{0}", xmlReader.Name);

            if (xmlReader.IsEmptyElement)
            {
                return;
            }
            string endElement = xmlReader.Name;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    if (xmlReader.Name.Equals("UML:Stereotype"))
                    {
                        parent.Stereotype = xmlReader["name"];
                    }
                    else
                    {
                        xmlReader.Skip();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (xmlReader.Name.Equals(endElement))
                    {
                        return;
                    }
                    FileFormatException(xmlReader, "Invalid configuration XML format (expected </{0}>)", endElement);
                    return;
                }
            }

            FileFormatException(xmlReader, "Unexpected end of stream");
        }
Пример #13
0
        private void mnuFileExportDB45Chapters_Click(object sender, EventArgs e)
        {
            Model.EATree element = GetElement();
            if (element == null)
            {
                return;
            }

            string fileName = GetFileName("xml", "DocBook 4.5 (*.xml)|*.xml", "Save As DocBook 4.5 with Chapters");

            if (fileName == null)
            {
                return;
            }

            try {
                using (Model.ITreeExport exportFormat = new Model.DocBook45ChapterExport(fileName)) {
                    exportFormat.ExportTree(element, false);
                }
            } catch (System.Exception exception) {
                EATrace.XmiImport(System.Diagnostics.TraceEventType.Warning, "EAExport DocBook 4.5 Chapter Export Failure: {0}", exception.Message);
                MessageBox.Show(exception.Message, "EAExport DocBook 4.5 Chapter Export Failure");
            }
        }
Пример #14
0
        private void mnuFileExportCsvPlain_Click(object sender, EventArgs e)
        {
            Model.EATree element = GetElement();
            if (element == null)
            {
                return;
            }

            string fileName = GetFileName("csv", "CSV (*.csv)|*.csv", "Save As CSV Plain Text File");

            if (fileName == null)
            {
                return;
            }

            try {
                using (Model.ITreeExport exportFormat = new Model.CsvDoorsTreePlainExport(fileName)) {
                    exportFormat.ExportTree(element, false);
                }
            } catch (System.Exception exception) {
                EATrace.XmiImport(System.Diagnostics.TraceEventType.Warning, "EAExport CSV Export Failure: {0}", exception.Message);
                MessageBox.Show(exception.Message, "EAExport CSV Export Failure");
            }
        }
Пример #15
0
        private void BuildTree(TreeNode parent, Model.EATree element, TreeStatistics statistics)
        {
            TreeNode node;

            StringBuilder heading = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(element.Stereotype))
            {
                heading.Append("«").Append(element.Stereotype).Append("» ");
            }
            heading.Append(element.Heading);
            if (!string.IsNullOrWhiteSpace(element.Alias))
            {
                heading.Append(" (").Append(element.Alias).Append(")");
            }

            node = new TreeNode(heading.ToString())
            {
                Tag = element
            };
            if (parent == null)
            {
                treXmiStructure.Nodes.Add(node);
            }
            else
            {
                parent.Nodes.Add(node);
            }
            statistics.Nodes++;
            if (string.Compare(element.Alias, statistics.MaxAlias) > 0)
            {
                statistics.MaxAlias = element.Alias;
            }

            if (element.Id.StartsWith("MX_EAID_"))
            {
                node.ImageKey = "Model";
            }
            else if (element.Id.StartsWith("EAPK"))
            {
                node.ImageKey = "Specification";
            }
            else if (element.Status != null)
            {
                if (element.Status.Equals("Approved", StringComparison.InvariantCultureIgnoreCase))
                {
                    node.ImageKey = "RequirementApproved";
                }
                else if (element.Status.Equals("Implemented", StringComparison.InvariantCultureIgnoreCase))
                {
                    node.ImageKey = "RequirementImplemented";
                }
                else if (element.Status.Equals("Mandatory", StringComparison.InvariantCultureIgnoreCase))
                {
                    node.ImageKey = "RequirementMandatory";
                }
                else if (element.Status.Equals("Proposed", StringComparison.InvariantCultureIgnoreCase))
                {
                    node.ImageKey = "RequirementProposed";
                }
                else if (element.Status.Equals("Validated", StringComparison.InvariantCultureIgnoreCase))
                {
                    node.ImageKey = "RequirementValidated";
                }
                else
                {
                    node.ImageKey = "Requirement";
                }
            }
            else
            {
                node.ImageKey = "Requirement";
            }
            node.SelectedImageKey = node.ImageKey;

            foreach (Model.EATree child in element.Children)
            {
                BuildTree(node, child, statistics);
            }
        }
Пример #16
0
 /// <summary>
 /// Exports the tree.
 /// </summary>
 /// <param name="root">The root element.</param>
 /// <param name="includeRoot">if set to <c>true</c> the also export the root element, else
 /// if set to <c>false</c>, then the children are exported.</param>
 public void ExportTree(EATree root, bool includeRoot)
 {
     WriteLine("EAID;EAParent;Heading;Text");
     ExportElement(root, includeRoot, root.Id);
 }
Пример #17
0
 /// <summary>
 /// Exports the tree.
 /// </summary>
 /// <param name="root">The root element.</param>
 /// <param name="includeRoot">if set to <c>true</c> the also export the root element, else
 /// if set to <c>false</c>, then the children are exported.</param>
 public void ExportTree(EATree root, bool includeRoot)
 {
     ExportElement(root, includeRoot, root.Id);
 }
Пример #18
0
        private void LoadUmlModelElementTaggedValue(XmlReader xmlReader, EATree parent)
        {
            EATrace.XmiImport(xmlReader, TraceEventType.Verbose, "{0}", xmlReader.Name);

            if (xmlReader.IsEmptyElement)
            {
                return;
            }
            string endElement = xmlReader.Name;

            string owner    = null;
            string package  = null;
            string package2 = null;
            string tpos     = null;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    if (xmlReader.Name.Equals("UML:TaggedValue"))
                    {
                        EATrace.XmiImport(xmlReader, TraceEventType.Verbose, "Tagged Value: {0} = {1}", xmlReader["tag"], xmlReader["value"]);
                        if (xmlReader["tag"].Equals("owner"))
                        {
                            owner = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("package"))
                        {
                            package = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("tpos"))
                        {
                            tpos = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("documentation"))
                        {
                            parent.Text = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("package2"))
                        {
                            package2 = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("alias"))
                        {
                            parent.Alias = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("version"))
                        {
                            parent.Version = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("author"))
                        {
                            parent.Author = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("status"))
                        {
                            parent.Status = xmlReader["value"];
                        }
                        else if (xmlReader["tag"].Equals("date_created"))
                        {
                            parent.CreateTime = ConvertDateTime(xmlReader["value"]);
                        }
                        else if (xmlReader["tag"].Equals("date_modified"))
                        {
                            parent.ModifiedTime = ConvertDateTime(xmlReader["value"]);
                        }

                        if (!xmlReader.IsEmptyElement)
                        {
                            xmlReader.Skip();
                        }
                    }
                    else
                    {
                        xmlReader.Skip();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (xmlReader.Name.Equals(endElement))
                    {
                        if (parent.ParentId == null)
                        {
                            if (owner != null)
                            {
                                parent.ParentId = owner;
                            }
                            else if (package != null)
                            {
                                parent.ParentId = package;
                            }
                        }

                        if (package2 != null)
                        {
                            // In EA, we see a package contains a ClassifierRole object as well as a Package.
                            // We need to filter these ClassifierRole objects out, else they occur twice in
                            // the tree. We assume that 'package2' is the same as the element ID.
                            m_PackageElements.Add(parent.Id, parent);
                        }

                        if (tpos != null)
                        {
                            parent.Pos = int.Parse(tpos);
                        }
                        return;
                    }
                    FileFormatException(xmlReader, "Invalid configuration XML format (expected </{0}>)", endElement);
                    return;
                }
            }

            FileFormatException(xmlReader, "Unexpected end of stream");
        }