Esempio n. 1
0
 private void WriteDefaultSettings()
 {
     try
     {
         if (File.Exists("settings")) File.Delete("settings");
         AdministrationSettings admin = new AdministrationSettings();    // create object with default settings
         Stream stream = File.Open("settings", FileMode.Create);
         BinaryFormatter bformatter = new BinaryFormatter();
         bformatter.Serialize(stream, admin);
         stream.Close();
     }
     catch (Exception ex)
     {
         throw new Exception("Konfigurationsdatei konnte nicht erstellt werden: " + ex.Message);
     }
 }
Esempio n. 2
0
        public Settings(bool includeCashpointSettings)
        {
            #region Administration
            Stream stream = null;

            if (!File.Exists("settings"))
                WriteDefaultSettings();

            try
            {
                stream = File.Open("settings", FileMode.Open);
                BinaryFormatter bformatter = new BinaryFormatter();
                Administration = (AdministrationSettings)bformatter.Deserialize(stream);
                stream.Close();
            }
            catch (Exception)
            {
                if (stream != null) stream.Close();
                WriteDefaultSettings();
                Administration = new AdministrationSettings();
                throw new Exception("Die Benutzereinstellungen konnten nicht geladen werden. Die Einstellungen werden nun zurückgesetzt.");
            }
            Administration.PropertyChanged += (sender, args) => { this.ApplyNeeded = true; };
            #endregion

            if (includeCashpointSettings)
                LoadCashpointSettings();


            this.ApplyNeeded = false;
        }