Ejemplo n.º 1
0
        /// <summary>
        /// Perform preview sync between source clean file and target dirty file. dirty = modification, deletion and rename.
        /// </summary>
        /// <param name="relativePath"></param>
        /// <param name="tgtFlag"></param>
        private void PreviewSrcCleanTgtDirty(String relativePath, String tgtFlag)
        {
            PreviewUnit preview = new PreviewUnit();
            preview.intDirtyType = 1;

            switch (tgtFlag)
            {
                case cFlag:
                    {
                        if (!_tgtRenameList.ContainsPriKey(relativePath))
                        {
                            PreviewCheckAndCreateTgtFolder(relativePath);
                            preview.sAction = SyncAction.CopyFileToSource;
                            preview.cleanRelativePath = "";
                            preview.cleanFileUnit = null;
                            preview.srcFlag = dFlag;
                            preview.tgtFlag = cFlag;
                            _previewFilesList.Add(relativePath, relativePath, preview);
                        }
                        else
                        {
                            String delRelativePath = _tgtRenameList.PriSub[relativePath];
                            if (_srcCleanFilesList.ContainsPriKey(delRelativePath))
                            {
                                preview.sAction = SyncAction.RenameSourceFile;
                                preview.cleanRelativePath = delRelativePath;
                                preview.cleanFileUnit = _srcCleanFilesList.GetByPrimary(delRelativePath);
                                preview.srcFlag = "";
                                preview.tgtFlag = cFlag;
                                _previewFilesList.Add(delRelativePath, relativePath, preview);
                                _srcCleanFilesList.RemoveByPrimary(delRelativePath);
                            }
                        }
                    }
                    break;
                case mFlag:
                    {
                        preview.sAction = SyncAction.CopyFileToSource;
                        preview.cleanRelativePath = relativePath;
                        preview.cleanFileUnit = _srcCleanFilesList.GetByPrimary(relativePath);
                        preview.srcFlag = "";
                        preview.tgtFlag = mFlag;
                        _previewFilesList.Add(relativePath, relativePath, preview);
                        _srcCleanFilesList.RemoveByPrimary(relativePath);
                    }
                    break;
                case dFlag:
                    {
                        preview.sAction = SyncAction.DeleteSourceFile;
                        preview.cleanRelativePath = relativePath;
                        preview.cleanFileUnit = _srcCleanFilesList.GetByPrimary(relativePath);
                        preview.srcFlag = "";
                        preview.tgtFlag = dFlag;
                        _previewFilesList.Add(relativePath, relativePath, preview);
                        _srcCleanFilesList.RemoveByPrimary(relativePath);
                    }
                    break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Perform sync preview between source replica and target replica.
        /// </summary>
        public void Preview()
        {
            FileUnit srcFile; FileUnit tgtFile;

            GetFilesFoldersLists();
            CheckRename();

            foreach (var mySrcRecord in _srcDirtyFilesList.PriSub)
            {
                String relativePath = mySrcRecord.Key;
                String srcSecondKey = mySrcRecord.Value;
                String srcFlag = "" + srcSecondKey[0];
                srcFile = _srcDirtyFilesList.GetByPrimary(relativePath);

                if (srcFlag.Equals(dFlag) && _srcRenameList.ContainsSecKey(relativePath))
                    continue;

                if (_tgtCleanFilesList.ContainsPriKey(relativePath))
                    PreviewSrcDirtyTgtClean(relativePath, srcFlag);

                else if (!_tgtDirtyFilesList.ContainsPriKey(relativePath))
                {
                    if (srcFlag.Equals(cFlag))
                    {
                        if (!_srcRenameList.ContainsPriKey(relativePath))
                            PreviewSrcDirtyTgtClean(relativePath, srcFlag);

                        else
                        {
                            String delRelativePath = _srcRenameList.PriSub[relativePath];
                            if (_tgtCleanFilesList.ContainsPriKey(delRelativePath))
                                PreviewSrcDirtyTgtClean(relativePath, srcFlag);

                            else if (_tgtDirtyFilesList.ContainsPriKey(delRelativePath))
                                PreviewSrcDirtyTgtDirty(relativePath, srcFlag, srcFile, delRelativePath, "", null);
                        }
                    }
                }
                else if (_tgtDirtyFilesList.ContainsPriKey(relativePath))
                {
                    string tgtSecondKey = _tgtDirtyFilesList.PriSub[relativePath];
                    String tgtFlag = "" + tgtSecondKey[0];
                    String tgtHashCode = tgtSecondKey.Substring(2);
                    tgtFile = _tgtDirtyFilesList.GetByPrimary(relativePath);

                    if (tgtFlag.Equals(dFlag) && _tgtRenameList.ContainsSecKey(relativePath))
                        PreviewSrcDirtyTgtDirty(relativePath, srcFlag, srcFile, relativePath, tgtFlag, tgtFile);

                    else if (srcFlag.Equals(cFlag) && _srcRenameList.ContainsPriKey(relativePath))
                        PreviewSrcDirtyTgtDirty(relativePath, srcFlag, srcFile, relativePath, tgtFlag, tgtFile);

                    else
                    {
                        PreviewSrcDirtyTgtDirty(relativePath, srcFlag, srcFile, relativePath, tgtFlag, tgtFile);
                    }
                }
            }

            foreach (var myTgtRecord in _tgtDirtyFilesList.PriSub)
            {
                String relativePath = myTgtRecord.Key;
                String tgtSecondKey = myTgtRecord.Value;
                String tgtFlag = "" + tgtSecondKey[0];

                if (tgtFlag.Equals(dFlag) && _tgtRenameList.ContainsSecKey(relativePath))
                    continue;
                PreviewSrcCleanTgtDirty(relativePath, tgtFlag);
            }

            foreach (var myRecord in _srcCleanFilesList.PriSub)
            {
                String relativePath = myRecord.Key;
                PreviewUnit preview = new PreviewUnit();
                preview.intDirtyType = 3;
                preview.sAction = SyncAction.NoAction;
                preview.cleanRelativePath = relativePath;
                preview.cleanFileUnit = _srcCleanFilesList.GetByPrimary(relativePath);
                _previewFilesList.Add(relativePath, relativePath, preview);
            }

            PreviewFoldersCleanup();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Preview folder cleanup after synchronization.
        /// </summary>
        private void PreviewFoldersCleanup()
        {
            foreach (var mySrcRecord in _srcDirtyFoldersList.PriSub)
            {
                String relativePath = mySrcRecord.Key;
                String srcSecondKey = mySrcRecord.Value;
                String srcFlag = "" + srcSecondKey[0];
                FileUnit srcFile = _srcDirtyFoldersList.GetByPrimary(relativePath);

                PreviewUnit preview = new PreviewUnit();

                if (srcFlag.Equals(cFlag))
                {
                    preview.srcFlag = cFlag;
                    preview.tgtFlag = dFlag;
                    preview.srcFile = srcFile;

                    if (_tgtDirtyFoldersList.ContainsSecKey(cFlag + "-" + relativePath))
                    {
                        preview.sAction = SyncAction.NoAction;
                        _tgtDirtyFoldersList.RemoveByPrimary(relativePath);
                    }
                    else
                        preview.sAction = SyncAction.CreateTargetDir;

                }
                else if (srcFlag.Equals(dFlag))
                {
                    preview.cleanRelativePath = relativePath;
                    preview.cleanFileUnit = srcFile;
                    preview.srcFlag = dFlag;

                    if (_tgtDirtyFoldersList.ContainsSecKey(dFlag + "-" + relativePath))
                    {
                        preview.sAction = SyncAction.DeleteBothDir;
                        preview.tgtFlag = dFlag;
                        _tgtDirtyFoldersList.RemoveByPrimary(relativePath);
                    }
                    else if (_tgtCleanFoldersList.ContainsPriKey(relativePath))
                    {
                        if (!Directory.Exists(_tgtPath + relativePath))
                            preview.tgtFlag = dFlag;

                        else
                            preview.tgtFlag = "";

                        preview.sAction = SyncAction.DeleteTargetDir;
                        _tgtCleanFoldersList.RemoveByPrimary(relativePath);
                    }
                }
                _previewFoldersList.Add(relativePath, relativePath, preview);

            }

            foreach (var myTgtRecord in _tgtDirtyFoldersList.PriSub)
            {
                PreviewUnit preview = new PreviewUnit();

                String relativePath = myTgtRecord.Key;
                String tgtSecondKey = myTgtRecord.Value;
                String tgtFlag = "" + tgtSecondKey[0];
                FileUnit tgtFile = _tgtDirtyFoldersList.GetByPrimary(relativePath);

                if (tgtFlag.Equals(cFlag))
                {
                    preview.sAction = SyncAction.CreateSourceDir;
                    preview.srcFlag = dFlag;
                    preview.tgtFlag = cFlag;
                    preview.tgtFile = tgtFile;
                }
                else if (tgtFlag.Equals(dFlag))
                {
                    preview.cleanRelativePath = relativePath;
                    preview.cleanFileUnit = tgtFile;
                    preview.srcFlag = "";
                    preview.tgtFlag = dFlag;
                    preview.sAction = SyncAction.DeleteSourceDir;
                    _srcCleanFoldersList.RemoveByPrimary(relativePath);
                }
                _previewFoldersList.Add(relativePath, relativePath, preview);
            }

            foreach (var myRecord in _srcCleanFoldersList.PriSub)
            {
                PreviewUnit preview = new PreviewUnit();
                preview.sAction = SyncAction.NoAction;
                preview.cleanRelativePath = myRecord.Key;
                preview.srcFile = preview.cleanFileUnit = _srcCleanFoldersList.Primary[myRecord.Key];
                _previewFoldersList.Add(myRecord.Key, myRecord.Key, preview);
                if (_tgtCleanFoldersList.ContainsPriKey(myRecord.Key))
                    _tgtCleanFoldersList.RemoveByPrimary(myRecord.Key);
            }

            foreach (var myRecord in _tgtCleanFoldersList.PriSub)
            {
                PreviewUnit preview = new PreviewUnit();
                preview.sAction = SyncAction.NoAction;
                preview.cleanRelativePath = myRecord.Key;
                preview.srcFile = preview.cleanFileUnit = _tgtCleanFoldersList.Primary[myRecord.Key];
                if (!_previewFoldersList.ContainsPriKey(myRecord.Key))
                    _previewFoldersList.Add(myRecord.Key, myRecord.Key, preview);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  Perform sync action based on preview result between source dirty file and target dirty file. dirty = modification, deletion and rename.
        /// </summary>
        /// <param name="srcRelativePath"></param>
        /// <param name="tgtRelativePath"></param>
        /// <param name="preview"></param>
        private void SyncPreviewSrcDirtyTgtDirty(String srcRelativePath, String tgtRelativePath, PreviewUnit preview)
        {
            int iSrcSlash = srcRelativePath.LastIndexOf('\\');
            int iTgtSlash = tgtRelativePath.LastIndexOf('\\');

            String srcFilePath = "";
            if (iSrcSlash > 0) { srcFilePath = srcRelativePath.Substring(0, iSrcSlash + 1); }

            String tgtFilePath = "";
            if (iTgtSlash > 0) { tgtFilePath = tgtRelativePath.Substring(0, iTgtSlash + 1); }

            if (!srcFilePath.Equals(tgtFilePath))
            {

                if (_taskSettings.FolderConflict == TaskSettings.ConflictFolderAction.KeepSourceName)
                {
                    if (!preview.tgtFlag.Equals(dFlag))
                    {
                        if (preview.srcFlag.Equals(dFlag))
                        {
                            PreviewUnit previewFolder = _previewFoldersList.GetByPrimary(srcFilePath);
                            if (previewFolder.srcFlag.Equals(dFlag)) srcFilePath = tgtFilePath;
                        }
                        else
                        {
                            CheckAndCreateFolder(_tgtPath + srcRelativePath);
                            File.Move(_tgtPath + tgtRelativePath, _tgtPath + srcFilePath + tgtRelativePath.Substring(iTgtSlash));
                            DirectoryInfo dir = new DirectoryInfo(_tgtPath + tgtFilePath);

                            int iFileCount = dir.GetFiles().Length;
                            int iDirCount = dir.GetDirectories().Length;

                            if (iFileCount == 0 && iDirCount == 0)
                            {
                                if (_previewFoldersList.ContainsPriKey(tgtFilePath))
                                {
                                    PreviewUnit previewFolder = _previewFoldersList.GetByPrimary(tgtFilePath);
                                    previewFolder.srcFlag = dFlag;
                                    previewFolder.tgtFlag = dFlag;
                                    _previewFoldersList.RemoveByPrimary(tgtFilePath);
                                    _previewFoldersList.Add(tgtFilePath, tgtFilePath, previewFolder);
                                }
                            }
                        }
                    }
                    tgtFilePath = srcFilePath;
                }
                else
                {
                    if (!preview.srcFlag.Equals(dFlag))
                    {
                        if (preview.tgtFlag.Equals(dFlag))
                        {
                            PreviewUnit previewFolder = _previewFoldersList.GetByPrimary(tgtFilePath);
                            if (previewFolder.tgtFlag.Equals(dFlag)) tgtFilePath = srcFilePath;
                        }
                        else
                        {
                            CheckAndCreateFolder(_srcPath + tgtRelativePath);
                            File.Move(_srcPath + srcRelativePath, _srcPath + tgtFilePath + srcRelativePath.Substring(iTgtSlash));
                            DirectoryInfo dir = new DirectoryInfo(_srcPath + srcFilePath);

                            int iFileCount = dir.GetFiles().Length;
                            int iDirCount = dir.GetDirectories().Length;

                            if (iFileCount == 0 && iDirCount == 0)
                            {
                                if (_previewFoldersList.ContainsPriKey(srcFilePath))
                                {
                                    PreviewUnit previewFolder = _previewFoldersList.GetByPrimary(srcFilePath);
                                    previewFolder.srcFlag = dFlag;
                                    previewFolder.tgtFlag = dFlag;
                                    _previewFoldersList.RemoveByPrimary(srcFilePath);
                                    _previewFoldersList.Add(srcFilePath, srcFilePath, previewFolder);
                                }
                            }
                        }
                    }
                    srcFilePath = tgtFilePath;
                }
                executeSyncAction(preview.srcFile, preview.tgtFile, preview.srcFlag, preview.tgtFlag,
                                _srcPath + srcFilePath, _tgtPath + tgtFilePath);
            }
            else
            {
                executeSyncAction(preview.srcFile, preview.tgtFile, preview.srcFlag, preview.tgtFlag,
                        _srcPath + srcFilePath, _tgtPath + srcFilePath);

                if (preview.srcFlag.Equals(cFlag) && preview.srcOldRelativePath != null)
                {
                    if (File.Exists(_tgtPath + preview.srcOldRelativePath)) File.Delete(_tgtPath + preview.srcOldRelativePath);

                    if (preview.tgtFlag.Equals(cFlag) && preview.tgtOldRelativePath != null)
                        if (File.Exists(_srcPath + preview.tgtOldRelativePath))
                            File.Delete(_srcPath + preview.tgtOldRelativePath);
                }
                else if (preview.srcFlag.Equals(cFlag) && preview.tgtOldRelativePath != null)
                    if (File.Exists(_srcPath + preview.tgtOldRelativePath))
                        File.Delete(_srcPath + preview.tgtOldRelativePath);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Perform sync action based on preview result between source dirty file and target clean file. dirty = modification, deletion and rename.
 /// </summary>
 /// <param name="srcRelativePath"></param>
 /// <param name="tgtRelativePath"></param>
 /// <param name="preview"></param>
 private void SyncPreviewSrcDirtyTgtClean(String srcRelativePath, String tgtRelativePath, PreviewUnit preview)
 {
     switch (preview.sAction)
     {
         case SyncAction.CopyFileToTarget:
             {
                 CheckAndCreateFolder(_tgtPath + srcRelativePath);
                 File.Copy(_srcPath + srcRelativePath, _tgtPath + srcRelativePath, true);
                 long fileSize = new FileInfo(_srcPath + srcRelativePath).Length;
                 Logger.WriteLog(Logger.LogType.CopySRC, _srcPath + srcRelativePath, fileSize, _tgtPath + srcRelativePath, fileSize);
                 FileUnit myFile = new FileUnit(_srcPath + srcRelativePath);
                 myFile.Hash = Utility.ComputeMyHash(myFile);
                 _updatedList.Add(srcRelativePath, myFile.Hash, myFile);
             }
             break;
         case SyncAction.RenameTargetFile:
             {
                 CheckAndCreateFolder(_tgtPath + srcRelativePath);
                 File.Move(_tgtPath + preview.cleanRelativePath, _tgtPath + srcRelativePath);
                 long fileSize = new FileInfo(_tgtPath + srcRelativePath).Length;
                 Logger.WriteLog(Logger.LogType.RenameTGT, _tgtPath + preview.cleanRelativePath, fileSize, _tgtPath + srcRelativePath, fileSize);
                 FileUnit myFile = new FileUnit(_tgtPath + srcRelativePath);
                 myFile.Hash = Utility.ComputeMyHash(myFile);
                 _updatedList.Add(srcRelativePath, myFile.Hash, myFile);
             }
             break;
         case SyncAction.DeleteTargetFile:
             {
                 long fileSize = new FileInfo(_tgtPath + srcRelativePath).Length;
                 File.Delete(_tgtPath + srcRelativePath);
                 Logger.WriteLog(Logger.LogType.DeleteTGT, null, 0, _tgtPath + srcRelativePath, fileSize);
             }
             break;
         case SyncAction.NoAction:
             {
                 _updatedList.Add(preview.cleanRelativePath, preview.cleanFileUnit.Hash, preview.cleanFileUnit);
             }
             break;
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Perform sync folder based on the preview result
 /// </summary>
 /// <param name="srcRelativePath"></param>
 /// <param name="tgtRelativePath"></param>
 /// <param name="preview"></param>
 private void SyncPreviewFoldersCleanup(String srcRelativePath, String tgtRelativePath, PreviewUnit preview)
 {
     switch (preview.sAction)
     {
         case SyncAction.CreateSourceDir:
             {
                 if (!Directory.Exists(_srcPath + srcRelativePath))
                     Directory.CreateDirectory(_srcPath + srcRelativePath);
                 if (!_updatedList.ContainsPriKey(srcRelativePath))
                     _updatedList.Add(srcRelativePath, srcRelativePath, preview.tgtFile);
             }
             break;
         case SyncAction.CreateTargetDir:
             {
                 if (!Directory.Exists(_tgtPath + tgtRelativePath))
                     Directory.CreateDirectory(_tgtPath + tgtRelativePath);
                 if (!_updatedList.ContainsPriKey(tgtRelativePath))
                     _updatedList.Add(srcRelativePath, tgtRelativePath, preview.srcFile);
             }
             break;
         case SyncAction.DeleteBothDir:
             {
                 if (Directory.Exists(_srcPath + srcRelativePath))
                     Directory.Delete(_srcPath + srcRelativePath);
                 if (Directory.Exists(_tgtPath + tgtRelativePath))
                     Directory.Delete(_tgtPath + tgtRelativePath);
             }
             break;
         case SyncAction.DeleteSourceDir:
             {
                 if (Directory.Exists(_srcPath + srcRelativePath))
                     Directory.Delete(_srcPath + srcRelativePath, true);
             }
             break;
         case SyncAction.DeleteTargetDir:
             {
                 if (Directory.Exists(_tgtPath + tgtRelativePath))
                     Directory.Delete(_tgtPath + tgtRelativePath, true);
             }
             break;
         case SyncAction.NoAction:
             {
                 if (Directory.Exists(_srcPath + srcRelativePath) && Directory.Exists(_tgtPath + tgtRelativePath))
                     _updatedList.Add(srcRelativePath, srcRelativePath, preview.srcFile);
                 else
                 {
                     if (Directory.Exists(_srcPath + srcRelativePath))
                         Directory.Delete(_srcPath + srcRelativePath, true);
                     if (Directory.Exists(_tgtPath + tgtRelativePath))
                         Directory.Delete(_tgtPath + tgtRelativePath, true);
                 }
             }
             break;
         case SyncAction.Skip:
             {
                 if (!String.IsNullOrEmpty(preview.cleanRelativePath))
                     _updatedList.Add(preview.cleanRelativePath, preview.cleanRelativePath, preview.cleanFileUnit);
             }
             break;
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Perform preview sync between source dirty file and target dirty file. dirty = modification, deletion and rename.
        /// </summary>
        /// <param name="srcRelativePath"></param>
        /// <param name="srcFlag"></param>
        /// <param name="srcFile"></param>
        /// <param name="tgtRelativePath"></param>
        /// <param name="tgtFlag"></param>
        /// <param name="tgtFile"></param>
        private void PreviewSrcDirtyTgtDirty(String srcRelativePath, String srcFlag, FileUnit srcFile, String tgtRelativePath, String tgtFlag, FileUnit tgtFile)
        {
            PreviewUnit preview = new PreviewUnit();
            preview.intDirtyType = 2;

            if (_tgtDirtyFilesList.ContainsPriKey(tgtRelativePath))
            {
                if (_tgtRenameList.ContainsSecKey(tgtRelativePath) && !_tgtRenameList.ContainsPriKey(srcRelativePath))
                {
                    preview.cleanRelativePath = tgtRelativePath;
                    preview.cleanFileUnit = _tgtDirtyFilesList.GetByPrimary(tgtRelativePath);

                    tgtFlag = cFlag;
                    List<String> lstFiles = _tgtRenameList.SubPri[tgtRelativePath];
                    tgtRelativePath = lstFiles[0];
                    tgtFile = _tgtRenameList.GetByPrimary(tgtRelativePath);
                }
                else if (!_tgtDirtyFilesList.ContainsPriKey(srcRelativePath))
                {
                    tgtFlag = "" + _tgtDirtyFilesList.PriSub[tgtRelativePath][0];

                    preview.cleanRelativePath = tgtRelativePath;
                    preview.cleanFileUnit = tgtFile = _tgtDirtyFilesList.GetByPrimary(tgtRelativePath);
                }
                else if (srcFlag.Equals(cFlag) && _srcRenameList.ContainsPriKey(srcRelativePath))
                {
                    String cleanPath = _srcRenameList.PriSub[srcRelativePath];
                    preview.cleanRelativePath = cleanPath;
                    preview.cleanFileUnit = _srcDirtyFilesList.GetByPrimary(cleanPath);
                }
                else
                {
                    preview.cleanRelativePath = srcRelativePath;
                    preview.cleanFileUnit = srcFile;
                }

            }

            int iSrcSlash = srcRelativePath.LastIndexOf('\\');
            int iTgtSlash = tgtRelativePath.LastIndexOf('\\');

            String srcFilePath = "";
            if (iSrcSlash > 0) { srcFilePath = srcRelativePath.Substring(0, iSrcSlash + 1); }

            String tgtFilePath = "";
            if (iTgtSlash > 0) { tgtFilePath = tgtRelativePath.Substring(0, iTgtSlash + 1); }

            preview.srcFlag = srcFlag; preview.tgtFlag = tgtFlag;
            preview.srcFile = srcFile; preview.tgtFile = tgtFile;
            preview.sAction = SyncAction.NoAction;

            if (!srcFilePath.Equals(tgtFilePath))
            {
                preview.isPathDiff = true;

                if (_taskSettings.FolderConflict == TaskSettings.ConflictFolderAction.KeepSourceName)
                {
                    if (!tgtFlag.Equals(dFlag))
                    {
                        if (srcFlag.Equals(dFlag) && _srcDirtyFoldersList.ContainsSecKey(dFlag + "-" + srcFilePath))
                        {
                            PreviewCheckAndCreateTgtFolder(tgtRelativePath);
                            preview.sAction = checkConflicts(srcFile, tgtFile, srcFlag, tgtFlag);
                        }
                        else
                        {
                            if (_srcDirtyFoldersList.ContainsPriKey(tgtFilePath))
                                _srcDirtyFoldersList.RemoveByPrimary(tgtFilePath);

                            if (_tgtDirtyFoldersList.ContainsPriKey(tgtFilePath))
                            {
                                PreviewUnit previewFolder = new PreviewUnit();
                                previewFolder.sAction = SyncAction.DeleteTargetDir;
                                previewFolder.srcFlag = dFlag;
                                previewFolder.tgtFlag = cFlag;
                                _previewFoldersList.Add(tgtFilePath, tgtFilePath, previewFolder);

                                _tgtDirtyFoldersList.RemoveByPrimary(tgtFilePath);
                            }
                        }
                        if (preview.sAction == SyncAction.NoAction) preview.sAction = SyncAction.RenameTargetFile;
                    }
                    else
                        preview.sAction = SyncAction.CopyFileToTarget;
                }
                else
                {
                    if (!srcFlag.Equals(dFlag))
                    {
                        if (tgtFlag.Equals(dFlag) && _tgtDirtyFoldersList.ContainsSecKey(dFlag + "-" + tgtFilePath))
                        {
                            PreviewCheckAndCreateSrcFolder(srcRelativePath);
                            preview.sAction = checkConflicts(srcFile, tgtFile, srcFlag, tgtFlag);
                        }
                        else
                        {
                            if (_srcDirtyFoldersList.ContainsPriKey(srcFilePath))
                                _srcDirtyFoldersList.RemoveByPrimary(srcFilePath);

                            if (_tgtDirtyFoldersList.ContainsPriKey(srcFilePath))
                            {
                                PreviewUnit previewFolder = new PreviewUnit();
                                previewFolder.sAction = SyncAction.DeleteSourceDir;
                                previewFolder.srcFlag = cFlag;
                                previewFolder.tgtFlag = dFlag;
                                _previewFoldersList.Add(srcFilePath, srcFilePath, previewFolder);

                                _tgtDirtyFoldersList.RemoveByPrimary(srcFilePath);
                            }
                        }
                        if (preview.sAction == SyncAction.NoAction) preview.sAction = SyncAction.RenameSourceFile;
                    }
                    else
                        preview.sAction = SyncAction.CopyFileToSource;
                }
            }
            else
            {
                preview.isPathDiff = false;

                if (srcFlag.Equals(cFlag) && _srcRenameList.ContainsPriKey(srcRelativePath))
                {
                    String delSrcFile = _srcRenameList.PriSub[srcRelativePath];
                    preview.srcOldRelativePath = delSrcFile;

                    if (_tgtCleanFilesList.ContainsPriKey(delSrcFile)) _tgtCleanFilesList.RemoveByPrimary(delSrcFile);
                    if (tgtFlag.Equals(cFlag) && _tgtRenameList.ContainsPriKey(srcRelativePath))
                    {
                        String delTgtFile = _tgtRenameList.PriSub[srcRelativePath];
                        preview.tgtOldRelativePath = delTgtFile;
                        if (_srcCleanFilesList.ContainsPriKey(delTgtFile)) _srcCleanFilesList.RemoveByPrimary(delTgtFile);
                    }
                }
                else if (srcFlag.Equals(cFlag) && _tgtRenameList.ContainsPriKey(srcRelativePath))
                {
                    String delTgtFile = _tgtRenameList.PriSub[srcRelativePath];
                    preview.tgtOldRelativePath = delTgtFile;
                    if (_srcCleanFilesList.ContainsPriKey(delTgtFile)) _srcCleanFilesList.RemoveByPrimary(delTgtFile);
                }

                preview.sAction = checkConflicts(srcFile, tgtFile, srcFlag, tgtFlag);
            }
            _tgtDirtyFilesList.RemoveByPrimary(tgtRelativePath);
            _previewFilesList.Add(srcRelativePath, tgtRelativePath, preview);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Perform preview sync between source dirty file and target clean file. dirty = modification, deletion and rename.
        /// </summary>
        /// <param name="relativePath"></param>
        /// <param name="srcFlag"></param>
        private void PreviewSrcDirtyTgtClean(String relativePath, String srcFlag)
        {
            PreviewUnit preview = new PreviewUnit();
            preview.intDirtyType = 0;

            switch (srcFlag)
            {
                case cFlag:
                    {
                        preview.srcFlag = cFlag;

                        if (!_srcRenameList.ContainsPriKey(relativePath))
                        {
                            PreviewCheckAndCreateSrcFolder(relativePath);
                            preview.sAction = SyncAction.CopyFileToTarget;
                            preview.cleanRelativePath = "";
                            preview.cleanFileUnit = null;
                            preview.tgtFlag = dFlag;
                            _previewFilesList.Add(relativePath, relativePath, preview);
                        }
                        else
                        {
                            preview.tgtFlag = "";
                            String delRelativePath = _srcRenameList.PriSub[relativePath];
                            preview.sAction = SyncAction.RenameTargetFile;
                            preview.cleanRelativePath = delRelativePath;
                            preview.cleanFileUnit = _tgtCleanFilesList.GetByPrimary(delRelativePath);
                            _previewFilesList.Add(relativePath, delRelativePath, preview);
                            _tgtCleanFilesList.RemoveByPrimary(delRelativePath);
                        }
                    }
                    break;
                case mFlag:
                    {
                        preview.sAction = SyncAction.CopyFileToTarget;
                        preview.cleanRelativePath = relativePath;
                        preview.cleanFileUnit = _tgtCleanFilesList.GetByPrimary(relativePath);
                        preview.srcFlag = mFlag;
                        preview.tgtFlag = "";
                        _previewFilesList.Add(relativePath, relativePath, preview);
                        _tgtCleanFilesList.RemoveByPrimary(relativePath);
                    }
                    break;
                case dFlag:
                    {
                        preview.sAction = SyncAction.DeleteTargetFile;
                        preview.cleanRelativePath = relativePath;
                        preview.cleanFileUnit = _tgtCleanFilesList.GetByPrimary(relativePath);
                        preview.srcFlag = dFlag;
                        preview.tgtFlag = "";
                        _previewFilesList.Add(relativePath, relativePath, preview);
                        _tgtCleanFilesList.RemoveByPrimary(relativePath);
                    }
                    break;
            }
        }