public ConfigurationSaveHelper(Configuration config)
 {
     //create save helper from config
     foreach (Entities.Tab tab in config.Tabs)
     {
         foreach (Entities.Group group in tab.Groups)
         {
             foreach (Entities.Setting setting in group.Settings)
             {
                 //add setting
                 settings.Add(new Entities.SettingHelper(setting.Name, setting.Identifier, group.Identifier, setting.Value, setting.Type));
             }
         }
     }
 }
Esempio n. 2
0
        private void OpenConfigurationToFile()
        {
            config = new Configuration();
            try
            {
                if (ConfigurationFilePath.Exists)
                {
                    //deserialize
                    //Open the file written above and read values from it.
                    Stream stream = System.IO.File.Open(ConfigurationFilePath.FullName, FileMode.Open);
                    BinaryFormatter formatter = new BinaryFormatter();

                    ConfigurationSaveHelper configSaveHelper = (ConfigurationSaveHelper)formatter.Deserialize(stream);
                    stream.Close();
                    config.LoadConfigurationHelper(configSaveHelper);
                    writeLine("Config succesfully loaded from file.");
                }
                else if (!Directory.Exists(ConfigurationFilePath.Directory.FullName))
                {
                    Directory.CreateDirectory(ConfigurationFilePath.Directory.FullName);
                }
            }
            catch (SerializationException e)
            {
                writeLine("Config could not be loaded default has been loaded. Message: " + e.Message);
                config = new Configuration();
            }
            catch (Exception e)
            {
                writeLine("Error loading config: " + e.Message);
                ExceptionHandler.TriggerException("Error loading config: " + e.Message, ExceptionLevel.Error, e);
                throw e;
            }
            finally
            {
                SaveConfigurationToFile();
            }
        }
Esempio n. 3
0
 private void MenuItemOptionsRestoreToDefault_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to restore the settings to default?", "Are you sure?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
     {
         config = new Configuration();
         RestoreValuesInUI();
     }
 }