Example #1
0
        public void SaveData()
        {
            var newdata = new MyData();
            newdata.CopyFromTM();
            if (MyData.Equals(newdata)) return;
            MyData = newdata;

            var xs = Utils.CreateDefaultXmlSerializer(typeof(MyData));
            //XmlSerializer xs = new XmlSerializer(typeof(MyData));
            TextWriter wr = null;
            try
            {
                wr = new StreamWriter(DataFileName);
                xs.Serialize(wr, MyData);
            }
            catch (Exception e)
            {
                LogMsg(e.Message);
            }
            finally
            {
                if (wr != null) wr.Close();
            }
        }
Example #2
0
 public void LoadData()
 {
     MyData = new MyData();
     if (!File.Exists(DataFileName)) return;
     XmlSerializer xs = null;
     FileStream fs = null;
     try
     {
         xs = new XmlSerializer(typeof(MyData));
         fs = new FileStream(DataFileName, FileMode.Open);
         Deserializing = true;
         MyData = (MyData)xs.Deserialize(fs);
         MyData.CopyToTM();
         CheckAfterLoad();
     }
     catch (Exception e)
     {
         LogMsg(e.Message);
         MyData = new MyData();
     }
     finally
     {
         if (fs != null) fs.Close();
         Deserializing = false;
     }
 }