示例#1
0
        public XDocument Convert(string path)
        {
            var document = new XDocument();

            using (var reader = new Reader(path))
            {
                var boundaries = new Stack<Boundary>();
                Entry entry;

                boundaries.Push(_boundary);
                var element = document.Add<XElement>(new XElement(_boundary.Name));

                do
                {
                    entry = reader.Read();

                    if (entry == null || entry.IsEmpty) continue;

                    var entryData = entry.Data;

                    var boundary = boundaries.Peek();

                    if (!boundary.IsEnd(entry.Data) &&
                        boundary.Boundries.Count > 0 &&
                        boundary.Boundries.Exists(b => b.IsStart(entryData)))
                    {
                        boundary = boundary.Boundries.First(b => b.IsStart(entryData));
                        boundaries.Push(boundary);
                        element = element.Add<XElement>(new XElement(boundary.Name));
                        EnsureStartTimestamp(entry, element);
                        if (BeginBoundry != null) BeginBoundry(this, new EventArgs<Boundary>(boundary));
                    }

                    if (element == null) continue;

                    if (boundary.Boundries.Count == 0)
                        element.Add(new XCData(boundary.Format(entry.Data)));

                    if (!boundary.IsEnd(entry.Data)) continue;

                    EnsureEndTimestamp(entry, element);
                    EnsureDuration(element);
                    element = element.Parent;
                    boundaries.Pop();
                } while (entry != null);
            }

            return document;
        }
示例#2
0
 public XDocument Convert(string path)
 {
     XDocument xDocument = new XDocument();
     using (Reader reader = new Reader(path))
     {
         Stack<Boundary> stack = new Stack<Boundary>();
         stack.Push(_boundary);
         XElement xElement = xDocument.Add<XElement>(new XElement(_boundary.Name));
         Entry entry;
         do
         {
             entry = reader.Read();
             if (entry != null && !entry.IsEmpty)
             {
                 string entryData = entry.Data;
                 Boundary boundary = stack.Peek();
                 if (!boundary.IsEnd(entry.Data) && boundary.Boundries.Count > 0 && boundary.Boundries.Exists((Boundary b) => b.IsStart(entryData)))
                 {
                     boundary = boundary.Boundries.First((Boundary b) => b.IsStart(entryData));
                     stack.Push(boundary);
                     xElement = xElement.Add<XElement>(new XElement(boundary.Name));
                     EnsureStartTimestamp(entry, xElement);
                     if (BeginBoundary != null)
                     {
                         BeginBoundary(this, new EventArgs<Boundary>(boundary));
                     }
                 }
                 if (xElement != null)
                 {
                     if (boundary.Boundries.Count == 0)
                     {
                         xElement.Add(new XCData(boundary.Format(entry.Data)));
                     }
                     if (boundary.IsEnd(entry.Data))
                     {
                         EnsureEndTimestamp(entry, xElement);
                         EnsureDuration(xElement);
                         xElement = xElement.Parent;
                         stack.Pop();
                     }
                 }
             }
         }
         while (entry != null);
     }
     return xDocument;
 }