Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        /// <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;
        }
Exemple #4
0
        /// <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;
        }