예제 #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);
 }