using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; using BusinessLib.DataModel; using System.Xml; using Microsoft.WindowsAPICodePack.Shell; namespace BusinessLib.DataAccess { public class WinLibrarySetStorage { private static List _libraries = new List(); public static List Libraries { get { return _libraries; } } public static void SaveLibraries(string filePath) { // xml serialization XmlWriter xmlWriter = XmlWriter.Create(filePath); XmlSerializer xmlSerializer = new XmlSerializer(typeof(List)); xmlSerializer.Serialize(xmlWriter, _libraries); xmlWriter.Close(); } public static List LoadLibraries(string filePath) { // xml de-serialization XmlReader xmlReader = XmlReader.Create(filePath); XmlSerializer xmlSerializer = new XmlSerializer(typeof(List)); _libraries = (List)xmlSerializer.Deserialize(xmlReader); xmlReader.Close(); UpgradeLibraries(); return Libraries; } /// /// When the WinLibrary class changes, we need to make some modifications. /// private static void UpgradeLibraries() { foreach (WinLibrary lib in _libraries) { // Make sure that the icon reference is valid. if (String.IsNullOrEmpty(lib.IconReference.ReferencePath)) { lib.IconReference = new IconReference(WinLibrary.DefaultIconReference); } } } } }