public virtual void TestDeserialize()
        {
            object value  = GetValue();
            object rvalue = xstream.FromXml("<" + xmlName + ">" + value + "</" + xmlName + ">");

            AssertEquality(value, rvalue);
        }
예제 #2
0
파일: Ints.cs 프로젝트: xlgwr/TestDevices
        public static Device FromXML(string xml)
        {
            XStream xstream = new XStream();
            xstream.Alias("Device", typeof(Device));

            xstream.Alias("main", typeof(Main));
            xstream.Alias("mains", typeof(Main[]));

            xstream.Alias("CmdInfo", typeof(CmdInfo));
            xstream.Alias("CmdInfos", typeof(CmdInfo[]));
            try
            {
                if (xml != null)
                {
                    xml = xml.Replace(@"<\/", "</");
                    Device ddd = (Device)xstream.FromXml(xml);//"<Device><cmdInfos><CmdInfo><name>yearmonth</name> <address>002F</address> <csharpType>System.Int16</csharpType> <unitFactor>0</unitFactor></CmdInfo> <CmdInfo><name>dayhour</name> <address>002E</address> <csharpType>System.Int16</csharpType> <unitFactor>0</unitFactor></CmdInfo> <CmdInfo><name>minutesecond</name> <address>002D</address> <csharpType>System.Int16</csharpType> <unitFactor>0</unitFactor></CmdInfo> <CmdInfo><name>zljyggl</name> <address>006A</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>zssyggl</name> <address>0092</address> <csharpType>System.Int32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>a1</name> <address>00B4</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>a2</name> <address>00B6</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>a3</name> <address>00B8</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>v1</name> <address>00A4</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.1</unitFactor></CmdInfo> <CmdInfo><name>v2</name> <address>00A6</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.1</unitFactor></CmdInfo> <CmdInfo><name>v3</name> <address>00A8</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.1</unitFactor></CmdInfo> <CmdInfo><name>pf</name> <address>00C5</address> <csharpType>System.Int16</csharpType> <unitFactor>0.001</unitFactor></CmdInfo></cmdInfos></Device>");
                    if (ddd == null)
                    {
                        return new Device();
                    }
                    else
                    {
                        return ddd;
                    }
                }
                else
                {
                    return new Device();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void TestStreamSimpleArrayList()
        {
            ArrayList list = new ArrayList(5);

            list.Add(TestRandomizer.GetInt());
            list.Add(TestRandomizer.GetString());
            list.Add(TestRandomizer.GetDecimal());
            list.Add("last");

            XStream xs  = new XStream();
            string  xml = xs.ToXml(list);

            Assert.IsNotNull(xml);
            Assert.IsTrue(xml.Length > 0);

            IList rlist = xs.FromXml(xml) as IList;

            Assert.IsNotNull(rlist);
            Assert.AreEqual(list.Count, rlist.Count);

            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(list[i], rlist[i]);
            }
        }
예제 #4
0
            public void should_deserialize()
            {
                var xml    = "<TestArray35><people><TestPerson35><ID>12</ID><Name>Joe</Name></TestPerson35></people></TestArray35>";
                var map    = new XStream <TestArray35>();
                var actual = map.FromXml(xml);

                Assert.AreEqual(12, actual.people[0].ID);
            }
예제 #5
0
        internal string SerialiseAndDeserialise(object value, AssertEqualsDelegate equalsDelegate)
        {
            string actualSerialisedObject = xstream.ToXml(value);

            Console.WriteLine(actualSerialisedObject);
            equalsDelegate(value, xstream.FromXml(actualSerialisedObject));
            return(actualSerialisedObject);
        }
예제 #6
0
            public void act()
            {
                XStream xs = new XStream();

                xs.Alias("person", typeof(TestPerson));
                string xml = xs.ToXml(person);

                actual = xs.FromXml <TestPerson>(xml);
            }
예제 #7
0
            public void act()
            {
                XStream xs = new XStream();

                xs.Alias <TestPerson>("person");
                string xml = xs.ToXml(person);

                actual = xs.FromXml(xml) as TestPerson;
            }
예제 #8
0
        public void ShouldAllowAliasingOfAClass()
        {
            var xStream = new XStream();
            xStream.Alias<Software>("software");

            const string expectedXml = "<software><name>apache</name></software>";

            Assert.That(xStream.ToXml(new Software("apache")), Is.EqualTo(expectedXml));
            Assert.That(xStream.FromXml(expectedXml), Is.EqualTo(new Software("apache")));
        }
예제 #9
0
        /**
         * Initialize socket server connections through xml configuration file.
         */
        public static void initialize() {
            //http://code.google.com/p/xstream-dot-net/
            StreamReader reader = File.OpenText("controller.xml");
            string xml = reader.ReadToEnd();
            reader.Close();

            XStream xstream = new XStream();
            xstream.Alias<List<SocketConnection>>("connections");
            xstream.Alias<SocketConnection>("connection");
            connectionList = xstream.FromXml<List<SocketConnection>>(xml);
        }
        public void should_be_able_to_use_a_setter_property()
        {
            string xml = "<person><ID>2</ID></person>";

            XStream xs = new XStream();

            xs.Alias <TestPerson35>("person");
            var person = xs.FromXml <TestPerson35>(xml);

            Assert.AreEqual(2, person.ID);
        }
예제 #11
0
            public void should_deserialize_a_generic_list()
            {
                string  xml = "<TestPeople><People><TestPerson><ID>12</ID><Name>Joe</Name></TestPerson></People></TestPeople>";
                XStream xs  = new XStream();

                xs.Alias <TestPeople35>("TestPeople");
                xs.Alias <TestPerson35>("TestPerson");

                TestPeople35 value = xs.FromXml <TestPeople35>(xml);

                Assert.AreEqual(1, value.People.Count);
            }
예제 #12
0
파일: Plugin.cs 프로젝트: jozpys/MUTDOD
        public static Plugin Read(string fileName)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(fileName);
            }
            catch (Exception)
            {
                InvalidPluginException e = new InvalidPluginException("Error while parsing plugin file: " + fileName);
                throw e;
            }
            XmlNode pluginNode = doc.GetElementsByTagName("Plugin").Item(0);

            if (pluginNode == null)
            {
                InvalidPluginException e = new InvalidPluginException("There is no plugin definition in file: " + fileName);
                throw e;
            }

            XStream xs = new XStream();

            xs.Alias("Plugin", typeof(PluginConfig));
            PluginConfig pluginXML = null;

            try
            {
                pluginXML = xs.FromXml(pluginNode.OuterXml) as PluginConfig;
            }
            catch (Exception)
            {
                InvalidPluginException e = new InvalidPluginException("Wrong plugin definition in file: " + fileName);
                throw e;
            }

            try
            {
                pluginXML.Valid();
            }
            catch (InvalidPluginException ex)
            {
                InvalidPluginException e = new InvalidPluginException(ex.Message + " in file: " + fileName, ex);
                e.Plugin = pluginXML;
                throw e;
            }

            Plugin plugin = new Plugin(pluginXML);

            plugin.Xml = pluginNode.OuterXml;
            return(plugin);
        }
