Esempio n. 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="directory">The directory.</param>
        public ConfigurationDirectory(DirectoryInfo directory)
        {
            Directory = directory;

            if (!Directory.Exists)
            {
                throw new DirectoryNotFoundException(directory.FullName);
            }

            List <ConfigurationFile> files = new List <ConfigurationFile>();

            foreach (FileInfo file in Directory.GetFiles("*.yml"))
            {
                if (ConfigurationFile.TryLoadFromFile(file, out ConfigurationFile configuration))
                {
                    files.Add(configuration);
                }
            }

            Files = files.AsReadOnly();

            Core_Extension = Files.FirstOrDefault(f =>
                                                  string.Equals(f.Name, CoreExtensionFileName, StringComparison.Ordinal));
        }
Esempio n. 2
0
        /// <summary>
        /// Loads and returns all Drupal configuration files from the calling directory (<paramref name="directory"/>).
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="nodeValid">Predicate function for determining which configuration nodes will be included in the
        /// loaded files (if <paramref name="nodeValid"/> returns <c>true</c>), and which will be ignored. Note that this
        /// function will be used <strong>only for root config nodes</strong> in all the files.</param>
        /// <param name="recursively">Determines if subdirectories of <paramref name="directory"/> should also be searched
        /// for config files or not.</param>
        /// <returns>Enumeration of <see cref="ConfigurationFile"/> instances, each representing one Drupal configuration
        /// file from <paramref name="directory"/>.</returns>
        internal static IEnumerable <ConfigurationFile> GetConfigurationFiles([NotNull] this DirectoryInfo directory,
                                                                              Predicate <IConfigNode> nodeValid = null, bool recursively = true)
        {
            IEnumerable <ConfigurationFile> localFiles = directory.GetFiles("*.yml").Select(f =>
                                                                                            ConfigurationFile.TryLoadFromFile(f, out ConfigurationFile configFile, nodeValid)
                    ? configFile
                    : null).Where(cf => cf != null);

            if (recursively)
            {
                localFiles = localFiles.Union(directory.GetDirectories()
                                              .Where(d => !ForbiddenDirectories.Contains(d.Name))
                                              // ReSharper disable once RedundantArgumentDefaultValue
                                              .SelectMany(d => GetConfigurationFiles(d, nodeValid, true)));
            }

            return(localFiles);
        }