Пример #1
0
    /// <summary>
    /// this method retrives the persisted data from the xml file in the start up directory
    /// </summary>
    public static void ReadData(){
      try{
        if (File.Exists(_path)) {
          XmlSerializer serializer      = new XmlSerializer(typeof(Data));
          FileStream fs                 = new FileStream(_path, FileMode.Open);
          Data = (Data)serializer.Deserialize(fs);
          fs.Close();

        } else {
          DialogResult result           = MessageBox.Show("Error reading data from XML file, Do you want to restore a previous version?", "ERROR",
                                                          MessageBoxButtons.YesNo, MessageBoxIcon.Error);
          if (result == DialogResult.Yes) {
            RestoreData();
            ReadData();

          } else {
            PersistData();
          }
        }

      } catch (Exception ex){
        Utilities.ShowErrorMessage("Error reading data from XML file.", ex);
      }
    }
Пример #2
0
 /// <summary>
 /// Constructor for Persistince.Persist class
 /// </summary>
 /// <param name="Path"></param>
 static Persist(){
   _path         = (Application.StartupPath + @"\Persistince.Persist.xml");
   Data          = new Data();
   ReadData();
 }