示例#1
0
        public void XmlSaveAndRestore()
        {
            var random = new Random(0);
            var saveds = new DemoPayload[3];

            for (var i = 0; i < saveds.Length; i++)
            {
                saveds[i] = new DemoPayload {
                    Text = i.ToString(), Number = random.Next(100, 1000)
                };
            }

            var builder = new StringBuilder();

            for (var i = 0; i < saveds.Length; i++)
            {
                var xml = XmlFragmentHelper.EncodeXmlFragment(saveds[i]);
                builder.AppendLine(xml);
            }

            var fileContent = builder.ToString();
            var restoreds   = XmlFragmentHelper.DecodeXmlFragments <DemoPayload>(fileContent);

            Assert.IsNotNull(restoreds);
            Assert.AreEqual(saveds.Length, restoreds.Length);
            for (var i = 0; i < saveds.Length; i++)
            {
                Assert.AreEqual(saveds[i].Text, restoreds[i].Text);
                Assert.AreEqual(saveds[i].Number, restoreds[i].Number);
            }
        }
示例#2
0
        public void SerializeXmlElementViaHelper()
        {
            var ob = new DemoPayload {
                Text = "Some Text", Number = 42
            };

            var xml = XmlFragmentHelper.EncodeXmlFragment(ob);

            Assert.AreEqual("<DemoPayload Text=\"Some Text\" Number=\"42\" />", xml);
        }
示例#3
0
        static void Main(string[] args)
        {
            var stream = new WebClient().OpenRead("http://www.gutenberg.org/cache/epub/2600/pg2600.txt");

            //var stream = File.OpenRead(@"C:\Users\petea\Desktop\pg2600.txt");

            using (var reader = new StreamReader(stream))
            {
                ProcessText(reader);
            }

            var builder = new StringBuilder();

            foreach (var record in records)
            {
                var fragment = XmlFragmentHelper.EncodeXmlFragment(record);
                builder.AppendLine(fragment);
            }
            File.WriteAllText("WarAndPeace.xml", builder.ToString());
        }