Esempio n. 1
0
        /// <summary>
        /// Create a project instance corresponding to the vschromium project file
        /// on disk at <paramref name="rootPath"/>.
        /// Return <code>null</code> if there is no project file.
        /// </summary>
        private Project CreateProject(FullPath rootPath)
        {
            var projectFilePath = rootPath.Combine(new RelativePath(ConfigurationFileNames.ProjectFileName));
            var sectionName     = ConfigurationSectionNames.SourceExplorerIgnore;

            if (!_fileSystem.FileExists(projectFilePath))
            {
                projectFilePath = rootPath.Combine(new RelativePath(ConfigurationFileNames.ProjectFileNameObsolete));
                sectionName     = ConfigurationSectionNames.SourceExplorerIgnoreObsolete;
                if (!_fileSystem.FileExists(projectFilePath))
                {
                    return(null);
                }
            }

            var fileWithSections      = new FileWithSections(_fileSystem, projectFilePath);
            var configurationProvider = new FileWithSectionConfigurationProvider(fileWithSections);
            var s1                    = ConfigurationSectionContents.Create(configurationProvider, sectionName);
            var s2                    = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesIgnore);
            var s3                    = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesInclude);
            var fileFilter            = new FileFilter(s1);
            var directoryFilter       = new DirectoryFilter(s1);
            var searchableFilesFilter = new SearchableFilesFilter(s2, s3);

            return(new Project(rootPath, fileFilter, directoryFilter, searchableFilesFilter, fileWithSections.Hash));
        }
Esempio n. 2
0
        public DirectorySnippetExtractor(
            DirectoryFilter directoryFilter,
            FileFilter fileFilter,
            GetPackageOrderForComponent packageOrder = null,
            TranslatePackage translatePackage        = null)
        {
            Guard.AgainstNull(directoryFilter, nameof(directoryFilter));
            Guard.AgainstNull(fileFilter, nameof(fileFilter));
            fileFinder = new FileFinder(directoryFilter, fileFilter);
            if (packageOrder == null)
            {
                this.packageOrder = x => Enumerable.Empty <string>();
            }
            else
            {
                this.packageOrder = packageOrder;
            }

            if (translatePackage == null)
            {
                this.translatePackage = alias => alias;
            }
            else
            {
                this.translatePackage = translatePackage;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Form an array of Regex expressions from a comma delimited string
        /// </summary>
        /// <param name="commaDelimitedString"></param>
        /// <param name="useRegex"></param>
        /// <returns></returns>
        private static DirectoryFilter[] FormRegexListfromString(string commaDelimitedString, bool useRegex)
        {
            List <DirectoryFilter> directoryFilters = new List <DirectoryFilter>();

            // Form a Regex object for each string
            foreach (string regexString in commaDelimitedString.Split(',', ' '))
            {
                if (regexString.Length > 0)
                {
                    DirectoryFilter newFilter = new DirectoryFilter();

                    // If simple strings are being used (useRegex = false) then specify that the entire string should be matched
                    if (useRegex == true)
                    {
                        newFilter.Name = new Regex(regexString);
                    }
                    else
                    {
                        newFilter.Name = new Regex('^' + regexString + '$');
                    }

                    newFilter.FullPath     = false;
                    newFilter.TopLevelOnly = true;
                    directoryFilters.Add(newFilter);
                }
            }

            return(directoryFilters.ToArray());
        }
Esempio n. 4
0
        /// <summary>
        /// Form an array of Regex expressions from an array of strings
        /// </summary>
        /// <param name="strings"></param>
        /// <param name="useRegex"></param>
        /// <returns></returns>
        private static DirectoryFilter[] RegexListFromStringList(directoryFilter[] filters, bool useRegex)
        {
            List <DirectoryFilter> directoryFilters = new List <DirectoryFilter>();

            foreach (directoryFilter filter in filters)
            {
                DirectoryFilter newFilter = new DirectoryFilter();

                // If simple strings are being used (useRegex = false) then specify that the entire string should be matched
                if (useRegex == true)
                {
                    newFilter.Name = new Regex(filter.Value);
                }
                else
                {
                    newFilter.Name = new Regex('^' + filter.Value + '$');
                }

                newFilter.FullPath     = filter.fullPath;
                newFilter.TopLevelOnly = filter.topLevelOnly;
                directoryFilters.Add(newFilter);
            }

            return(directoryFilters.ToArray());
        }
 /// <summary>
 /// Removes all the bundles from the collection and removes support for common conventions.
 /// </summary>
 /// <remarks>
 /// In addition to calling <see cref="Clear"/> on the collection, suport for common conventions is removed by also clearing
 /// <see cref="FileExtensionReplacementList"/>, <see cref="IgnoreList"/>, <see cref="DirectoryFilter"/>, and <see cref="FileSetOrderList"/>
 /// </remarks>
 public void ResetAll()
 {
     Clear();
     FileExtensionReplacementList.Clear();
     IgnoreList.Clear();
     DirectoryFilter.Clear();
     FileSetOrderList.Clear();
 }
 private Project CreateProject(FullPath rootPath) {
   var configurationProvider = _configurationSectionProvider;
   var section1 = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SourceExplorerIgnoreObsolete);
   var section2 = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesIgnore);
   var section3 = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesInclude);
   var fileFilter = new FileFilter(section1);
   var directoryFilter = new DirectoryFilter(section1);
   var searchableFilesFilter = new SearchableFilesFilter(section2, section3);
   var hash = MD5Hash.CreateHash(section1.Contents.Concat(section2.Contents).Concat(section3.Contents));
   return new Project(rootPath, fileFilter, directoryFilter, searchableFilesFilter, hash);
 }
