Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 4
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;
        }