コード例 #1
0
        private Stats GenerateAndParse(Stats original)
        {
            StringWriter sWriter = new StringWriter();
            XmlWriter xmlWriter = new XmlTextWriter(sWriter);
            original.Save(xmlWriter);
            xmlWriter.Close();

            return Parse(sWriter.ToString());
        }
コード例 #2
0
        public void TestGenerate()
        {
            Stats stats = new Stats();
            stats.Impressions.Total = 500;
            stats.Impressions["hello"] = 3;
            stats.PageViews.Total = 9;

            Stats stats2 = GenerateAndParse(stats);
            Assert.AreEqual(500, stats2.Impressions.Total);
            Assert.AreEqual(0, stats2.Clicks.Total);
            Assert.AreEqual(9, stats2.PageViews.Total);
            Assert.AreEqual(3, stats2.Impressions["hello"]);
        }
コード例 #3
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Parses an XML representation and creates an object</summary>
        ///////////////////////////////////////////////////////////////////////
        public static Stats Parse(XmlNode xml)
        {
            Stats retval = new Stats();
            for (XmlNode child = xml.FirstChild; child != null; child = child.NextSibling)
            {
                if (GBaseNameTable.NSGBaseMeta.Equals(child.NamespaceURI))
                {
                    switch (child.LocalName)
                    {
                        case "impressions":
                            retval.Impressions.Parse(child);
                            break;

                        case "clicks":
                            retval.Clicks.Parse(child);
                            break;

                        case "page_views":
                            retval.PageViews.Parse(child);
                            break;
                    }
                }
            }
            return retval;
        }