Exemple #1
0
 private void CreateConfigTree(DirectoryInfo directoryInfo, ConfigsMerger merger)
 {
     foreach (DirectoryInfo info in directoryInfo.GetDirectories())
     {
         string path = this.GetPath(info.FullName);
         this.root.FindOrCreateNode(path);
         this.CreateConfigTree(info, merger);
     }
     foreach (FileInfo info2 in directoryInfo.GetFiles())
     {
         if (this.configurationProfile.Match(info2.Name))
         {
             string         path           = this.GetPath(directoryInfo.FullName);
             ConfigTreeNode configTreeNode = this.root.FindOrCreateNode(path);
             try
             {
                 YamlNodeImpl yamlNode = YamlService.Load(info2);
                 merger.Put(configTreeNode, info2.Name, yamlNode);
             }
             catch (Exception exception1)
             {
                 throw new Exception(path, exception1);
             }
         }
     }
 }
Exemple #2
0
        private T ReadToConfigTree <T>(Stream inputStream, ConfigurationProfile configurationProfile) where T : ConfigTreeNode, new()
        {
            T             local  = Activator.CreateInstance <T>();
            ConfigsMerger merger = new ConfigsMerger();
            string        str    = null;

            try
            {
                IReader reader = ReaderFactory.Open(inputStream, Options.KeepStreamsOpen);
                while (reader.MoveToNextEntry())
                {
                    str = NormalizePath(reader.Entry.FilePath);
                    if (!string.IsNullOrEmpty(str))
                    {
                        if (reader.Entry.IsDirectory)
                        {
                            local.FindOrCreateNode(str);
                            continue;
                        }
                        if (configurationProfile.Match(Path.GetFileName(str)))
                        {
                            merger.Put(local.FindOrCreateNode(this.GetDirectoryName(str)), Path.GetFileNameWithoutExtension(str), this.LoadYaml(reader));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                LoggerProvider.GetLogger(this).Fatal("Error read configs " + str, exception);
                throw;
            }
            merger.Merge();
            return(local);
        }