Exemplo n.º 1
0
        /// <summary>
        /// Get Sub Folders in the Paths for Recursion
        /// </summary>
        /// <param name="sourcePath">Source Path</param>
        /// <param name="targetPath">Target Path</param>
        /// <param name="diffResult">Diff Result for Catching Exception</param>
        /// <param name="result">Result Album</param>
        /// <param name="recursive">Recurive Stack</param>
        private void getSubFoldersForRecursion(string sourcePath, string targetPath, DiffResult diffResult, Album result, Stack<DiffStackContent> recursive)
        {
            try
            {
                List<string> sourceFolders = getSubFoldersFromPath(sourcePath);
                List<string> targetFolders = getSubFoldersFromPath(targetPath);

                // Check ALL Folders: Recursively Check ALL Files Inside
                foreach (string sourceFolder in sourceFolders)
                {
                    string targetFolder = Album.combinePath(targetPath, getNameFromPath(sourceFolder));

                    // If Target Folder Exist: Recursively Check
                    if (targetFolders.Exists(delegate(string tempPath) { return tempPath.ToUpper() == targetFolder.ToUpper(); }))
                    {
                        // Recursion by pushing the folder into stack
                        DiffStackContent temp = new DiffStackContent();
                        temp.source = sourceFolder;
                        temp.target = targetFolder;

                        recursive.Push(temp);
                        //result = append(result, compare(sourceFolder, targetFolder));
                    }
                    // If Target Folder Doesn't Exist: Add Directly
                    else
                    {
                        result.add(new Album(getNameFromPath(sourceFolder), sourceFolder));
                    }
                }
            }
            catch (UnauthorizedAccessException uae)
            {
                // Record:
                diffResult.uaeThrown();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Public compare function:
        /// Compare the source path with the target path and return only the files in source folder
        /// that are different from files in the target folder.
        /// </summary>
        /// <param name="sourcePath">Path of source folder.</param>
        /// <param name="targetPath">Path of target folder.</param>
        /// <returns>Album containing the files/folders in source folder that are different.</returns>
        public DiffResult compare(string sourcePath, string targetPath)
        {
            #region Pre Conditions
            Debug.Assert(sourcePath != null, "Source Path cannot be null");
            Debug.Assert(targetPath != null, "Target Path cannot be null");
            #endregion

            // Create the Result Album
            DiffResult diffResult = new DiffResult();
            Album result = new Album(DIFF_ALBUM_NAME, string.Empty);

            // Initiate the Stack for Recursion
            Stack<DiffStackContent> recursive = new Stack<DiffStackContent>();
            DiffStackContent stackContent     = new DiffStackContent(sourcePath, targetPath);
            recursive.Push(stackContent);

            do  /* Do-While Loop for Performance */
            {
                // Get the sourcePath and targetPath: POP from Stack
                stackContent = recursive.Pop();
                sourcePath = stackContent.source;
                targetPath = stackContent.target;

                // Compare Files
                diffCompareFiles(sourcePath, targetPath, diffResult, result);
                // Get Sub Folders for Recursion
                getSubFoldersForRecursion(sourcePath, targetPath, diffResult, result, recursive);

            } while (recursive.Count != 0);

            // Return Result
            diffResult.setResult(result);

            #region Post Conditions
            Debug.Assert(diffResult != null, "Diff Result Cannot be null");
            #endregion

            return diffResult;
        }