Пример #1
0
        /// <summary>
        /// create folder
        /// </summary>
        /// <param name="sdei">sync execution information about directory</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 CreateFolder(SyncDirExecutionInfo sdei, Func <bool> interruptChecker)
        {
            if (interruptChecker())
            {
                return(true);
            }

            string sdp = sdei.AbsoluteSourcePath;
            string ddp = sdei.AbsoluteDestPath;

            if (!Delimon.Win32.IO.Directory.Exists(sdp))
            {
                return(false);
            }

            sdei.StartedNow();
            try
            {
                Delimon.Win32.IO.Directory.CreateDirectory(ddp);
                sdei.SyncElementInfo.SyncStatus = SyncElementStatus.ChangeApplied;
            }
            catch (Exception e)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.Unknown,
                                                                sdei.Direction == SyncDirection.To2 ? 2 : 1, "RunFolderCreationTask", e.Message, e));
            }
            sdei.EndedNow();

            return(false);
        }
Пример #2
0
 /// <summary>
 /// delete directory in new task
 /// </summary>
 /// <param name="di">directory information</param>
 /// <param name="result">
 /// 0: no error
 /// 1: the directory to be deleted was not found
 /// 2: the directory to be deleted was not empty
 /// </param>
 /// <returns>null if an error occurred</returns>
 private Task RunFolderDeletionTask(SyncDirExecutionInfo sdei)
 {
     return(Task.Run(() =>
     {
         int taskId = TaskStarted(NextTaskId);
         if (Helper.DeleteFolder(sdei, () => pauseIfRequested(true, taskId)))
         {
             return;
         }
         TaskEnded(taskId);
     }, _ct));
 }
Пример #3
0
        /// <summary>
        /// delete folder
        /// </summary>
        /// <param name="sdei">sync execution information about directory</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 DeleteFolder(SyncDirExecutionInfo sdei, Func <bool> interruptChecker)
        {
            if (interruptChecker())
            {
                return(true);
            }

            string ddp = sdei.AbsoluteDestPath;

            Delimon.Win32.IO.DirectoryInfo ddi = new Delimon.Win32.IO.DirectoryInfo(ddp);

            if (!ddi.Exists)
            {
                return(false);
            }

            //do not remove if directory is not empty
            if (ddi.GetFiles().Length > 0 || ddi.GetDirectories().Length > 0)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.DirNotEmpty,
                                                                sdei.Direction == SyncDirection.To1 ? 1 : 2, "RunFolderDeletionTask",
                                                                $"The directory to be deleted was not empty. Path: {sdei.SyncDirInfo.DirInfo.FullPath}", null));
                return(false);
            }

            interruptChecker();

            sdei.StartedNow();
            try
            {
                ddi.Delete();
                sdei.SyncDirInfo.SyncStatus = SyncElementStatus.ChangeApplied;
            }
            catch (Exception e)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.Unknown,
                                                                sdei.Direction == SyncDirection.To2 ? 2 : 1, "RunFolderDeletionTask", e.Message, e));
            }
            sdei.EndedNow();

            return(false);
        }
Пример #4
0
        /// <summary>
        /// create missing folders in new task
        /// </summary>
        /// <param name="di">direcotry info</param>
        /// <returns></returns>
        private Task RunFolderCreationTask(SyncDirExecutionInfo sdei)
        {
            string sdp = sdei.AbsoluteSourcePath;
            string ddp = sdei.AbsoluteDestPath;

            if (!Delimon.Win32.IO.Directory.Exists(sdp))
            {
                return(null);
            }

            return(Task.Run(() =>
            {
                int taskId = TaskStarted(NextTaskId);
                if (Helper.CreateFolder(sdei, () => pauseIfRequested(true, taskId)))
                {
                    return;
                }
                TaskEnded(taskId);
            }, _ct));
        }
Пример #5
0
        /// <summary>
        /// create missing folders in new task
        /// </summary>
        /// <param name="di">direcotry info</param>
        /// <returns></returns>
        private Task RunFolderCreationTask(SyncDirExecutionInfo sdei)
        {
            string sdp = sdei.AbsoluteSourcePath;
            string ddp = sdei.AbsoluteDestPath;
            
            if (!Delimon.Win32.IO.Directory.Exists(sdp))
                return null;

            return Task.Run(() =>
            {
                int taskId = TaskStarted(NextTaskId);
                if (Helper.CreateFolder(sdei, () => pauseIfRequested(true, taskId)))
                    return;
                TaskEnded(taskId);
            }, _ct);
        }
Пример #6
0
 /// <summary>
 /// delete directory in new task
 /// </summary>
 /// <param name="di">directory information</param>
 /// <param name="result">
 /// 0: no error
 /// 1: the directory to be deleted was not found
 /// 2: the directory to be deleted was not empty
 /// </param>
 /// <returns>null if an error occurred</returns>
 private Task RunFolderDeletionTask(SyncDirExecutionInfo sdei)
 {
     return Task.Run(() =>
     {
         int taskId = TaskStarted(NextTaskId);
         if (Helper.DeleteFolder(sdei, () => pauseIfRequested(true, taskId)))
             return;
         TaskEnded(taskId);
     }, _ct);
 }
Пример #7
0
        /// <summary>
        /// delete folder
        /// </summary>
        /// <param name="sdei">sync execution information about directory</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 DeleteFolder(SyncDirExecutionInfo sdei, Func<bool> interruptChecker)
        {
            if (interruptChecker()) return true;

            string ddp = sdei.AbsoluteDestPath;
            Delimon.Win32.IO.DirectoryInfo ddi = new Delimon.Win32.IO.DirectoryInfo(ddp);

            if (!ddi.Exists)
                return false;

            //do not remove if directory is not empty
            if (ddi.GetFiles().Length > 0 || ddi.GetDirectories().Length > 0)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.DirNotEmpty,
                    sdei.Direction == SyncDirection.To1 ? 1 : 2, "RunFolderDeletionTask",
                    $"The directory to be deleted was not empty. Path: {sdei.SyncDirInfo.DirInfo.FullPath}", null));
                return false;
            }

            interruptChecker();

            sdei.StartedNow();
            try
            {
                ddi.Delete();
                sdei.SyncDirInfo.SyncStatus = SyncElementStatus.ChangeApplied;
            }
            catch (Exception e)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.Unknown,
                    sdei.Direction == SyncDirection.To2 ? 2 : 1, "RunFolderDeletionTask", e.Message, e));
            }
            sdei.EndedNow();

            return false;
        }
Пример #8
0
        /// <summary>
        /// create folder
        /// </summary>
        /// <param name="sdei">sync execution information about directory</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 CreateFolder(SyncDirExecutionInfo sdei, Func<bool> interruptChecker)
        {
            if(interruptChecker()) return true;

            string sdp = sdei.AbsoluteSourcePath;
            string ddp = sdei.AbsoluteDestPath;

            if (!Delimon.Win32.IO.Directory.Exists(sdp))
                return false;

            sdei.StartedNow();
            try
            {
                Delimon.Win32.IO.Directory.CreateDirectory(ddp);
                sdei.SyncElementInfo.SyncStatus = SyncElementStatus.ChangeApplied;
            }
            catch (Exception e)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.Unknown,
                    sdei.Direction == SyncDirection.To2 ? 2 : 1, "RunFolderCreationTask", e.Message, e));
            }
            sdei.EndedNow();

            return false;
        }