예제 #1
0
        public static Settings Load()
        {
            //serializer
            JsonSerializer serializer = new JsonSerializer();
            //Allow nulls references to be saved
            serializer.NullValueHandling = NullValueHandling.Ignore;
            //This allows all the DataTags and Enity references to remain their references after deserialization
            serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
            //This allow us to serialize and deserialize and array of abstract objects back into their original base types
            serializer.TypeNameHandling = TypeNameHandling.Auto;
            //This makes it look nice
            serializer.Formatting = Formatting.Indented;
            //Circular reference handling
            serializer.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;

            string filePath = GetSettingsFile();
            Settings settings = null;
            if (File.Exists(filePath))
            {
                using (StreamReader sr = new StreamReader(filePath))
                {
                    using (JsonReader reader = new JsonTextReader(sr))
                    {
                        settings = serializer.Deserialize(reader, typeof(Settings)) as Settings;
                    }
                }
            }
            else
            {
                settings = new Settings();
                settings.Save();
            }
            return settings;
        }
 public SettingsWindowViewModel()
 {
     this.settings = Settings.Load();
     AuxiliaryApplications = new ObservableCollection<AuxiliaryApplicationViewModel>();
     settings.AuxiliaryApplications.ForEach(x => AuxiliaryApplications.Add(new AuxiliaryApplicationViewModel(x)));
     if (AuxiliaryApplications.Count > 0)
     {
         AuxiliaryApplications[0].IsExpanded = true;
     }
 }