Ejemplo n.º 1
0
        public void ShouldStreamTwoObjects()
        {
            const string xml = @"<root><item id=""1""/><item id=""2""/></root>";

            using (TextReader source = new StringReader(xml))
                using (XmlStream stream = new XmlStream(source))
                {
                    Assert.That(stream.Open("item").Count(), Is.EqualTo(2));
                }
        }
Ejemplo n.º 2
0
        public void ShouldStreamAllProperties()
        {
            const string xml = @"<root><item id=""1""/><item id=""2""/></root>";

            using (TextReader source = new StringReader(xml))
                using (XmlStream stream = new XmlStream(source))
                {
                    foreach (dynamic element in stream.Open("item"))
                    {
                        Assert.That(element.id.ToString(), Is.EqualTo("1").Or.EqualTo("2"));
                    }
                }
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            Stopwatch watch     = new Stopwatch();
            Reflector reflector = new Reflector();

            Collectible       collectible = new Collectible(16 * 1024 * 1024);
            Serializer <Page> serializer  = reflector.GetSerializer <Page>();

            using (TextReader reader = new StreamReader(@"D:\plwiki-20170720-stub-meta-history1.xml"))
                using (XmlStream stream = new XmlStream(reader))
                {
                    watch.Start();

                    foreach (dynamic row in stream.Open("page"))
                    {
                        collectible.Enqueue(serializer, GetPage(row));

                        if (collectible.Count % 1000 == 0)
                        {
                            GC.Collect();
                            Console.WriteLine($"{collectible.Count} {collectible.UsedSize} {collectible.TotalSize} {watch.Elapsed.TotalSeconds:F2}");
                        }
                    }
                }

            Serializer <Revision> byRevision = reflector.GetSerializer <Revision>();

            collectible = Select.Table(collectible, Select.Many(serializer, byRevision, x => x.Revisions));

            GC.Collect();
            Console.WriteLine($"{collectible.Count} {collectible.UsedSize} {collectible.TotalSize} {watch.Elapsed.TotalSeconds:F2}");

            collectible = Sort.Table(collectible, Sort.By(byRevision, x => x.Timestamp).Inverse());

            GC.Collect();
            Console.WriteLine($"{collectible.Count} {collectible.UsedSize} {collectible.TotalSize} {watch.Elapsed.TotalSeconds:F2}");

            for (int i = 0; i < Math.Min(10, collectible.Count); i++)
            {
                Revision revision = collectible.At(byRevision, i).AsDynamic();

                Console.WriteLine($"{i} {revision.Id} {revision.Comment?.Length} {revision.Comment}");
            }

            Console.ReadLine();
        }