Beispiel #1
0
        private void ButtonApprove_Click(object sender, EventArgs e)
        {
            var wfId = GetSlectedWorkflowId();

            if (wfId > -1)
            {
                _wexflowServiceClient.ApproveWorkflow(wfId, Login.Username, Login.Password);
                UpdateButtons(wfId, true);
            }
        }
Beispiel #2
0
        private void ButtonApprove_Click(object sender, EventArgs e)
        {
            var wfId = GetSlectedWorkflowId();

            if (wfId > -1)
            {
                if (_jobs.ContainsKey(wfId))
                {
                    _wexflowServiceClient.ApproveWorkflow(wfId, _jobs[wfId], Login.Username, Login.Password);
                    UpdateButtons(wfId, true);
                }
                else
                {
                    MessageBox.Show("Job id not found.");
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            try
            {
                IConfiguration config = new ConfigurationBuilder()
                                        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                        .Build();

                var parser = new Parser(cfg => cfg.CaseInsensitiveEnumValues = true);
                var res    = parser.ParseArguments <Options>(args)
                             .WithParsed(o =>
                {
                    var client   = new WexflowServiceClient(config["WexflowWebServiceUri"]);
                    var username = config["Username"];
                    var password = config["Password"];

                    var workflows = client.Search(string.Empty, username, password);
                    if (!workflows.Any(w => w.Id == o.WorkflowId))
                    {
                        Console.WriteLine("Workflow id {0} is incorrect.", o.WorkflowId);
                        return;
                    }

                    WorkflowInfo workflow;
                    switch (o.Operation)
                    {
                    case Operation.Start:
                        var instanceId = client.StartWorkflow(o.WorkflowId, username, password);
                        Console.WriteLine("JobId: {0}", instanceId);

                        if (o.Wait)
                        {
                            Thread.Sleep(1000);
                            workflow      = client.GetWorkflow(username, password, o.WorkflowId);
                            var isRunning = workflow.IsRunning;
                            while (isRunning)
                            {
                                Thread.Sleep(100);
                                workflow  = client.GetWorkflow(username, password, o.WorkflowId);
                                isRunning = workflow.IsRunning;
                            }
                        }
                        break;

                    case Operation.Suspend:
                        workflow = client.GetWorkflow(username, password, o.WorkflowId);
                        if (!workflow.IsRunning)
                        {
                            Console.WriteLine("Workflow {0} is not running to be suspended.", o.WorkflowId);
                            return;
                        }
                        client.SuspendWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
                        break;

                    case Operation.Stop:
                        workflow = client.GetWorkflow(username, password, o.WorkflowId);
                        if (!workflow.IsRunning)
                        {
                            Console.WriteLine("Workflow {0} is not running to be stopped.", o.WorkflowId);
                            return;
                        }
                        client.StopWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
                        break;

                    case Operation.Resume:
                        workflow = client.GetWorkflow(username, password, o.WorkflowId);
                        if (!workflow.IsPaused)
                        {
                            Console.WriteLine("Workflow {0} is not suspended to be resumed.", o.WorkflowId);
                            return;
                        }
                        client.ResumeWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
                        break;

                    case Operation.Approve:
                        workflow = client.GetWorkflow(username, password, o.WorkflowId);
                        if (!workflow.IsWaitingForApproval)
                        {
                            Console.WriteLine("Workflow {0} is not waiting for approval to be approved.", o.WorkflowId);
                            return;
                        }
                        client.ApproveWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
                        break;

                    case Operation.Reject:
                        workflow = client.GetWorkflow(username, password, o.WorkflowId);
                        if (!workflow.IsWaitingForApproval)
                        {
                            Console.WriteLine("Workflow {0} is not waiting for approval to be rejected.", o.WorkflowId);
                            return;
                        }
                        client.RejectWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
                        break;
                    }
                });

                res.WithNotParsed(errs =>
                {
                    var helpText = HelpText.AutoBuild(res, h => h, e =>
                    {
                        return(e);
                    });
                    Console.WriteLine(helpText);
                });
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: {0}", e);
            }
        }
Beispiel #4
0
        public override TaskStatus Run()
        {
            Info("Task started.");
            bool success           = true;
            bool atLeastOneSucceed = false;

            foreach (var id in WorkflowIds)
            {
                WexflowServiceClient client = new WexflowServiceClient(WexflowWebServiceUri);
                WorkflowInfo         wfInfo = client.GetWorkflow(id);
                switch (Action)
                {
                case WorkflowAction.Start:
                    if (wfInfo.IsRunning)
                    {
                        success = false;
                        ErrorFormat("Can't start the workflow {0} because it's already running.", Workflow.Id);
                    }
                    else
                    {
                        client.StartWorkflow(id, Username, Password);
                        InfoFormat("Workflow {0} started.", id);
                        if (!atLeastOneSucceed)
                        {
                            atLeastOneSucceed = true;
                        }
                    }
                    break;

                case WorkflowAction.Suspend:
                    if (wfInfo.IsRunning)
                    {
                        client.SuspendWorkflow(id, Username, Password);
                        InfoFormat("Workflow {0} suspended.", id);
                        if (!atLeastOneSucceed)
                        {
                            atLeastOneSucceed = true;
                        }
                    }
                    else
                    {
                        success = false;
                        ErrorFormat("Can't suspend the workflow {0} because it's not running.", Workflow.Id);
                    }
                    break;

                case WorkflowAction.Resume:
                    if (wfInfo.IsPaused)
                    {
                        client.ResumeWorkflow(id, Username, Password);
                        InfoFormat("Workflow {0} resumed.", id);
                        if (!atLeastOneSucceed)
                        {
                            atLeastOneSucceed = true;
                        }
                    }
                    else
                    {
                        success = false;
                        ErrorFormat("Can't resume the workflow {0} because it's not suspended.", Workflow.Id);
                    }
                    break;

                case WorkflowAction.Stop:
                    if (wfInfo.IsRunning)
                    {
                        client.StopWorkflow(id, Username, Password);
                        InfoFormat("Workflow {0} stopped.", id);
                        if (!atLeastOneSucceed)
                        {
                            atLeastOneSucceed = true;
                        }
                    }
                    else
                    {
                        success = false;
                        ErrorFormat("Can't stop the workflow {0} because it's not running.", Workflow.Id);
                    }
                    break;

                case WorkflowAction.Approve:
                    if (wfInfo.IsApproval && wfInfo.IsWaitingForApproval)
                    {
                        client.ApproveWorkflow(id, Username, Password);
                        InfoFormat("Workflow {0} approved.", id);
                        if (!atLeastOneSucceed)
                        {
                            atLeastOneSucceed = true;
                        }
                    }
                    else
                    {
                        success = false;
                        ErrorFormat("Can't approve the workflow {0} because it's not waiting for approval.", Workflow.Id);
                    }
                    break;

                case WorkflowAction.Disapprove:
                    if (wfInfo.IsApproval && wfInfo.IsWaitingForApproval)
                    {
                        client.DisapproveWorkflow(id, Username, Password);
                        InfoFormat("Workflow {0} disapproved.", id);
                        if (!atLeastOneSucceed)
                        {
                            atLeastOneSucceed = true;
                        }
                    }
                    else
                    {
                        success = false;
                        ErrorFormat("Can't disapprove the workflow {0} because it's not waiting for approval.", Workflow.Id);
                    }
                    break;
                }
            }
            Info("Task finished.");
            var status = Core.Status.Success;

            if (!success && atLeastOneSucceed)
            {
                status = Core.Status.Warning;
            }
            else if (!success)
            {
                status = Core.Status.Error;
            }

            return(new TaskStatus(status));
        }
Beispiel #5
0
        public override TaskStatus Run()
        {
            Info("Task started.");
            bool success           = true;
            bool atLeastOneSucceed = false;

            foreach (var id in WorkflowIds)
            {
                try
                {
                    WexflowServiceClient client = new WexflowServiceClient(WexflowWebServiceUri);
                    WorkflowInfo         wfInfo = client.GetWorkflow(Username, Password, id);
                    switch (Action)
                    {
                    case WorkflowAction.Start:
                        if (wfInfo.IsRunning)
                        {
                            success = false;
                            ErrorFormat("Can't start the workflow {0} because it's already running.", id);
                        }
                        else
                        {
                            var instanceId = client.StartWorkflow(id, Username, Password);
                            if (Jobs.ContainsKey(id))
                            {
                                Jobs[id] = instanceId;
                            }
                            else
                            {
                                Jobs.Add(id, instanceId);
                            }
                            InfoFormat("Workflow {0} started.", id);
                            if (!atLeastOneSucceed)
                            {
                                atLeastOneSucceed = true;
                            }
                        }
                        break;

                    case WorkflowAction.Suspend:
                        if (wfInfo.IsRunning)
                        {
                            var jobId = Workflow.WexflowEngine.GetWorkflow(id).Jobs.Select(j => j.Key).FirstOrDefault();
                            if (jobId != null)
                            {
                                client.SuspendWorkflow(id, jobId, Username, Password);
                                InfoFormat("Workflow {0} suspended.", id);
                                if (!atLeastOneSucceed)
                                {
                                    atLeastOneSucceed = true;
                                }
                            }
                            else
                            {
                                success = false;
                                ErrorFormat("Can't suspend the workflow {0} because it's not running.", id);
                            }
                        }
                        else
                        {
                            success = false;
                            ErrorFormat("Can't suspend the workflow {0} because it's not running.", id);
                        }
                        break;

                    case WorkflowAction.Resume:
                        if (wfInfo.IsPaused)
                        {
                            var jobId = Workflow.WexflowEngine.GetWorkflow(id).Jobs.Select(j => j.Key).FirstOrDefault();
                            if (jobId != null)
                            {
                                client.ResumeWorkflow(id, jobId, Username, Password);
                                InfoFormat("Workflow {0} resumed.", id);
                                if (!atLeastOneSucceed)
                                {
                                    atLeastOneSucceed = true;
                                }
                            }
                            else
                            {
                                success = false;
                                ErrorFormat("Can't resume the workflow {0} because it's not suspended.", id);
                            }
                        }
                        else
                        {
                            success = false;
                            ErrorFormat("Can't resume the workflow {0} because it's not suspended.", id);
                        }
                        break;

                    case WorkflowAction.Stop:
                        if (wfInfo.IsRunning)
                        {
                            var jobId = Workflow.WexflowEngine.GetWorkflow(id).Jobs.Select(j => j.Key).FirstOrDefault();
                            if (jobId != null)
                            {
                                client.StopWorkflow(id, jobId, Username, Password);
                                InfoFormat("Workflow {0} stopped.", id);
                                if (!atLeastOneSucceed)
                                {
                                    atLeastOneSucceed = true;
                                }
                            }
                            else
                            {
                                success = false;
                                ErrorFormat("Can't stop the workflow {0} because it's not running.", id);
                            }
                        }
                        else
                        {
                            success = false;
                            ErrorFormat("Can't stop the workflow {0} because it's not running.", id);
                        }
                        break;

                    case WorkflowAction.Approve:
                        if (wfInfo.IsApproval && wfInfo.IsWaitingForApproval)
                        {
                            var jobId = Workflow.WexflowEngine.GetWorkflow(id).Jobs.Select(j => j.Key).FirstOrDefault();
                            if (jobId != null)
                            {
                                client.ApproveWorkflow(id, jobId, Username, Password);
                                InfoFormat("Workflow {0} approved.", id);
                                if (!atLeastOneSucceed)
                                {
                                    atLeastOneSucceed = true;
                                }
                            }
                            else
                            {
                                success = false;
                                ErrorFormat("Can't approve the workflow {0} because it's not waiting for approval.", id);
                            }
                        }
                        else
                        {
                            success = false;
                            ErrorFormat("Can't approve the workflow {0} because it's not waiting for approval.", id);
                        }
                        break;

                    case WorkflowAction.Reject:
                        if (wfInfo.IsApproval && wfInfo.IsWaitingForApproval)
                        {
                            var jobId = Workflow.WexflowEngine.GetWorkflow(id).Jobs.Select(j => j.Key).FirstOrDefault();
                            if (jobId != null)
                            {
                                client.RejectWorkflow(id, jobId, Username, Password);
                                InfoFormat("Workflow {0} rejected.", id);
                                if (!atLeastOneSucceed)
                                {
                                    atLeastOneSucceed = true;
                                }
                            }
                            else
                            {
                                success = false;
                                ErrorFormat("Can't reject the workflow {0} because it's not waiting for approval.", id);
                            }
                        }
                        else
                        {
                            success = false;
                            ErrorFormat("Can't reject the workflow {0} because it's not waiting for approval.", id);
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    success = false;
                    ErrorFormat("An error occured while processing the workflow {0}", e, id);
                }
            }
            Info("Task finished.");
            var status = Core.Status.Success;

            if (!success && atLeastOneSucceed)
            {
                status = Core.Status.Warning;
            }
            else if (!success)
            {
                status = Core.Status.Error;
            }

            return(new TaskStatus(status));
        }