Beispiel #1
0
        /// <summary>
        /// Format the LogReport into a change log
        /// which will be written to textWriter
        /// </summary>
        private void FormatReport(XmlTextWriter textWriter, LogReport logReport)
        {
            LogRevision logRevision;

            // This is where we accumulate information on all the entries from the log command
            SortedList entries = new SortedList();
            LogEntry   entry;
            string     prevRevision;

            // now collect together revisions that were checked-in together
            foreach (LogFile logFile in logReport)
            {
//              foreach (LogRevision logRevision in logFile)
                // traverse revisions in reverse order so we look at oldest first
                // which simplifies the remembering the previous revision
                prevRevision = "";
                for (int idx = logFile.Count - 1; idx >= 0; idx--)
                {
                    logRevision = logFile[idx];
                    entry       = new LogEntry(logRevision.Timestamp, logRevision.Author, logRevision.Comment);
                    // determine if this entry already exists
                    if (entries.ContainsKey(entry.Key))
                    {
                        // need to update an existing entry
                        entry = (LogEntry)entries[entry.Key];
                    }
                    else
                    {
                        // add new entry
                        entries.Add(entry.Key, entry);
                    }
                    // finally add details about the file/revision
                    entry.AddFileRevision(logFile.WorkingFnm, logRevision.Revision, prevRevision);
                    prevRevision = logRevision.Revision;
                }
            }

            // now finally produce the XML report
//            try {
            textWriter.Formatting = Formatting.Indented;
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("changelog");

            // add the entries ...
            foreach (DictionaryEntry de in entries)
            {
                LogEntry logEntry = (LogEntry)de.Value;
                logEntry.ExportToXml(textWriter, nameMap);
            }

            // finish off
            textWriter.WriteEndElement();        // changelog
            textWriter.WriteEndDocument();
            textWriter.Close();
//            } catch (Exception e) {
//                System.Console.WriteLine("XML write error: {0}", e.Message);
//                throw e;
//            }
        }
Beispiel #2
0
        public void Serialise()
        {
            DateTime timestamp = DateTime.Now;
            string   author    = "gne";
            string   comment   = "checkin comment";

            StringDictionary nameMap = new StringDictionary();

            nameMap.Add("gne", "Gerald Evans");

            LogEntry logEntry = new LogEntry(timestamp, author, comment);

            logEntry.AddFileRevision("testfile.cs", "1.4", "1.3");

            MemoryStream  stream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(stream, new System.Text.UTF8Encoding());

            // Serialise the FileRevision to a memory stream as XML
            writer.WriteStartDocument();
            writer.WriteStartElement("test");
            logEntry.ExportToXml(writer, nameMap);
            writer.WriteEndElement();    // test
            writer.WriteEndDocument();
            writer.Flush();
//            writer.Close();

            // rewind and check what was written
            stream.Position = 0;

            XmlTextReader reader = new XmlTextReader(stream);

//            while (reader.Read())
//            {
//            System.Console.WriteLine("{0}-{1}-{2}", reader.NodeType, reader.Value, reader.Name);
//            }

            // the xml declaration
            reader.Read();
            Assert.AreEqual(XmlNodeType.XmlDeclaration, reader.NodeType);

            // the root element
            reader.Read();
            Assert.AreEqual(XmlNodeType.Element, reader.NodeType);

            CheckStart(reader, timestamp, "Gerald Evans");
            FileRevisionTest.Check(reader, "testfile.cs", "1.4", "1.3");
            CheckEnd(reader, "checkin comment");


            // the end of the root element
            reader.Read();
            Assert.AreEqual(XmlNodeType.EndElement, reader.NodeType);
            Assert.AreEqual("test", reader.Name);
        }