private static void Serialize(string file, MoveTrackerList mtl) { //string tmpFile = file + ".tmp"; string tmpFile = Path.GetTempFileName(); try { Stream streamWrite = File.Create(tmpFile); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(mtl.GetType()); xs.Serialize(streamWrite, mtl); streamWrite.Close(); if (File.Exists(file)) { File.Delete(file); } File.Move(tmpFile, file); } catch { throw; } }
public static MoveTrackerList LoadFromFile(string file) { if (!File.Exists(file)) { return(new MoveTrackerList()); } else { return(MoveTrackerList.Deserialize(file)); } }
private static MoveTrackerList Deserialize(string file) { try { Stream streamRead = File.OpenRead(file); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MoveTrackerList)); MoveTrackerList obj = (MoveTrackerList)xs.Deserialize(streamRead); obj.Sort(); streamRead.Close(); return(obj); } catch { // File.Delete(file); throw; } }
public static void SaveToFile(string file, MoveTrackerList mtl) { mtl.List.RemoveAll(n => n.DestinationDir == n.SourceDir); Serialize(file, mtl); }