/// <summary> /// Save MRU items to xml file /// </summary> /// <param name="items">MRU items to save</param> public void SaveMRUItems(IEnumerable <MRUItem> items) { Stream seralizationStream = null; try { seralizationStream = File.Create(storageFilePath); XmlSerializer serializer = new XmlSerializer(typeof(MRUItemsHolder)); MRUItemsHolder holder = new MRUItemsHolder { Items = items as List <MRUItem> }; serializer.Serialize(seralizationStream, holder); } catch (Exception ex) { if (seralizationStream != null) { seralizationStream.Close(); } throw new Exception(string.Format("MRUItemFileStorage: Fail to save object to storage!\r\n{0}", ex.Message)); } finally { if (seralizationStream != null) { seralizationStream.Close(); } } }
/// <summary> /// Read MRU items from xml file /// </summary> /// <returns>List of MRU items</returns> public IEnumerable <MRUItem> ReadMRUItems() { Stream deseralizationStream = null; try { deseralizationStream = File.OpenRead(storageFilePath); XmlSerializer serializer = new XmlSerializer(typeof(MRUItemsHolder)); MRUItemsHolder holder = serializer.Deserialize(deseralizationStream) as MRUItemsHolder; return(holder.Items); } catch (Exception ex) { if (deseralizationStream != null) { deseralizationStream.Close(); } throw new Exception(string.Format("MRUItemFileStorage: Fail to read object from storage!\r\n{0}", ex.Message)); } finally { if (deseralizationStream != null) { deseralizationStream.Close(); } } }