CmdToolConfig ReadAppConfig() { CmdToolConfig cfg = null; AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve; try { if (_configFile == null || _configLoadTime < File.GetLastWriteTime(_configFile.FilePath)) { _configFile = ConfigurationManager.OpenExeConfiguration(typeof(Config).Assembly.Location); _configLoadTime = DateTime.Now; } if (_configFile != null) { cfg = _configFile.GetSection(CONFIG_SECTION) as Config; } if (cfg != null) { cfg.MakeFullPaths(Path.GetDirectoryName(_configFile.FilePath)); } } catch (Exception ex) { _args.WriteLine("{0}: {1}", _configFile != null ? _configFile.FilePath : "configuration error", ex.ToString()); } finally { AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve; } return(cfg ?? new CmdToolConfig()); }
private void PerformMatch(List <ICodeGenerator> generators, CmdToolConfig config, out bool stop) { stop = false; foreach (FileMatch match in config.Matches) { string directory = Path.GetDirectoryName(_args.InputPath); directory = CleanPath(directory); bool ismatch = false; foreach (string file in Directory.GetFiles(directory, match.FileSpec)) { ismatch |= StringComparer.OrdinalIgnoreCase.Equals(file, _args.InputPath); } if (!ismatch) { continue; } ismatch = match.AppliesTo.Length == 0; foreach (MatchAppliesTo appliesTo in match.AppliesTo) { ismatch |= directory.StartsWith(CleanPath(appliesTo.FolderPath), StringComparison.OrdinalIgnoreCase); } if (!ismatch) { continue; } if (match.StopHere) { stop = true; } Dictionary <string, ICodeGenerator> usedExtensions = new Dictionary <string, ICodeGenerator>(StringComparer.OrdinalIgnoreCase); foreach (ICodeGenerator gen in generators) { foreach (string ext in gen.PossibleExtensions) { usedExtensions.Add(ext, gen); } } foreach (GeneratorConfig gen in match.Generators) { bool alreadyExists = false; ICodeGenerator codeGen = new OutOfProcessGenerator(gen); foreach (string ext in codeGen.PossibleExtensions) { alreadyExists |= usedExtensions.ContainsKey(ext); } if (!alreadyExists) { generators.Add(codeGen); } } } }
public ConfigurationLoader(IGeneratorArguments args) { _args = args; _generators = new List <ICodeGenerator>(); string filename = _args.PseudoPath; DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filename)); while (di != null && !di.Exists) { di = di.Parent; } if (di != null && di.Exists) { SearchConfig(_generators, di); } CmdToolConfig config = ReadAppConfig(); bool ignore; PerformMatch(_generators, config, out ignore); }