예제 #13
0
        /**
         * Initialize socket server connections through xml configuration file.
         */
        public static void initialize()
        {
            //http://code.google.com/p/xstream-dot-net/
            StreamReader reader = File.OpenText("controller.xml");
            string       xml    = reader.ReadToEnd();

            reader.Close();

            XStream xstream = new XStream();

            xstream.Alias <List <SocketConnection> >("connections");
            xstream.Alias <SocketConnection>("connection");
            connectionList = xstream.FromXml <List <SocketConnection> >(xml);
        }
예제 #14
0
        public static Device FromXML(string xml)
        {
            XStream xstream = new XStream();

            xstream.Alias("Device", typeof(Device));

            xstream.Alias("main", typeof(Main));
            xstream.Alias("mains", typeof(Main[]));

            xstream.Alias("CmdInfo", typeof(CmdInfo));
            xstream.Alias("CmdInfos", typeof(CmdInfo[]));
            try
            {
                if (xml != null)
                {
                    xml = xml.Replace(@"<\/", "</");
                    Device ddd = (Device)xstream.FromXml(xml);//"<Device><cmdInfos><CmdInfo><name>yearmonth</name> <address>002F</address> <csharpType>System.Int16</csharpType> <unitFactor>0</unitFactor></CmdInfo> <CmdInfo><name>dayhour</name> <address>002E</address> <csharpType>System.Int16</csharpType> <unitFactor>0</unitFactor></CmdInfo> <CmdInfo><name>minutesecond</name> <address>002D</address> <csharpType>System.Int16</csharpType> <unitFactor>0</unitFactor></CmdInfo> <CmdInfo><name>zljyggl</name> <address>006A</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>zssyggl</name> <address>0092</address> <csharpType>System.Int32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>a1</name> <address>00B4</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>a2</name> <address>00B6</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>a3</name> <address>00B8</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.01</unitFactor></CmdInfo> <CmdInfo><name>v1</name> <address>00A4</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.1</unitFactor></CmdInfo> <CmdInfo><name>v2</name> <address>00A6</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.1</unitFactor></CmdInfo> <CmdInfo><name>v3</name> <address>00A8</address> <csharpType>System.UInt32</csharpType> <unitFactor>0.1</unitFactor></CmdInfo> <CmdInfo><name>pf</name> <address>00C5</address> <csharpType>System.Int16</csharpType> <unitFactor>0.001</unitFactor></CmdInfo></cmdInfos></Device>");
                    if (ddd == null)
                    {
                        return(new Device());
                    }
                    else
                    {
                        return(ddd);
                    }
                }
                else
                {
                    return(new Device());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }