/// <summary> /// Loads StreamSources from a specified file. /// </summary> /// <param name="fileName">The filename to load. If you are trying to load multiple distinct files, set bypassCache to true.</param> /// <param name="bypassCache"> /// Set to true to always read from the disk and return a distinct copy /// Set to false to use the cached copy if available. /// </param> /// <returns>the StreamSources from the indicated file</returns> public static StreamSources LoadFromFile(string fileName, bool bypassCache) { if ((_sources == null) || bypassCache) { FileStream file = null; try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(StreamSources)); file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); StreamSources s = (StreamSources)xmlSerializer.Deserialize(file); if (bypassCache) { return(s); } else { _sources = s; } } finally { if (file != null) { file.Close(); file.Dispose(); } } } return(_sources); }
/// <summary> /// Writes a <see cref="StreamSources"/> collection to disk at the <see cref="P:PersistFileName"/> location. /// </summary> /// <param name="sources">sources to write</param> public static void SaveToFile(StreamSources sources) { FileStream file = null; try { XmlSerializer xmlSerializer = new XmlSerializer(sources.GetType()); file = new FileStream(PersistFileName, FileMode.Create, FileAccess.Write, FileShare.None); xmlSerializer.Serialize(file, sources); } finally { if (file != null) { file.Close(); file.Dispose(); } } }