Esempio n. 7
0
        public DirectorySnippetReverter(DirectoryFilter directoryFilter, FileFilter fileFilter)
        {
            Guard.AgainstNull(directoryFilter, nameof(directoryFilter));
            Guard.AgainstNull(fileFilter, nameof(fileFilter));
            FileFilter withMdFileFilter = x =>
            {
                var extension = Path.GetExtension(x);
                return(string.Equals(extension, ".md", StringComparison.OrdinalIgnoreCase) && fileFilter(x));
            };

            fileFinder = new FileFinder(directoryFilter, withMdFileFilter);
        }
        private Project CreateProject(FullPath rootPath)
        {
            var configurationProvider = _configurationSectionProvider;
            var section1              = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SourceExplorerIgnoreObsolete);
            var section2              = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesIgnore);
            var section3              = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesInclude);
            var fileFilter            = new FileFilter(section1);
            var directoryFilter       = new DirectoryFilter(section1);
            var searchableFilesFilter = new SearchableFilesFilter(section2, section3);
            var hash = MD5Hash.CreateHash(section1.Contents.Concat(section2.Contents).Concat(section3.Contents));

            return(new Project(rootPath, fileFilter, directoryFilter, searchableFilesFilter, hash));
        }
Esempio n. 9
0
        private Project CreateProject(FullPath rootPath)
        {
            var configurationProvider         = _configurationSectionProvider;
            var ignorePathsSection            = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SourceExplorerIgnoreObsolete);
            var ignoreSearchableFilesSection  = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesIgnore);
            var includeSearchableFilesSection = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesInclude);
            var fileFilter            = new FileFilter(ignorePathsSection);
            var directoryFilter       = new DirectoryFilter(ignorePathsSection);
            var searchableFilesFilter = new SearchableFilesFilter(ignoreSearchableFilesSection, includeSearchableFilesSection);
            var hash = MD5Hash.CreateHash(ignorePathsSection.Contents.Concat(ignoreSearchableFilesSection.Contents).Concat(includeSearchableFilesSection.Contents));

            return(new Project(rootPath, ignorePathsSection, ignoreSearchableFilesSection, includeSearchableFilesSection, fileFilter, directoryFilter, searchableFilesFilter, hash));
        }
Esempio n. 10
0
        /// <summary>
        /// Remove documents from the existing index.
        /// </summary>
        /// <param name="directoryIndexInfo">The directory infomation where the index files are located.</param>
        /// <param name="directoryInfo">The top level relative directory information where all the files that are to be removed are located.</param>
        /// <param name="files">The array of all files that are to be removed relative to the directory info.</param>
        /// <param name="documents">The supported documents search filter, used to indicate what files are to be removed.</param>
        public void RemoveDocuments(DirectoryInfo directoryIndexInfo, DirectoryInfo directoryInfo, string[] files, SupportedDocumentExtension documents)
        {
            Lucene.Net.Index.IndexWriter writer    = null;
            Lucene.Net.Store.Directory   directory = null;

            try
            {
                if (documents != null)
                {
                    // Create the analyzer.
                    SimpleAnalyzer   simpleAnalyzer   = new Analyzer.SimpleAnalyzer();
                    StandardAnalyzer standardAnalyzer = new Analyzer.StandardAnalyzer(simpleAnalyzer);

                    // Create the index writer.
                    directory = FSDirectory.Open(directoryIndexInfo);
                    IndexWriterConfig indexConfig = new IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48, standardAnalyzer);
                    indexConfig.SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND);

                    // Open existing or create new.
                    writer = new IndexWriter(directory, indexConfig);

                    // Create the directory filter.
                    DirectoryFilter filter  = new DirectoryFilter();
                    Query[]         queries = filter.RemoveDocuments(directoryInfo, files, documents);
                    writer.DeleteDocuments(queries);

                    // Commit the index.
                    writer.Commit();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Dispose();
                }

                if (directory != null)
                {
                    directory.Dispose();
                }
            }
        }
