Beispiel #1
0
        public void SaveSettings(PMSettingsModel settings)
        {
            if (settings == null)
            {
                return;
            }

            using (rwlock.Write())
            {
                settingsModel = settings.Clone();

                try
                {
                    var serializer = new DataContractSerializer(typeof(PMSettingsModel));

                    using (var fs = File.Open(settingsFileName, FileMode.Create))
                    {
                        using (var writer = new XmlTextWriter(fs, Encoding.UTF8))
                        {
                            writer.Formatting = Formatting.Indented;
                            serializer.WriteObject(writer, settingsModel);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogProvider.Log.Error(this, e);
                }
            }
        }
Beispiel #2
0
        private bool TryLoad()
        {
            try
            {
                using (rwlock.Write())
                {
                    if (File.Exists(settingsFileName))
                    {
                        using (var fs = File.Open(settingsFileName, FileMode.Open))
                        {
                            var serializer = new DataContractSerializer(typeof(PMSettingsModel));
                            settingsModel = serializer.ReadObject(fs) as PMSettingsModel;
                            return(settingsModel != null);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogProvider.Log.Error(CustomModulesNames.PMCatcher, "Could not load settings.", ex);
            }

            return(false);
        }