示例#1
0
        /// <summary>
        ///     Чтение настроек
        /// </summary>
        public SettingsFields ReadSettings(SettingsFields settFields)
        {
            var fd = new OpenFileDialog();

            fd.Filter = "Файлы настроек|*.xml";
            var result = fd.ShowDialog();

            if (result == true)
            {
                var ser = new XmlSerializer(typeof(SettingsFields));

                using (var reader = new FileStream(fd.FileName, FileMode.Open))
                {
                    try
                    {
                        settFields = ser.Deserialize(reader) as SettingsFields;
                    }
                    catch
                    {
                        throw new IOException {
                                  Source = fd.FileName
                        };
                    }
                }
            }

            return(settFields);
        }
示例#2
0
        /// <summary>
        ///     Запись настроек
        /// </summary>
        public SettingsFields WriteSettings(SettingsFields settFields, string path = null)
        {
            var ser = new XmlSerializer(typeof(SettingsFields));

            using (var writer = File.Create(path ?? settingsLocation))
            {
                ser.Serialize(writer, settFields);
            }

            return(settFields);
        }
示例#3
0
        /// <summary>
        ///  Сохранение настроек
        ///  (по нажатию кнопки)
        /// </summary>
        private void SaveSettings()
        {
            GetSettingsFromUI();

            var fd = new SaveFileDialog();

            fd.FileName   = "settings";
            fd.DefaultExt = ".xml";

            var result = fd.ShowDialog();

            if (result == true)
            {
                var newSettings = settFields.Clone();
                settFields = settingsSaver.WriteSettings(newSettings, fd.FileName);
            }
        }
示例#4
0
        /// <summary>
        ///     Конструктор
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            settingsSaver           = new SettingsSaver();
            Stop.IsEnabled          = false;
            SuperInter.Visibility   = Visibility.Hidden;
            SuperOptions.Visibility = Visibility.Hidden;
            myCanvas.Background     = new SolidColorBrush(Color.FromArgb(0, 0, 150, 0));
            settFields = new SettingsFields();

            Closing += (sender, e) => SilentSaveSettings();

            var settFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.xml");

            if (!File.Exists(settFilePath))
            {
                SilentSaveSettings();
            }
            else
            {
                Task.Run(async() =>
                {
                    await Task.Delay(500);
                    Application.Current?.Dispatcher?.BeginInvoke(new Action(() =>
                    {
                        try
                        {
                            SilentReadSettings();
                        }
                        catch (IOException exception)
                        {
                            MessageBox.Show($"Не удалось загрузить сохраненные настройки приложения {Environment.NewLine}Файл: {Path.GetFileName(exception.Source)}");
                        }
                    }));
                });
            }
        }
示例#5
0
 /// <summary>
 /// Восстановление настроек
 /// </summary>
 private void SilentReadSettings()
 {
     settFields = settingsSaver.SilentReadSettings();
     SetSettingsToUI();
 }
示例#6
0
 /// <summary>
 /// Чтение настроек
 /// </summary>
 private void ReadSettings()
 {
     settFields = settingsSaver.ReadSettings(settFields);
     SetSettingsToUI();
 }