Ejemplo n.º 1
0
        public void ShowDifferences(ShowDiffArgs e)
        {
            DirectoryDiff diff = new DirectoryDiff(
                Options.ShowOnlyInA,
                Options.ShowOnlyInB,
                Options.ShowDifferent,
                Options.ShowSame,
                Options.Recursive,
                Options.IgnoreDirectoryComparison,
                Options.FileFilter);

            DirectoryDiffResults results = diff.Execute(e.A, e.B);

            this.DiffCtrl.SetData(results);

            this.Text = string.Format("{0} : {1}", results.DirectoryA.Name, results.DirectoryB.Name);

            this.Show();

            this.lastDiffArgs = e;
        }
        /// <summary>
        /// This function allows to synchronize a local folder with an folder exists in the cloud storage
        /// and vice versa. The local folder and the target folder has to be created before.
        /// </summary>
        /// <param name="srcFolder"></param>
        /// <param name="tgtFolder"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public Boolean SynchronizeFolder(DirectoryInfo srcFolder, ICloudDirectoryEntry tgtFolder, SyncFolderFlags flags)
        {
            // init ret value
            var bRet = true;

            // init helper parameter
            var bRecursive = ((flags & SyncFolderFlags.Recursive) != 0);

            // init the differ
            var diff = new DirectoryDiff(srcFolder, tgtFolder);

            // build the diff results
            var res = diff.Compare(bRecursive);

            // process the diff result
            foreach (var item in res)
            {
                switch (item.compareResult)
                {
                case ComparisonResult.Identical:
                {
                    continue;
                }

                case ComparisonResult.MissingInLocalFolder:
                {
                    // check of the upload flag was set
                    if ((flags & SyncFolderFlags.DownloadItems) != SyncFolderFlags.DownloadItems)
                    {
                        continue;
                    }

                    // copy remote to local or create path

                    // 1. get the rel path
                    String relPath;
                    if (item.remoteItem is ICloudDirectoryEntry)
                    {
                        relPath = GetFullCloudPath(tgtFolder, item.remoteItem, '\\');
                    }
                    else
                    {
                        relPath = GetFullCloudPath(tgtFolder, item.remoteItem.Parent, '\\');
                    }

                    // 2. ensure the directory exists
                    var tgtPath = Path.Combine(srcFolder.FullName, relPath);
                    if (!Directory.Exists(tgtPath))
                    {
                        Directory.CreateDirectory(tgtPath);
                    }

                    // 3. download file if needed
                    if (!(item.remoteItem is ICloudDirectoryEntry))
                    {
                        DownloadFile(item.remoteItem.Parent, item.remoteItem.Name, tgtPath);
                    }
                    break;
                }

                case ComparisonResult.MissingInRemoteFolder:
                {
                    // check of the upload flag was set
                    if ((flags & SyncFolderFlags.UploadItems) != SyncFolderFlags.UploadItems)
                    {
                        continue;
                    }

                    // copy local to remote

                    // 1. get the rel path
                    String relPath;
                    if ((item.localItem.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        relPath = item.localItem.FullName.Remove(0, srcFolder.FullName.Length);
                    }
                    else
                    {
                        relPath = Path.GetDirectoryName(item.localItem.FullName).Remove(0, srcFolder.FullName.Length);
                    }

                    // 2. convert delimit
                    relPath = relPath.Replace(Path.DirectorySeparatorChar, '/');

                    // 3. ensure the directory exists
                    ICloudDirectoryEntry realTarget;

                    if (relPath.Length == 0)
                    {
                        realTarget = tgtFolder;
                    }
                    else
                    {
                        if (relPath[0] == '/')
                        {
                            relPath = relPath.Remove(0, 1);
                        }

                        //check if subfolder exists, if it doesn't, create it
                        realTarget = GetFolder(relPath, tgtFolder) ?? CreateFolderEx(relPath, tgtFolder);
                    }

                    // 4. check target
                    if (realTarget == null)
                    {
                        bRet = false;
                        continue;
                    }

                    // 5. upload file if needed
                    if ((item.localItem.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        if (UploadFile(item.localItem.FullName, realTarget) == null)
                        {
                            bRet = false;
                        }
                    }
                    break;
                }

                case ComparisonResult.SizeDifferent:
                {
                    throw new NotImplementedException();
                }
                }
            }

            return(bRet);
        }
Ejemplo n.º 3
0
        private void CompareFilesCommand_Executed(string leftDir,
                                                  string rightDir,
                                                  DiffDirFileMode dirFileMode)
        {
            if (_cancelTokenSource.IsCancellationRequested == true)
            {
                return;
            }

            DirDiffArgs args = _Args;

            _Args.CompareDirFileMode = dirFileMode;

            // Construct deffault options if there are no others
            if (_Args == null)
            {
                args = new DirDiffArgs(leftDir, rightDir);
            }
            else
            {
                _Args.LeftDir  = leftDir;
                _Args.RightDir = rightDir;
            }

            var diff = new DirectoryDiff(args);

            try
            {
                _DiffProgress.ResetProgressValues(_cancelTokenSource.Token);

                Task.Factory.StartNew <IDiffProgress>(
                    (p) => diff.Execute(args.LeftDir, args.RightDir, _DiffProgress, _DataSource)
                    , TaskCreationOptions.LongRunning, _cancelTokenSource.Token)
                .ContinueWith((r) =>
                {
                    bool onError       = false;
                    bool taskCancelled = false;

                    if (_cancelTokenSource != null)
                    {
                        // Re-create cancellation token if this task was cancelled
                        // to support cancelable tasks in the future
                        if (_cancelTokenSource.IsCancellationRequested)
                        {
                            taskCancelled = true;
                            _cancelTokenSource.Dispose();
                            _cancelTokenSource = new CancellationTokenSource();
                        }
                    }

                    if (taskCancelled == false)
                    {
                        if (r.Result == null)
                        {
                            onError = true;
                        }
                        else
                        {
                            if (r.Result.ResultData == null)
                            {
                                onError = true;
                            }
                        }
                    }

                    if (onError == false && taskCancelled == false)
                    {
                        var diffResults = r.Result.ResultData as IDirectoryDiffRoot;
                        _DirDiffDoc.ShowDifferences(args, diffResults);
                    }
                    else
                    {
                        // Display Error
                    }
                });
            }
            catch
            {
                // Handle task based error and display error
            }
        }
Ejemplo n.º 4
0
 public _ReadOnlyList_237(DirectoryDiff _enclosing, INodeDirectory currentDir)
 {
     this._enclosing = _enclosing;
     this.currentDir = currentDir;
     this.children   = null;
 }