fork(1) download
  1. <#@ template language="C#" hostspecific="True" debug="True" #>
  2. <#@ output extension=".cs"#>
  3. <#@ assembly name="System.Core" #>
  4. <#@ assembly name="System.Xml" #>
  5. <#@ assembly name="System.Xml.Linq" #>
  6. <#@ import namespace="System.Collections.Generic" #>
  7. <#@ import namespace="System.Linq" #>
  8. <#@ import namespace="System.Xml.Linq" #>
  9. <#@ import namespace="System.Xml.XPath" #>
  10.  
  11. <#@ output extension="txt" #>
  12. using System.Collections.Generic;
  13.  
  14. <#
  15.  
  16. string targetNamespace="ProjectNamespace";
  17. var dcmKeys=ReadKeys("DynamicCM.config","//add[@key]");
  18. var webKeys=ReadKeys("..\\web.config","//appSettings/add[@key]");
  19.  
  20. if(string.IsNullOrEmpty( targetNamespace)==false){
  21. #>
  22. namespace <#=targetNamespace#> {
  23. <# }
  24. #>
  25.  
  26. public static class Config {
  27.  
  28. <#
  29. foreach (string key in dcmKeys.Concat(webKeys)){ // did not do another distinct. We would rather spot the conflicting names
  30. #>
  31. public const string <#= RemoveAll(key,new[]{".","-",":"}) #> = "<#=key#>";
  32. <# }#>
  33. public readonly static IEnumerable<string> AllKeys = new []{
  34. <#
  35. foreach (string key in dcmKeys.Concat(webKeys)){
  36. #> "<#= key #>",
  37. <# }#>
  38. };
  39. }<# if(string.IsNullOrEmpty( targetNamespace)==false) WriteLine("}");#>
  40.  
  41.  
  42. <#+ IEnumerable<string> ReadKeys(string basePath,string xPath)
  43. {
  44. var hostPath=Host.ResolvePath(basePath);
  45. WriteLine("//"+hostPath);
  46. var config=System.IO.File.ReadAllText(hostPath);
  47. var x= System.Xml.Linq.XDocument.Parse(config);
  48. return x.Root.XPathSelectElements(xPath)
  49. .Select(n=>n.Attribute(XNamespace.None+ "key").Value)
  50. .Distinct().ToArray();
  51. }
  52. #>
  53. <#+ string RemoveAll(string text, IEnumerable<string> removals)
  54. {
  55. if(string.IsNullOrEmpty(text))
  56. return text;
  57. if(removals.Any()==false)
  58. return text;
  59. return RemoveAll(text.Replace(removals.First(),string.Empty),removals.Skip(1));
  60. }#>
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty