Пример #1
0
        public async Task <string> ExecuteAsync(Guid projectId, WorkItemData workItemPayload, IClientsContext clients, CancellationToken cancellationToken)
        {
            if (State == EngineState.Error)
            {
                return(string.Empty);
            }

            var workItem    = workItemPayload.WorkItem;
            var context     = new EngineContext(clients, projectId, workItem.GetTeamProject(), logger);
            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 Globals
            {
                self        = self,
                selfChanges = selfChanges,
                store       = store,
                logger      = logger
            };

            logger.WriteInfo($"Executing Rule...");
            var result = await roslynScript.RunAsync(globals, cancellationToken);

            if (result.Exception != null)
            {
                logger.WriteError($"Rule failed with {result.Exception}");
                State = EngineState.Error;
            }
            else
            {
                logger.WriteInfo($"Rule succeeded with {result.ReturnValue ?? "no return value"}");
                State = EngineState.Success;
            }

            logger.WriteVerbose($"Post-execution, save any change (mode {saveMode})...");
            var saveRes = await store.SaveChanges(saveMode, !DryRun, cancellationToken);

            if (saveRes.created + saveRes.updated > 0)
            {
                logger.WriteInfo($"Changes saved to Azure DevOps (mode {saveMode}): {saveRes.created} created, {saveRes.updated} updated.");
            }
            else
            {
                logger.WriteInfo($"No changes saved to Azure DevOps.");
            }

            return(result.ReturnValue);
        }
Пример #2
0
        protected RuleExecutionContext CreateRuleExecutionContext(Guid projectId, WorkItemData workItemPayload, IClientsContext clients)
        {
            var workItem    = workItemPayload.WorkItem;
            var context     = new EngineContext(clients, projectId, workItem.GetTeamProject(), logger);
            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
            };

            return(globals);
        }