Example #1
0
 private static void Compare(SyncFileData syncFileData, SyncDirectory syncDirA, SyncDirectory syncDirB)
 {
     var fileInfoHelper = new FileInfoHelper();
     var syncFile = syncDirB.SyncFileData.SingleOrDefault(f => f.Name == syncFileData.Name);
     if (syncFile == null)
     {
         fileInfoHelper.Copy(syncFileData, syncDirA, syncDirB);
     }
     else
     {
         if (syncFileData.Logs.Last().Hash != syncFile.Logs.Last().Hash)
         {
             if (syncFileData.Logs.Last().Date > syncFile.Logs.Last().Date)
             {
                 //fm.Copy(syncDirA, syncDirB, syncFileData);
             }
         }
         else
         {
             if (syncFileData.Logs.Last().Date > syncFile.Logs.Last().Date)
             {
                 // fm.Copy(syncDirB, syncDirA, syncFileData);
             }
         }
     }
 }
Example #2
0
        internal void Copy(SyncFileData fileToCopy, SyncDirectory fromDirectory, SyncDirectory toDirectory)
        {
            var src = Format(fromDirectory, fileToCopy.Name);
            var dest = Format(toDirectory, fileToCopy.Name);

            File.Copy(src, dest, true);
            var syncFileData
                = SyncFileManager.CreateSyncFileData(dest);

            var foo = toDirectory.SyncFileData.ToList();
            foo.Add(syncFileData);
            toDirectory.SyncFileData = foo;

            WriteToSyncFile(toDirectory);
        }
Example #3
0
        private static void UpdateSyncFile(SyncFileData file, SyncFileData fileInfo)
        {
            var last = file.Logs.Last(); // last log in sync file
            var hash = last.Hash; // hash of the file in sync log

            var dirlog = fileInfo.Logs.Last(); // last log
            var updateHash = dirlog.Hash; // hash of the update file in directory

            if (hash == updateHash)
            {
                return;
            }
            if (last.Date >= dirlog.Date)
            {
                throw new InvalidOperationException(
                    string.Format("Sync file date is new that directory file [{0}]", fileInfo.Name));
            }
            var syncFileLogs = file.Logs.ToList();

            syncFileLogs.Add(new Log
            {
                Hash = updateHash,
                Date = dirlog.Date
            });
        }