/// <summary>
        /// Append directory level information into the specified DataTable.
        /// </summary>
        /// <param name="qualifier">Top level directory.</param>
        /// <param name="dirs">Work in progress collection of directories.</param>
        /// <param name="estimate">Number of directory entries found. Used for future estimating.</param>
        public void DirLevel(string qualifier, string directory, ref List <string> dirs, ref long estimate)
        {
            string spec;
            string path;
            string name;

            path = directory;
            if (directory.Length > qualifier.Length)
            {
                directory = directory.Substring(qualifier.Length);
            }
            else
            {
                directory = string.Empty;
            }
            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                directoryInfo.Refresh();
                if (DirectoryExclusionsHelper.AllowDirectory(path))
                {
                    DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories();
                    for (int row = 0; row < directoryInfoArray.Length; row++)
                    {
                        try
                        {
                            name = directoryInfoArray[row].Name;
                            spec = path + Path.DirectorySeparatorChar.ToString() + name;
                            if (DirectoryExclusionsHelper.AllowDirectory(spec))
                            {
                                if (directoryInfoArray[row].Exists)
                                {
                                    dirs.Add(spec);
                                    AdvancedDirectoryEntry entry = new AdvancedDirectoryEntry();
                                    entry.StdHlq     = qualifier.Trim();
                                    entry.StdDir     = directory.Trim();
                                    entry.StdFile    = name.Trim();
                                    entry.StdSize    = 0;
                                    entry.StdDate    = System.DateTime.Parse("01/01/2000");
                                    entry.SourceDate = entry.StdDate;
                                    entry.TargetDate = entry.StdDate;
                                    entry.SourceFile = entry.StdFile;
                                    entry.TargetFile = entry.StdFile;
                                    entry.StdType    = "dir";
                                    string matchAfter = string.Empty;
                                    entry.FolderGroup = GetFolderGroup(spec, ref matchAfter);
                                    string matchSpec = GetMatchPart(spec, matchAfter);
                                    entry.FolderGroupMatchPath     = matchSpec;
                                    entry.FolderGroupMatchStem     = matchSpec;
                                    entry.FolderGroupMatchFileSpec = matchSpec;
                                    entry.FolderGroupFullPath      = spec;
                                    entry.FolderGroupFullStem      = spec;
                                    entry.FolderGroupFullFileSpec  = spec;
                                    entry.CtlComparison            = string.Empty;
                                    directoryListing.Add(entry);
                                    estimate += entry.StdSize;
                                    SignalUpdateProgress("DirList", entry.StdSize);
                                }
                            }
                        }
                        catch (OleDbException oExceptionA)
                        {
                            System.Diagnostics.Debug.WriteLine(oExceptionA.Errors[0].Message);
                        }
                        if (Interrupt.Reason == "Cancel")
                        {
                            break;
                        }
                    }
                    FileInfo[] fileInfoArray = directoryInfo.GetFiles();
                    for (int row = 0; row < fileInfoArray.Length; row++)
                    {
                        try
                        {
                            name = fileInfoArray[row].Name;
                            spec = path + Path.DirectorySeparatorChar.ToString() + name;
                            if (fileInfoArray[row].Exists)
                            {
                                string fullExt = Path.GetExtension(spec);
                                string ext     = fullExt;
                                if (ext.StartsWith("."))
                                {
                                    if (ext.Length > 1)
                                    {
                                        ext = ext.Substring(1);
                                    }
                                    else
                                    {
                                        ext = string.Empty;
                                    }
                                }
                                if (MonitoredTypesHelper.AllowFile(spec, monitoredTypesOnly))
                                {
                                    AdvancedDirectoryEntry entry = new AdvancedDirectoryEntry();
                                    entry.StdHlq     = qualifier.Trim();
                                    entry.StdDir     = directory.Trim();
                                    entry.StdFile    = name.Trim();
                                    entry.StdSize    = fileInfoArray[row].Length;
                                    entry.StdDate    = fileInfoArray[row].LastWriteTime;
                                    entry.SourceDate = entry.StdDate;
                                    entry.TargetDate = entry.StdDate;
                                    entry.SourceFile = entry.StdFile;
                                    entry.TargetFile = entry.StdFile;
                                    entry.StdType    = ext;
                                    string matchAfter = string.Empty;
                                    entry.FolderGroup          = GetFolderGroup(spec, ref matchAfter);
                                    entry.FolderGroupMatchPath = GetMatchPart(fileInfoArray[row].DirectoryName, matchAfter);
                                    string matchSpec = GetMatchPart(spec, matchAfter);
                                    string matchStem = RemoveExt(matchSpec, fullExt);
                                    entry.FolderGroupMatchStem     = matchStem;
                                    entry.FolderGroupMatchFileSpec = matchSpec;
                                    entry.FolderGroupFullPath      = fileInfoArray[row].DirectoryName;
                                    entry.FolderGroupFullStem      = RemoveExt(spec, fullExt);
                                    entry.FolderGroupFullFileSpec  = spec;
                                    entry.CtlComparison            = string.Empty;
                                    directoryListing.Add(entry);
                                    estimate += entry.StdSize;
                                    SignalUpdateProgress("DirList", entry.StdSize);
                                }
                            }
                        }
                        catch (OleDbException exceptionB)
                        {
                            System.Diagnostics.Debug.WriteLine(exceptionB.Errors[0].Message);
                        }
                        if (Interrupt.Reason == "Cancel")
                        {
                            break;
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException oExceptionNF)
            {
                System.Diagnostics.Debug.WriteLine(oExceptionNF.Message);
            }
            finally
            {
            }
        }
Exemple #2
0
        private KeyValuePair <string, string> FindMostSpecificLongestRuleMatch()
        {
            KeyValuePair <string, string> rulePair = new KeyValuePair <string, string>(SourceHlq, TargetHlq);
            int longestMatchLength = 0;
            int matchLength        = 0;

            foreach (KeyValuePair <string, string> rule in _directoryRules)
            {
                string sourceRule = rule.Key;
                string targetRule = rule.Value;
                if (CurrentPath.StartsWith(sourceRule))
                {
                    matchLength = sourceRule.Length;
                    if (matchLength > longestMatchLength)
                    {
                        longestMatchLength = matchLength;
                        rulePair           = rule;
                    }
                }
            }
            AdvancedDirectoryEntry fileMatch = null;
            AdvancedDirectoryEntry mainMatch = null;
            AdvancedDirectoryEntry aaaMatch  = null;
            AdvancedDirectoryEntry bbbMatch  = null;

            foreach (var entry in _targetSampleDirectoryListing)
            {
                var existingFileMatches = (from existingFile in _targetSampleDirectoryListing
                                           where CurrentPath.Contains(existingFile.FolderGroupMatchFileSpec) && existingFile.StdType != "dir"
                                           select existingFile).ToList();
                if (existingFileMatches.Count() > 0)
                {
                    foreach (var existingFile in existingFileMatches)
                    {
                        if (existingFile.FolderGroup == "MAIN" || existingFile.FolderGroup == "TEST")
                        {
                            mainMatch = existingFile;
                        }
                        else if (existingFile.FolderGroup == "BBB" || existingFile.FolderGroup == "BBBTEST")
                        {
                            //Ignore BBB matches.
                        }
                        else if (existingFile.FolderGroup == "AAA" || existingFile.FolderGroup == "AAATEST")
                        {
                            aaaMatch = existingFile;
                        }
                    }
                }
            }
            if (mainMatch != null)
            {
                fileMatch = mainMatch;
            }
            else if (aaaMatch != null)
            {
                fileMatch = aaaMatch;
            }
            if (fileMatch != null)
            {
                string source = CurrentPath;
                string target = fileMatch.FolderGroupFullFileSpec.Replace(TargetSampleHlq, TargetHlq);
                rulePair = new KeyValuePair <string, string>(source, target);
            }
            else
            {
                foreach (KeyValuePair <string, string> rule in _fileRules)
                {
                    string sourceRule = rule.Key;
                    string targetRule = rule.Value;
                    if (CurrentPath.StartsWith(sourceRule))
                    {
                        matchLength = sourceRule.Length;
                        if (matchLength > longestMatchLength)
                        {
                            longestMatchLength = matchLength;
                            rulePair           = rule;
                        }
                    }
                }
            }
            return(rulePair);
        }