/// <summary> /// apply change to a file in new task (deleting or copying) /// </summary> /// <param name="sfei">sync execution information about file</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static bool ApplyFileChange(SyncFileExecutionInfo sfei, Func <bool> interruptChecker) { if (interruptChecker()) { return(true); } string sfp = sfei.AbsoluteSourcePath; string dfp = sfei.AbsoluteDestPath; Delimon.Win32.IO.FileInfo sfi = new Delimon.Win32.IO.FileInfo(sfp); sfei.StartedNow(); try { if (sfei.Remove) { File.SetAttributes(dfp, FileAttributes.Normal); //change attributes to avoid UnauthorizedAccessException File.Delete(dfp); } else if (sfi.Exists) { //Copy Methods: //FileMove2(sfp, dfp, interruptChecker); File.Copy(sfp, dfp, true); } sfei.SyncFileInfo.SyncStatus = SyncElementStatus.ChangeApplied; } catch (IOException ioe) { string[] parts = ioe.Message.Split('\"'); if (parts.Length > 1) { string path = parts[1]; int conflictPath = path.Contains(sfei.SyncFileInfo.SyncInfo.Link.Path1) ? 1 : 2; sfei.SyncFileInfo.Conflicted(new FileConflictInfo(sfei.SyncFileInfo, ConflictType.IO, conflictPath, "RunApplyFileChangeTask", ioe.Message, ioe)); } } catch (UnauthorizedAccessException uae) { string[] parts = uae.Message.Split('\"'); if (parts.Length > 1) { string path = parts[1]; int conflictPath = path.Contains(sfei.SyncFileInfo.SyncInfo.Link.Path1) ? 1 : 2; sfei.SyncFileInfo.Conflicted(new FileConflictInfo(sfei.SyncFileInfo, ConflictType.UA, conflictPath, "RunApplyFileChangeTask", uae.Message, uae)); } } catch (Exception e) { sfei.SyncFileInfo.Conflicted(new FileConflictInfo(sfei.SyncFileInfo, ConflictType.Unknown, 0, "RunApplyFileChangeTask", e.Message, e)); } sfei.EndedNow(); return(false); }
/// <summary> /// apply change to a file in new task (deleting or copying) /// </summary> /// <param name="sfei">sync execution information about file</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static bool ApplyFileChange(SyncFileExecutionInfo sfei, Func<bool> interruptChecker) { if(interruptChecker()) return true; string sfp = sfei.AbsoluteSourcePath; string dfp = sfei.AbsoluteDestPath; Delimon.Win32.IO.FileInfo sfi = new Delimon.Win32.IO.FileInfo(sfp); sfei.StartedNow(); try { if (sfei.Remove) { File.SetAttributes(dfp, FileAttributes.Normal); //change attributes to avoid UnauthorizedAccessException File.Delete(dfp); } else if (sfi.Exists) { //Copy Methods: //FileMove2(sfp, dfp, interruptChecker); File.Copy(sfp, dfp, true); } sfei.SyncFileInfo.SyncStatus = SyncElementStatus.ChangeApplied; } catch (IOException ioe) { string[] parts = ioe.Message.Split('\"'); if (parts.Length > 1) { string path = parts[1]; int conflictPath = path.Contains(sfei.SyncFileInfo.SyncInfo.Link.Path1) ? 1 : 2; sfei.SyncFileInfo.Conflicted(new FileConflictInfo(sfei.SyncFileInfo, ConflictType.IO, conflictPath, "RunApplyFileChangeTask", ioe.Message, ioe)); } } catch (UnauthorizedAccessException uae) { string[] parts = uae.Message.Split('\"'); if (parts.Length > 1) { string path = parts[1]; int conflictPath = path.Contains(sfei.SyncFileInfo.SyncInfo.Link.Path1) ? 1 : 2; sfei.SyncFileInfo.Conflicted(new FileConflictInfo(sfei.SyncFileInfo, ConflictType.UA, conflictPath, "RunApplyFileChangeTask", uae.Message, uae)); } } catch (Exception e) { sfei.SyncFileInfo.Conflicted(new FileConflictInfo(sfei.SyncFileInfo, ConflictType.Unknown, 0, "RunApplyFileChangeTask", e.Message, e)); } sfei.EndedNow(); return false; }
/// <summary> /// apply change to a file in new task /// including file deleting /// </summary> /// <param name="file"></param> /// <returns></returns> private Task <SyncFileExecutionInfo> RunApplyFileChangeTask(SyncFileExecutionInfo sfei) { return(Task.Run(() => { int taskId = TaskStarted(NextTaskId); if (Helper.ApplyFileChange(sfei, () => pauseIfRequested(true, taskId))) { return null; } TaskEnded(taskId); return sfei; }, _ct)); }
/// <summary> /// apply change to a file in new task /// including file deleting /// </summary> /// <param name="file"></param> /// <returns></returns> private Task<SyncFileExecutionInfo> RunApplyFileChangeTask(SyncFileExecutionInfo sfei) { return Task.Run(() => { int taskId = TaskStarted(NextTaskId); if(Helper.ApplyFileChange(sfei, () => pauseIfRequested(true, taskId))) return null; TaskEnded(taskId); return sfei; }, _ct); }