Esempio n. 11
0
 public DirectorySnippetExtractor(DirectoryFilter directoryFilter, FileFilter fileFilter,
                                  GetPackageOrderForComponent packageOrder, TranslatePackage translatePackage = null)
 {
     Guard.AgainstNull(directoryFilter, nameof(directoryFilter));
     Guard.AgainstNull(fileFilter, nameof(fileFilter));
     this.directoryFilter = directoryFilter;
     this.fileFilter      = fileFilter;
     this.packageOrder    = packageOrder;
     if (translatePackage == null)
     {
         this.translatePackage = alias => alias;
     }
     else
     {
         this.translatePackage = translatePackage;
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Create a project instance corresponding to the vschromium project file
        /// on disk at <paramref name="rootPath"/>.
        /// Return <code>null</code> if there is no project file.
        /// </summary>
        private Project CreateProject(FullPath rootPath, FullPath searchPath)
        {
            var projectFilePath = rootPath.Combine(new RelativePath(ConfigurationFileNames.ProjectFileName));

            var ignorePathsSectionName = ConfigurationSectionNames.SourceExplorerIgnore;

            if (!_fileSystem.FileExists(projectFilePath))
            {
                projectFilePath        = rootPath.Combine(new RelativePath(ConfigurationFileNames.ProjectFileNameObsolete));
                ignorePathsSectionName = ConfigurationSectionNames.SourceExplorerIgnoreObsolete;
                if (!_fileSystem.FileExists(projectFilePath))
                {
                    return(null);
                }
            }

            var fileWithSections              = new FileWithSections(_fileSystem, projectFilePath);
            var configurationProvider         = new FileWithSectionConfigurationProvider(fileWithSections);
            var propertiesSection             = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.Properties);
            var ignorePathsSection            = ConfigurationSectionContents.Create(configurationProvider, ignorePathsSectionName);
            var ignoreSearchableFilesSection  = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesIgnore);
            var includeSearchableFilesSection = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesInclude);
            var propertyCollection            = new PropertyCollection(propertiesSection);
            var fileFilter            = new FileFilter(ignorePathsSection);
            var directoryFilter       = new DirectoryFilter(ignorePathsSection);
            var searchableFilesFilter = new SearchableFilesFilter(ignoreSearchableFilesSection, includeSearchableFilesSection);

            int      rootDepth        = 0;
            FullPath modifiedRootPath = rootPath;

            if (propertyCollection.TryGetInt("RootDepth", out rootDepth) && rootDepth > 0)
            {
                int rootPathDepth = rootPath.ToString().Split(Path.DirectorySeparatorChar).Count();
                IEnumerable <string> pathComponents = searchPath.ToString().Split(Path.DirectorySeparatorChar);
                modifiedRootPath = new FullPath(string.Join(Path.DirectorySeparatorChar.ToString(), pathComponents.Take(rootPathDepth + rootDepth)));
            }

            return(new Project(modifiedRootPath, ignorePathsSection, ignoreSearchableFilesSection, includeSearchableFilesSection, fileFilter, directoryFilter, searchableFilesFilter, fileWithSections.Hash));
        }
Esempio n. 13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="directoryFilter">Directories to include.</param>
 /// <param name="fileFilter">Files to include.</param>
 public CachedSnippetExtractor(DirectoryFilter directoryFilter, FileFilter fileFilter, GetPackageOrderForComponent packageOrder = null, TranslatePackage translatePackage = null)
 {
     Guard.AgainstNull(directoryFilter, nameof(directoryFilter));
     Guard.AgainstNull(fileFilter, nameof(fileFilter));
     extractor = new DirectorySnippetExtractor(directoryFilter, fileFilter, packageOrder, translatePackage);
 }
Esempio n. 14
0
 public FileFinder(DirectoryFilter directoryFilter = null, FileFilter fileFilter = null)
 {
     this.directoryFilter = directoryFilter;
     this.fileFilter      = fileFilter;
 }
    /// <summary>
    /// Create a project instance corresponding to the vschromium project file
    /// on disk at <paramref name="rootPath"/>.
    /// Return <code>null</code> if there is no project file.
    /// </summary>
    private Project CreateProject(FullPath rootPath) {
      var projectFilePath = rootPath.Combine(new RelativePath(ConfigurationFileNames.ProjectFileName));
      var sectionName = ConfigurationSectionNames.SourceExplorerIgnore;
      if (!_fileSystem.FileExists(projectFilePath)) {
        projectFilePath = rootPath.Combine(new RelativePath(ConfigurationFileNames.ProjectFileNameObsolete));
        sectionName = ConfigurationSectionNames.SourceExplorerIgnoreObsolete;
        if (!_fileSystem.FileExists(projectFilePath)) {
          return null;
        }
      }

      var fileWithSections = new FileWithSections(_fileSystem, projectFilePath);
      var configurationProvider = new FileWithSectionConfigurationProvider(fileWithSections);
      var s1 = ConfigurationSectionContents.Create(configurationProvider, sectionName);
      var s2 = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesIgnore);
      var s3 = ConfigurationSectionContents.Create(configurationProvider, ConfigurationSectionNames.SearchableFilesInclude);
      var fileFilter = new FileFilter(s1);
      var directoryFilter = new DirectoryFilter(s1);
      var searchableFilesFilter = new SearchableFilesFilter(s2, s3);
      return new Project(rootPath, fileFilter, directoryFilter, searchableFilesFilter, fileWithSections.Hash);
    }
Esempio n. 16
0
 public DirectorySnippetExtractor(DirectoryFilter directoryFilter = null, FileFilter fileFilter = null)
 {
     fileFinder = new FileFinder(directoryFilter, fileFilter);
 }