示例#1
0
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (Program.DebugMode || Program.IsWexflowWindowsServiceRunning())
                {
                    try
                    {
                        _wexflowServiceClient = new WexflowServiceClient(WexflowWebServiceUri);

                        var keyword = textBoxSearch.Text.ToUpper();
                        _workflows = _wexflowServiceClient.Search(keyword);
                    }
                    catch (Exception ex)
                    {
                        _exception = ex;
                    }
                }
                else if (!Program.DebugMode && !Program.IsWexflowWindowsServiceRunning())
                {
                    _exception = new Exception();
                }
                else
                {
                    _workflows       = new WorkflowInfo[] { };
                    textBoxInfo.Text = "";
                }
            }
            catch (Exception)
            {
                ShowError();
            }
        }
示例#2
0
        /// <summary>
        /// Get a workflow by ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public WorkflowInfo Get(int id)
        {
            var client = new WexflowServiceClient(_configs.WexflowWebServiceUri);

            var workflows = client.Search(string.Empty, _configs.Username, _configs.Password);

            return(workflows.FirstOrDefault(p => p.Id == id));
        }
示例#3
0
文件: Program.cs 项目: ymf1/Wexflow
        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);
            }
        }