/// <summary> /// Parse the specified <see cref="XDocument"/> to build a <see cref="TFSAggregatorSettings"/> instance. /// </summary> /// <param name="lastWriteTime">Last teime the document has been changed.</param> /// <param name="load">A lambda returning the <see cref="XDocument"/> to parse.</param> /// <returns></returns> public static TFSAggregatorSettings Load(DateTime lastWriteTime, Func <LoadOptions, XDocument> load, ILogEvents logger) { var instance = new TFSAggregatorSettings(); LoadOptions xmlLoadOptions = LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo; XDocument doc = load(xmlLoadOptions); instance.Hash = ComputeHash(doc, lastWriteTime); if (!ValidateDocAgainstSchema(doc, logger)) { // HACK we must handle this scenario with clean exit return(null); } // XML Schema has done lot of checking and set defaults, no need to recheck later, just manage missing pieces ParseRuntimeSection(instance, doc); Dictionary <string, Rule> rules = ParseRulesSection(instance, doc); var ruleInUse = rules.Keys.ToDictionary(ruleName => ruleName, ruleName => false); List <Policy> policies = ParsePoliciesSection(doc, rules, ruleInUse); instance.Policies = policies; // checks foreach (var unusedRule in ruleInUse.Where(kv => kv.Value == false)) { logger.UnreferencedRule(unusedRule.Key); } return(instance); }
/// <summary> /// Parse the specified <see cref="XDocument"/> to build a <see cref="TFSAggregatorSettings"/> instance. /// </summary> /// <param name="lastWriteTime">Last teime the document has been changed.</param> /// <param name="load">A lambda returning the <see cref="XDocument"/> to parse.</param> /// <returns></returns> public static TFSAggregatorSettings Load(DateTime lastWriteTime, Func<LoadOptions, XDocument> load, ILogEvents logger) { var instance = new TFSAggregatorSettings(); LoadOptions xmlLoadOptions = LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo; XDocument doc = load(xmlLoadOptions); instance.Hash = ComputeHash(doc, lastWriteTime); if (!ValidateDocAgainstSchema(doc, logger)) { // HACK we must handle this scenario with clean exit return null; } // XML Schema has done lot of checking and set defaults, no need to recheck later, just manage missing pieces ParseRuntimeSection(instance, doc); Dictionary<string, Rule> rules = ParseRulesSection(instance, doc); var ruleInUse = rules.Keys.ToDictionary(ruleName => ruleName, ruleName => false); List<Policy> policies = ParsePoliciesSection(doc, rules, ruleInUse); instance.Policies = policies; // checks foreach (var unusedRule in ruleInUse.Where(kv => kv.Value == false)) { logger.UnreferencedRule(unusedRule.Key); } return instance; }