コード例 #1
0
        /// <summary>
        /// Serializes counting informations.
        /// </summary>
        /// <param name="element">An <see cref="XmlElement"/> node
        /// used to write counting informations.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/> is null.
        /// </exception>
        internal void Serialize(XmlElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            XmlDocument document      = element.OwnerDocument;
            XmlElement  nameElement   = document.CreateElement("Name");
            XmlElement  resultElement = document.CreateElement("Result");

            element.AppendChild(nameElement);
            element.AppendChild(resultElement);

            nameElement.InnerText = name;
            if (report != null)
            {
                report.Serialize(resultElement);
            }
            foreach (SourceFile file in files.Values)
            {
                XmlElement fileElement = document.CreateElement("File");
                file.Serialize(fileElement);
                element.AppendChild(fileElement);
            }
        }
コード例 #2
0
ファイル: FileSet.cs プロジェクト: michaeloed/SourceCounter
        /// <summary>
        /// Generates an XML report document that represents all the
        /// informations of a succesful counting.
        /// </summary>
        /// <remarks>A DTD description will be added to the document.
        /// If the document is created before the counting succeeds,
        /// the document will be missing relevant report elements.</remarks>
        /// <returns>An XML document containing report informations.</returns>
        /// <exception cref="InvalidOperationException">
        /// No input file has been added.
        /// </exception>
        public XmlDocument GenerateXmlReport()
        {
            if (fileCount == 0)
            {
                throw new InvalidOperationException(
                          "Cannot generate XML report until input file has been added.");
            }

            XmlDocument     document = new XmlDocument();
            XmlElement      root     = document.CreateElement("Report");
            XmlDocumentType docType  = document.CreateDocumentType("Report", null, null, @"
  <!ELEMENT Report    (Result, Project+)>

  <!ELEMENT Project   (Name, Result, File+)>
  <!ELEMENT Name      (#PCDATA)>

  <!ELEMENT File      (Directory, FileName, Result)>
  <!ELEMENT Directory (#PCDATA)>
  <!ELEMENT FileName  (#PCDATA)>

  <!ELEMENT Result    (Total, Code, Comment, Blank)>
  <!ELEMENT Total     (#PCDATA)>
  <!ELEMENT Code      (#PCDATA)>
  <!ELEMENT Comment   (#PCDATA)>
  <!ELEMENT Blank     (#PCDATA)>
");

            document.AppendChild(docType);             // Add DTD description to the document
            document.AppendChild(root);

            // Add summary element
            XmlElement resultElement = document.CreateElement("Result");

            if (report != null)
            {
                report.Serialize(resultElement);
            }
            root.AppendChild(resultElement);

            foreach (Project project in projects.Values)
            {
                // Serialize each non-empty project
                if (project.FileCount > 0)
                {
                    XmlElement projectElement = document.CreateElement("Project");

                    project.Serialize(projectElement);
                    root.AppendChild(projectElement);
                }
            }

            return(document);
        }
コード例 #3
0
        /// <summary>
        /// Serializes counting informations.
        /// </summary>
        /// <param name="element">An <see cref="XmlElement"/> node
        /// used to write counting informations.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/> is null.
        /// </exception>
        internal void Serialize(XmlElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            XmlDocument document      = element.OwnerDocument;
            XmlElement  dirElement    = document.CreateElement("Directory");
            XmlElement  nameElement   = document.CreateElement("FileName");
            XmlElement  resultElement = document.CreateElement("Result");

            dirElement.InnerText  = Directory;
            nameElement.InnerText = Name;
            if (report != null)
            {
                report.Serialize(resultElement);
            }

            element.AppendChild(dirElement);
            element.AppendChild(nameElement);
            element.AppendChild(resultElement);
        }