Ejemplo n.º 1
0
            public void StoreObject(object key, object obj)
            {
                object  oid  = m_xmlsc.GetOidForObject(obj);
                XmlNode node = m_xmlsc.CreateEmptyNode(key.ToString(), m_type, oid);

                m_xmlsc.CurrentNode.AppendChild(node);
                m_xmlsc.PushNode(node);
                DictionaryEntry de = (DictionaryEntry)obj;

                m_xmlsc.StoreObject("key", de.Key);
                m_xmlsc.StoreObject("Value", de.Value);
                m_xmlsc.PopNode();
            }
Ejemplo n.º 2
0
            public void StoreObject(object key, object obj)
            {
                object  oid  = m_xmlsc.GetOidForObject(obj);
                XmlNode node = m_xmlsc.CreateEmptyNode(key.ToString(), obj.GetType(), oid);

                m_xmlsc.CurrentNode.AppendChild(node);
                m_xmlsc.PushNode(node);
                Delegate del = (Delegate)obj;

                m_xmlsc.StoreObject("Target", del.Target);
                m_xmlsc.StoreObject("Method", del.Method.Name);
                m_xmlsc.PopNode();
            }
Ejemplo n.º 3
0
 public void SerializeTo(XmlSerializationContext xmlsc)
 {
     xmlsc.StoreObject("Child1", m_child1);
     xmlsc.StoreObject("Child2", m_child2);
     xmlsc.StoreObject("Name", m_name);
     xmlsc.StoreObject("Age", m_age);
     xmlsc.StoreObject("Married", m_married);
     xmlsc.StoreObject("Birthday", m_birthday);
     xmlsc.StoreObject("TimeSpan", m_ts);
     xmlsc.StoreObject("Hashtable", m_ht);
     xmlsc.StoreObject("ArrayList", m_al);
 }
Ejemplo n.º 4
0
        [TestMethod] public void TestPersistenceBasics()
        {
            XmlSerializationContext xsc = new XmlSerializationContext();

            MyTestObject mto2 = new MyTestObject("Gary", 3.1, null);

            MyTestObject mto = new MyTestObject("Bill", 6.2,
                                                new MyTestObject("Bob", 12.4,
                                                                 new MyTestObject("Steve", 24.8,
                                                                                  new MyTestObject("Dave", 48.1,
                                                                                                   new MyTestObject("Sally", 96.2,
                                                                                                                    new MyTestObject("Rufus", 186.9,
                                                                                                                                     null))))));

            Debug.WriteLine("Setting " + mto.Child1.Child1.Name + "'s child2 to " + mto2.Name);
            mto.Child1.Child1.Child2 = mto2;
            Debug.WriteLine("Setting " + mto.Child1.Name + "'s child2 to " + mto2.Name);
            mto.Child1.Child2 = mto2;

            xsc.StoreObject("MTO", mto);

            xsc.Save(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "foo.xml");

            xsc.Reset();

            xsc.Load(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "foo.xml");

            MyTestObject mto3 = (MyTestObject)xsc.LoadObject("MTO");

            xsc = new XmlSerializationContext();
            xsc.StoreObject("MTO", mto3);
            xsc.Save(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "foo2.xml");
        }
Ejemplo n.º 5
0
            public void StoreObject(object key, object obj)   // TODO: Array of primitives - more compact format.
            {
                object  oid  = m_xmlsc.GetOidForObject(obj);
                XmlNode node = m_xmlsc.CreateEmptyNode(key.ToString(), m_type, oid);

                m_xmlsc.CurrentNode.AppendChild(node);
                m_xmlsc.PushNode(node);

                Array array = (Array)obj;
                int   rank  = array.Rank;

                int[] lengths = new int[rank];
                for (int i = 0; i < rank; i++)
                {
                    lengths[i] = array.GetLength(i);
                }
                m_xmlsc.StoreObject("ElementType", array.GetType());
                if (rank > 1)
                {
                    m_xmlsc.StoreObject("Lengths", lengths);
                }
                else
                {
                    m_xmlsc.StoreObject("Length", lengths[0]);
                }

                int[] indices = new int[rank];
                Array.Clear(indices, 0, rank);

                int ndx = 0;

                while (ndx < rank)
                {
                    ndx = 0;
                    string ndxStr = GetNdxString(indices);
                    m_xmlsc.StoreObject(ndxStr, array.GetValue(indices));
                    while ((ndx < indices.Length) && (++indices[ndx]) == lengths[ndx])
                    {
                        indices[ndx] = 0;
                        ndx++;
                    }
                }

                m_xmlsc.PopNode();
            }
Ejemplo n.º 6
0
            public void StoreObject(object key, object obj)
            {
                object  oid  = m_xmlsc.GetOidForObject(obj);
                XmlNode node = m_xmlsc.CreateEmptyNode(key.ToString(), m_type, oid);

                m_xmlsc.CurrentNode.AppendChild(node);
                m_xmlsc.PushNode(node);
                ArrayList al = (ArrayList)obj;

                m_xmlsc.StoreObject("NumEntries", al.Count);
                int i = 0;

                foreach (object entry in al)
                {
                    m_xmlsc.StoreObject("Val_" + i, entry);
                    i++;
                }
                m_xmlsc.PopNode();
            }
Ejemplo n.º 7
0
            public void StoreObject(object key, object obj)
            {
                object  oid  = m_xmlsc.GetOidForObject(obj);
                XmlNode node = m_xmlsc.CreateEmptyNode(key.ToString(), obj.GetType(), oid);

                m_xmlsc.CurrentNode.AppendChild(node);
                m_xmlsc.PushNode(node);
                m_xmlsc.StoreObject(key, obj.ToString());
                m_xmlsc.PopNode();
            }
Ejemplo n.º 8
0
        [TestMethod] public void TestPersistenceChemistryStorage()
        {
            BasicReactionSupporter brs = new BasicReactionSupporter();

            Initialize(brs);
            XmlSerializationContext xsc = new XmlSerializationContext();

            xsc.StoreObject("Chemistry", brs);

            xsc.Save(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "chemistry.xml");
        }
Ejemplo n.º 9
0
            public void StoreObject(object key, object obj)
            {
                object  oid  = m_xmlsc.GetOidForObject(obj);
                XmlNode node = m_xmlsc.CreateEmptyNode(key.ToString(), m_type, oid);

                m_xmlsc.CurrentNode.AppendChild(node);
                m_xmlsc.PushNode(node);
                Hashtable ht = (Hashtable)obj;

                m_xmlsc.StoreObject("NumEntries", ht.Count);
                int i = 0;

                foreach (DictionaryEntry de in ht)
                {
                    m_xmlsc.StoreObject("Key_" + i, de.Key);
                    m_xmlsc.StoreObject("Val_" + i, de.Value);
                    i++;
                }
                m_xmlsc.PopNode();
            }
Ejemplo n.º 10
0
        [TestMethod] public void TestPersistenceWaterStorage()
        {
            MaterialType mt = new MaterialType(null, "Water", Guid.NewGuid(), 1.234, 4.05, MaterialState.Liquid, 18.0, 1034);

            BasicReactionSupporter brs = new BasicReactionSupporter();

            brs.MyMaterialCatalog.Add(mt);

            IMaterial water = mt.CreateMass(1500, 35);

            XmlSerializationContext xsc = new XmlSerializationContext();

            xsc.StoreObject("Water", water);

            xsc.Save(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "water.xml");

            xsc.Reset();

            xsc.StoreObject("MC", brs.MyMaterialCatalog);

            xsc.Save(Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + "mc.xml");
        }