Example #1
0
        public static bool IsPresetChanged(Preset preset)
        {
            if (preset == null)
            {
                throw new ArgumentNullException("preset");
            }

            if (IsProtectedPreset(preset.Name))
            {
                return(false);
            }

            var fileData    = PresetDataManager.ReadPresetDataFromFile();
            var currentData = PresetDataManager.data;

            if (!currentData.Presets.Contains(preset))
            {
                throw new InvalidOperationException(
                          "The following preset does not exsists in the current preset data: " + preset);
            }

            var original = fileData.Presets.FirstOrDefault(x => x.Name == preset.Name);

            if (original == null)
            {
                // We found a new preset
                return(true);
            }
            else
            {
                var origialSerialized = original.ToXml();
                var presetSerialized  = preset.ToXml();
                return(origialSerialized != presetSerialized);
            }
        }
        public static PresetData Deserialize(string xmlFileLocation)
        {
            if (!File.Exists(xmlFileLocation))
            {
                throw new FileNotFoundException(xmlFileLocation);
            }

            var serializer = new XmlSerializer(typeof(PresetData));

            serializer.UnknownNode += (ss, ee) => { throw new InvalidOperationException("Deserialize found unknown node"); };
            using (var fileStream = new FileStream(xmlFileLocation, FileMode.Open))
            {
                var        reader = new XmlTextReader(fileStream);
                PresetData data   = (PresetData)serializer.Deserialize(reader);

                // Removing protected presets from file data
                var array = new Preset[data.Presets.Count];
                data.Presets.CopyTo(array, 0);

                foreach (var item in array)
                {
                    if (PresetDataManager.IsProtectedPreset(item.Name))
                    {
                        data.Presets.Remove(item);
                    }
                }

                InsertImuttablePresets(data);
                return(data);
            }
        }
        public void Serialize(string xmlFileLocation)
        {
            var filteredPresets = new ObservableCollection <Preset>();

            foreach (var preset in this.Presets)
            {
                if (PresetDataManager.IsProtectedPreset(preset.Name))
                {
                    continue;
                }

                filteredPresets.Add(preset);
            }

            var filteredData = new PresetData();

            filteredData.Presets = filteredPresets;

            using (var writer = new StreamWriter(path: xmlFileLocation, append: false, encoding: Encoding.Unicode))
            {
                var serializer = new XmlSerializer(this.GetType());
                serializer.Serialize(writer, filteredData);
            }
        }
Example #4
0
 static PresetDataManager()
 {
     PresetDataManager.data = PresetDataManager.ReadPresetDataFromFile();
 }