/// <summary> /// compare file in paths for two way synchronisation in new task /// </summary> /// <param name="fileName">filename</param> /// <param name="relativePath">file path relative to the homedir without filename</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static bool DoFileComparison_TwoWay(SyncFileInfo file, Func <bool> interruptChecker) { if (interruptChecker()) { return(true); } file.SyncStatus = SyncElementStatus.ChangeDetectingStarted; try { //compare TwoWayCompareResult compResult = Helper.CompareFiles_TwoWay(file); if (compResult == null) { file.SyncStatus = SyncElementStatus.NoChangeFound; } else { file.FileInfo.Size = new Delimon.Win32.IO.FileInfo(compResult.Direction == SyncDirection.To2 ? file.AbsolutePath1 : file.AbsolutePath2).Length; //load file size new SyncFileExecutionInfo(file, compResult.Direction, compResult.Remove); } } catch (Exception e) { file.Conflicted(new FileConflictInfo(file, ConflictType.Unknown, 0, "RunTwoWayFileCompareTask", e.Message, e)); } return(false); }
/// <summary> /// compare 2 files for two way synchronisation in new task /// </summary> /// <see cref="RunTwoWayFileCompareTask(SyncFileInfo)"/> private Task <SyncFileInfo> RunTwoWayFileCompareTask(SyncFileInfo file) { return(Task.Run(() => { int taskId = TaskStarted(NextTaskId); if (Helper.DoFileComparison_TwoWay(file, () => pauseIfRequested(true, taskId))) { return null; } TaskEnded(taskId); return file; }, _ct)); }
/// <summary> /// compare 2 files for one way synchronisation in new task /// </summary> /// <param name="sourcePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destPath">absolute destination folder path (homepath as defined in link)</param> /// <param name="fileName">file name</param> /// <param name="relativePath">file path relative to the homepath without filename</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static bool DoFileComparison_OneWay(string sourcePath, string destPath, SyncFileInfo file, Func <bool> interruptChecker) { if (interruptChecker()) { return(true); } file.SyncStatus = SyncElementStatus.ChangeDetectingStarted; string sf = sourcePath + file.FileInfo.FullPath; string df = destPath + file.FileInfo.FullPath; Delimon.Win32.IO.FileInfo srcFileInfo = new Delimon.Win32.IO.FileInfo(sf); Delimon.Win32.IO.FileInfo destFileInfo = new Delimon.Win32.IO.FileInfo(df); try { if (Helper.CompareFiles_OneWay(srcFileInfo, destFileInfo, interruptChecker)) { file.FileInfo.Size = srcFileInfo.Length; new SyncFileExecutionInfo(file, file.SyncInfo.Link.Direction, false); } } catch (Exception e) { if (file.SyncInfo != null) { file.Conflicted(new FileConflictInfo(file, ConflictType.Unknown, 0, "RunOneWayFileCompareTask", e.Message, e)); } else { file.SyncInfo.Log(new LogMessage(LogType.ERROR, e.Message, e)); } } return(false); }
/// <summary> /// Check if 2 Files are updated for two way synchronisation. /// The order of the files does not matter. /// </summary> /// <param name="fi1">file 1</param> /// <param name="fi2">file 2</param> /// <param name="remove">if remove is enabled</param> /// <param name="parentDir1">parent directory of file 1</param> /// <param name="parentDir2">parent directory of file 2</param> /// <returns>compare result</returns> public static TwoWayCompareResult CompareFiles_TwoWay(SyncFileInfo file) { Delimon.Win32.IO.FileInfo fi1 = new Delimon.Win32.IO.FileInfo(file.AbsolutePath1); Delimon.Win32.IO.FileInfo fi2 = new Delimon.Win32.IO.FileInfo(file.AbsolutePath2); Delimon.Win32.IO.DirectoryInfo parent1 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath1); Delimon.Win32.IO.DirectoryInfo parent2 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath2); bool remove = file.SyncInfo.Link.Remove; if (!fi1.Exists) { // if the parent directory of file 1 is older than file 2 -> create file in parent directory 1 // otherwise remove file 2 if remove ist enabled if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null) { if (parent1.LastWriteTime <= parent2.LastWriteTime) { return(new TwoWayCompareResult(SyncDirection.To1, false)); } else if (remove) { return(new TwoWayCompareResult(SyncDirection.To2, true)); } } else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To1) { return(new TwoWayCompareResult(SyncDirection.To1, false)); } else if (remove) { return(new TwoWayCompareResult(SyncDirection.To2, true)); } return(null); } if (!fi2.Exists) { // if the parent directory of file 2 is older than file 1 -> create file in parent directory 2 // otherwise remove file 1 if remove ist enabled if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null) { if (parent2.LastWriteTime <= parent1.LastWriteTime) { return(new TwoWayCompareResult(SyncDirection.To2, false)); } else if (remove) { return(new TwoWayCompareResult(SyncDirection.To1, true)); } } else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To2) { return(new TwoWayCompareResult(SyncDirection.To2, false)); } else if (remove) { return(new TwoWayCompareResult(SyncDirection.To1, true)); } return(null); } // update file 1 if file 2 is newer if (fi1.LastWriteTime < fi2.LastWriteTime) { return(new TwoWayCompareResult(SyncDirection.To1, false)); } // update file 2 if file 1 is newer if (fi1.LastWriteTime > fi2.LastWriteTime) { return(new TwoWayCompareResult(SyncDirection.To2, false)); } return(null); }
public SyncFileExecutionInfo(SyncFileInfo syncFileInfo, SyncDirection dir, bool remove) : base(syncFileInfo, dir, remove) { }
public FileConflictInfo(SyncFileInfo syncFileInfo, ConflictType type, int conflictPath, string context, string message, Exception exception) : base(syncFileInfo, type, conflictPath, context, message, exception) { }
/// <summary> /// compare 2 files for two way synchronisation in new task /// </summary> /// <see cref="RunTwoWayFileCompareTask(SyncFileInfo)"/> private Task<SyncFileInfo> RunTwoWayFileCompareTask(SyncFileInfo file) { return Task.Run(() => { int taskId = TaskStarted(NextTaskId); if(Helper.DoFileComparison_TwoWay(file, () => pauseIfRequested(true, taskId))) return null; TaskEnded(taskId); return file; }, _ct); }
/// <summary> /// compare 2 files for one way synchronisation in new task /// </summary> /// <see cref="Helper.DoFileComparison_OneWay(string, string, SyncFileInfo, Func{bool})"/> private Task<SyncFileInfo> RunOneWayFileCompareTask(string sourcePath, string destPath, SyncFileInfo file) { return Task.Run(() => { int taskId = TaskStarted(NextTaskId); Helper.DoFileComparison_OneWay(sourcePath, destPath, file, () => pauseIfRequested(true, taskId)); TaskEnded(taskId); return file; }, _ct); }
/// <summary> /// compare 2 files for one way synchronisation in new task /// </summary> /// <see cref="Helper.DoFileComparison_OneWay(string, string, SyncFileInfo, Func{bool})"/> private Task <SyncFileInfo> RunOneWayFileCompareTask(string sourcePath, string destPath, SyncFileInfo file) { return(Task.Run(() => { int taskId = TaskStarted(NextTaskId); Helper.DoFileComparison_OneWay(sourcePath, destPath, file, () => pauseIfRequested(true, taskId)); TaskEnded(taskId); return file; }, _ct)); }
/// <summary> /// compare file in paths for two way synchronisation in new task /// </summary> /// <param name="fileName">filename</param> /// <param name="relativePath">file path relative to the homedir without filename</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static bool DoFileComparison_TwoWay(SyncFileInfo file, Func<bool> interruptChecker) { if (interruptChecker()) return true; file.SyncStatus = SyncElementStatus.ChangeDetectingStarted; try { //compare TwoWayCompareResult compResult = Helper.CompareFiles_TwoWay(file); if (compResult == null) file.SyncStatus = SyncElementStatus.NoChangeFound; else { file.FileInfo.Size = new Delimon.Win32.IO.FileInfo(compResult.Direction == SyncDirection.To2 ? file.AbsolutePath1 : file.AbsolutePath2).Length; //load file size new SyncFileExecutionInfo(file, compResult.Direction, compResult.Remove); } } catch (Exception e) { file.Conflicted(new FileConflictInfo(file, ConflictType.Unknown, 0, "RunTwoWayFileCompareTask", e.Message, e)); } return false; }
/// <summary> /// compare 2 files for one way synchronisation in new task /// </summary> /// <param name="sourcePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destPath">absolute destination folder path (homepath as defined in link)</param> /// <param name="fileName">file name</param> /// <param name="relativePath">file path relative to the homepath without filename</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static bool DoFileComparison_OneWay(string sourcePath, string destPath, SyncFileInfo file, Func<bool> interruptChecker) { if(interruptChecker()) return true; file.SyncStatus = SyncElementStatus.ChangeDetectingStarted; string sf = sourcePath + file.FileInfo.FullPath; string df = destPath + file.FileInfo.FullPath; Delimon.Win32.IO.FileInfo srcFileInfo = new Delimon.Win32.IO.FileInfo(sf); Delimon.Win32.IO.FileInfo destFileInfo = new Delimon.Win32.IO.FileInfo(df); try { if (Helper.CompareFiles_OneWay(srcFileInfo, destFileInfo, interruptChecker)) { file.FileInfo.Size = srcFileInfo.Length; new SyncFileExecutionInfo(file, file.SyncInfo.Link.Direction, false); } } catch (Exception e) { if (file.SyncInfo != null) file.Conflicted(new FileConflictInfo(file, ConflictType.Unknown, 0, "RunOneWayFileCompareTask", e.Message, e)); else file.SyncInfo.Log(new LogMessage(LogType.ERROR, e.Message, e)); } return false; }
/// <summary> /// Check if 2 Files are updated for two way synchronisation. /// The order of the files does not matter. /// </summary> /// <param name="fi1">file 1</param> /// <param name="fi2">file 2</param> /// <param name="remove">if remove is enabled</param> /// <param name="parentDir1">parent directory of file 1</param> /// <param name="parentDir2">parent directory of file 2</param> /// <returns>compare result</returns> public static TwoWayCompareResult CompareFiles_TwoWay(SyncFileInfo file) { Delimon.Win32.IO.FileInfo fi1 = new Delimon.Win32.IO.FileInfo(file.AbsolutePath1); Delimon.Win32.IO.FileInfo fi2 = new Delimon.Win32.IO.FileInfo(file.AbsolutePath2); Delimon.Win32.IO.DirectoryInfo parent1 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath1); Delimon.Win32.IO.DirectoryInfo parent2 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath2); bool remove = file.SyncInfo.Link.Remove; if (!fi1.Exists) { // if the parent directory of file 1 is older than file 2 -> create file in parent directory 1 // otherwise remove file 2 if remove ist enabled if(file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null) { if (parent1.LastWriteTime <= parent2.LastWriteTime) return new TwoWayCompareResult(SyncDirection.To1, false); else if (remove) return new TwoWayCompareResult(SyncDirection.To2, true); } else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To1) return new TwoWayCompareResult(SyncDirection.To1, false); else if (remove) return new TwoWayCompareResult(SyncDirection.To2, true); return null; } if (!fi2.Exists) { // if the parent directory of file 2 is older than file 1 -> create file in parent directory 2 // otherwise remove file 1 if remove ist enabled if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null) { if (parent2.LastWriteTime <= parent1.LastWriteTime) return new TwoWayCompareResult(SyncDirection.To2, false); else if (remove) return new TwoWayCompareResult(SyncDirection.To1, true); } else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To2) return new TwoWayCompareResult(SyncDirection.To2, false); else if (remove) return new TwoWayCompareResult(SyncDirection.To1, true); return null; } // update file 1 if file 2 is newer if (fi1.LastWriteTime < fi2.LastWriteTime) return new TwoWayCompareResult(SyncDirection.To1, false); // update file 2 if file 1 is newer if (fi1.LastWriteTime > fi2.LastWriteTime) return new TwoWayCompareResult(SyncDirection.To2, false); return null; }