/// <summary> /// Parse the specified <see cref="XDocument"/> to build a <see cref="TFSAggregatorSettings"/> instance. /// </summary> /// <param name="lastWriteTime">Last time the document has been changed.</param> /// <param name="load">A lambda returning the <see cref="XDocument"/> to parse.</param> /// <returns>An instance of <see cref="TFSAggregatorSettings"/> or null</returns> public TFSAggregatorSettings Parse(DateTime lastWriteTime, Func <LoadOptions, XDocument> load) { this.instance = new TFSAggregatorSettings(); LoadOptions xmlLoadOptions = LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo; XDocument doc = load(xmlLoadOptions); this.instance.Hash = this.ComputeHash(doc, lastWriteTime); if (!this.ValidateDocAgainstSchema(doc)) { return(null); } // XML Schema has done lot of checking and set defaults, no need to recheck later, just manage missing pieces this.ParseRuntimeSection(doc); this.instance.Snippets = this.ParseSnippetsSection(doc); this.instance.Functions = this.ParseFunctionsSection(doc); Dictionary <string, Rule> rules = this.ParseRulesSection(doc); List <Policy> policies = this.ParsePoliciesSection(doc, rules); this.instance.Policies = policies; this.ValidateSemantic(rules); return(this.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; }
/// <summary> /// Parse the specified <see cref="XDocument"/> to build a <see cref="TFSAggregatorSettings"/> instance. /// </summary> /// <param name="lastWriteTime">Last time the document has been changed.</param> /// <param name="load">A lambda returning the <see cref="XDocument"/> to parse.</param> /// <returns>An instance of <see cref="TFSAggregatorSettings"/> or null</returns> public TFSAggregatorSettings Parse(DateTime lastWriteTime, Func<LoadOptions, XDocument> load) { this.instance = new TFSAggregatorSettings(); LoadOptions xmlLoadOptions = LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo; XDocument doc = load(xmlLoadOptions); this.instance.Hash = this.ComputeHash(doc, lastWriteTime); if (!this.ValidateDocAgainstSchema(doc)) { return null; } // XML Schema has done lot of checking and set defaults, no need to recheck later, just manage missing pieces this.ParseRuntimeSection(doc); Dictionary<string, Rule> rules = this.ParseRulesSection(doc); List<Policy> policies = this.ParsePoliciesSection(doc, rules); this.instance.Policies = policies; this.ValidateSemantic(rules); return this.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); }
private static void ParseRuntimeSection(TFSAggregatorSettings instance, XDocument doc) { var loggingNode = doc.Root.Element("runtime") != null? doc.Root.Element("runtime").Element("logging") : null; instance.LogLevel = loggingNode != null ? (LogLevel)Enum.Parse(typeof(LogLevel), loggingNode.Attribute("level").Value) : LogLevel.Normal; var runtimeNode = doc.Root.Element("runtime") ?? null; var debugvalue = runtimeNode?.Attribute("debug")?.Value; instance.Debug = debugvalue != null? bool.Parse(debugvalue) : false; var authenticationNode = doc.Root.Element("runtime") != null? doc.Root.Element("runtime").Element("authentication") : null; instance.AutoImpersonate = authenticationNode != null && bool.Parse(authenticationNode.Attribute("autoImpersonate").Value); var scriptNode = doc.Root.Element("runtime") != null? doc.Root.Element("runtime").Element("script") : null; instance.ScriptLanguage = scriptNode?.Attribute("language").Value ?? "C#"; }
/// <summary> /// Initializes a new instance of the <see cref="EventProcessor"/> class. /// </summary> public EventProcessor(IWorkItemRepository workItemStore, IRuntimeContext runtime) { this.logger = runtime.Logger; this.store = workItemStore; this.settings = runtime.Settings; this.engine = runtime.GetEngine(workItemStore); }
/// <summary> /// Initializes a new instance of the <see cref="EventProcessor"/> class. /// </summary> public EventProcessor(IRuntimeContext runtime) { this.logger = runtime.Logger; this.settings = runtime.Settings; this.limiter = runtime.RateLimiter; this.store = runtime.GetWorkItemRepository(); this.engine = runtime.GetEngine(); }
public static RuntimeContext MakeRuntimeContext( string settingsPath, TFSAggregatorSettings settings, IRequestContext requestContext, ILogEvents logger, Func<Uri, Microsoft.TeamFoundation.Framework.Client.IdentityDescriptor, ILogEvents, IWorkItemRepository> repoBuilder) { var runtime = new RuntimeContext(); runtime.Logger = logger; runtime.RequestContext = requestContext; runtime.SettingsPath = settingsPath; runtime.Settings = settings; runtime.RateLimiter = new RateLimiter(runtime); logger.MinimumLogLevel = runtime.Settings?.LogLevel ?? LogLevel.Normal; runtime.repoBuilder = repoBuilder; runtime.HasErrors = settings == null; return runtime; }
private static Dictionary <string, Rule> ParseRulesSection(TFSAggregatorSettings instance, XDocument doc) { var rules = new Dictionary <string, Rule>(); foreach (var ruleElem in doc.Root.Elements("rule")) { var rule = new Rule() { Name = ruleElem.Attribute("name").Value, }; var ruleScopes = new List <RuleScope>(); if (ruleElem.Attribute("appliesTo") != null) { ruleScopes.Add(new WorkItemTypeScope() { ApplicableTypes = ruleElem.Attribute("appliesTo").Value.Split(ListSeparators) }); } if (ruleElem.Attribute("hasFields") != null) { ruleScopes.Add(new HasFieldsScope() { FieldNames = ruleElem.Attribute("hasFields").Value.Split(ListSeparators) }); } rule.Scope = ruleScopes.ToArray(); rule.Script = ruleElem.Value; rules.Add(rule.Name, rule); } instance.Rules = rules.Values.ToList(); return(rules); }
public static RuntimeContext MakeRuntimeContext(string settingsPath, TFSAggregatorSettings settings, IRequestContext requestContext, ILogEvents logger) { var runtime = new RuntimeContext(); runtime.Logger = logger; runtime.RequestContext = requestContext; runtime.SettingsPath = settingsPath; runtime.Settings = settings; logger.MinimumLogLevel = runtime.Settings.LogLevel; runtime.HasErrors = false; return runtime; }
private static void ParseRuntimeSection(TFSAggregatorSettings instance, XDocument doc) { var loggingNode = doc.Root.Element("runtime") != null ? doc.Root.Element("runtime").Element("logging") : null; instance.LogLevel = loggingNode != null ? (LogLevel)Enum.Parse(typeof(LogLevel), loggingNode.Attribute("level").Value) : LogLevel.Normal; var runtimeNode = doc.Root.Element("runtime") ?? null; var debugvalue = runtimeNode?.Attribute("debug")?.Value; instance.Debug = debugvalue != null ? bool.Parse(debugvalue) : false; var authenticationNode = doc.Root.Element("runtime") != null ? doc.Root.Element("runtime").Element("authentication") : null; instance.AutoImpersonate = authenticationNode != null && bool.Parse(authenticationNode.Attribute("autoImpersonate").Value); var scriptNode = doc.Root.Element("runtime") != null ? doc.Root.Element("runtime").Element("script") : null; instance.ScriptLanguage = scriptNode?.Attribute("language").Value ?? "C#"; }
private static Dictionary<string, Rule> ParseRulesSection(TFSAggregatorSettings instance, XDocument doc) { var rules = new Dictionary<string, Rule>(); foreach (var ruleElem in doc.Root.Elements("rule")) { var rule = new Rule() { Name = ruleElem.Attribute("name").Value, }; var ruleScopes = new List<RuleScope>(); if (ruleElem.Attribute("appliesTo") != null) { ruleScopes.Add(new WorkItemTypeScope() { ApplicableTypes = ruleElem.Attribute("appliesTo").Value.Split(ListSeparators) }); } if (ruleElem.Attribute("hasFields") != null) { ruleScopes.Add(new HasFieldsScope() { FieldNames = ruleElem.Attribute("hasFields").Value.Split(ListSeparators) }); } rule.Scope = ruleScopes.ToArray(); rule.Script = ruleElem.Value; rules.Add(rule.Name, rule); } instance.Rules = rules.Values.ToList(); return rules; }