示例#1
0
        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;
            }
        }
示例#2
0
 public static MoveTrackerList LoadFromFile(string file)
 {
     if (!File.Exists(file))
     {
         return(new MoveTrackerList());
     }
     else
     {
         return(MoveTrackerList.Deserialize(file));
     }
 }
示例#3
0
 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;
     }
 }
示例#4
0
 public static void SaveToFile(string file, MoveTrackerList mtl)
 {
     mtl.List.RemoveAll(n => n.DestinationDir == n.SourceDir);
     Serialize(file, mtl);
 }