private void Initialize(IPreprocessedRule preprocessedRule) { RuleDirectives = preprocessedRule; ImpersonateExecution = RuleDirectives.Impersonate; Settings = preprocessedRule.Settings; var references = new HashSet <Assembly>(DefaultAssemblyReferences().Concat(RuleDirectives.LoadAssemblyReferences())); var imports = new HashSet <string>(DefaultImports().Concat(RuleDirectives.Imports)); var scriptOptions = ScriptOptions.Default .WithEmitDebugInformation(true) .WithReferences(references) // Add namespaces .WithImports(imports); if (RuleDirectives.IsCSharp()) { _roslynScript = CSharpScript.Create <string>( code: RuleDirectives.GetRuleCode(), options: scriptOptions, globalsType: typeof(RuleExecutionContext)); } else { _logger.WriteError($"Cannot execute rule: language is not supported."); } }
public EngineContext(IClientsContext clients, Guid projectId, string projectName, IAggregatorLogger logger, IRuleSettings ruleSettings) { Clients = clients; Logger = logger; Tracker = new Tracker(); ProjectId = projectId; ProjectName = projectName; RuleSettings = ruleSettings; }
protected RuleExecutionContext CreateRuleExecutionContext(Guid projectId, WorkItemData workItemPayload, string eventType, IClientsContext clients, IRuleSettings ruleSettings) { var workItem = workItemPayload.WorkItem; var context = new EngineContext(clients, projectId, workItem.GetTeamProject(), logger, ruleSettings); var store = new WorkItemStore(context, workItem); var self = store.GetWorkItem(workItem.Id.Value); var selfChanges = new WorkItemUpdateWrapper(workItemPayload.WorkItemUpdate); logger.WriteInfo($"Initial WorkItem {self.Id} retrieved from {clients.WitClient.BaseAddress}"); var globals = new RuleExecutionContext { self = self, selfChanges = selfChanges, store = store, logger = logger, eventType = eventType }; return(globals); }