コード例 #1
0
ファイル: Form1.cs プロジェクト: NkululekoN/Wexflow
        void ButtonStart_Click(object sender, EventArgs e)
        {
            var wfId = GetSlectedWorkflowId();

            if (wfId > -1)
            {
                _wexflowServiceClient.StartWorkflow(wfId);
            }
        }
コード例 #2
0
        private void ButtonStart_Click(object sender, EventArgs e)
        {
            var wfId = GetSlectedWorkflowId();

            if (wfId > -1)
            {
                _wexflowServiceClient.StartWorkflow(wfId, Login.Username, Login.Password);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: robertkentish/Wexflow
        void StartClick(object sender, EventArgs e)
        {
            var wfId = GetSlectedWorkflowId();

            if (wfId > -1)
            {
                var wfInstanceID = _wexflowServiceClient.StartWorkflow(wfId);
                _runningWorkflows.Add(wfId.ToString(), wfInstanceID.ToString());
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: robertkentish/Wexflow
        void buttonStart_Click(object sender, EventArgs e)
        {
            var wfId = GetSlectedWorkflowId();

            if (wfId > -1)
            {
                var wfInstanceID = _wexflowServiceClient.StartWorkflow(wfId);
                _runningWorkflows.Add($"{wfId}:{wfInstanceID}");
            }
        }
コード例 #5
0
        private void ButtonStart_Click(object sender, EventArgs e)
        {
            var wfId = GetSlectedWorkflowId();

            if (wfId > -1)
            {
                var instanceId = _wexflowServiceClient.StartWorkflow(wfId, Login.Username, Login.Password);
                if (_jobs.ContainsKey(wfId))
                {
                    _jobs[wfId] = instanceId;
                }
                else
                {
                    _jobs.Add(wfId, instanceId);
                }
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
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));
        }
コード例 #8
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));
        }
コード例 #9
0
        public static void Main(string[] args)
        {
            try
            {
                Config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                         .Build();

                int port = int.Parse(Config["WexflowServicePort"]);

                XmlDocument log4NetConfig = new XmlDocument();
                log4NetConfig.Load(File.OpenRead("log4net.config"));
                var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
                XmlConfigurator.Configure(repo, log4NetConfig["log4net"]);

                string wexflowSettingsFile = Config["WexflowSettingsFile"];
                WexflowEngine = new WexflowEngine(wexflowSettingsFile
                                                  , Config["WorkiomAuthUrl"]
                                                  , Config["CreateRecordUrl"]
                                                  , Config["UpdateRecordUrl"]
                                                  , Config["NotifyUserUrl"]);

                WexflowEngine.Run();

                var uri       = Config["CloudAmpqUrl"];
                var queueName = Config["QueueName"];
                var factory   = new ConnectionFactory()
                {
                    Uri = new Uri(uri)
                };
                //var factory = new ConnectionFactory() { HostName = "localhost" };
                //var wexflowWebServiceUri = string.Format("http://localhost:{0}/wexflow/", port);
                var wexflowWebServiceUri = Config["WexflowWebServiceUri"];
                var client   = new WexflowServiceClient(wexflowWebServiceUri);
                var username = Config["Username"];
                var password = Config["Password"];
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        channel.QueueDeclare(queue: queueName,
                                             durable: true,
                                             exclusive: false,
                                             autoDelete: false,
                                             arguments: null);

                        var consumer = new EventingBasicConsumer(channel);
                        consumer.Received += (model, ea) =>
                        {
                            try
                            {
                                var body    = ea.Body;
                                var message = Encoding.UTF8.GetString(body);
                                Logger.InfoFormat("Received: {0}", message);

                                var o          = JObject.Parse(message);
                                var workflowId = o.Value <int>("workflowId");
                                var payload    = o.Value <JObject>("payload");

                                var parameters =
                                    "[" +
                                    "{\"ParamName\":\"Payload\",\"ParamValue\":" + (payload == null ? "\"\"" : payload.ToString()) + "}" +
                                    "]";

                                var started = client.StartWorkflow(workflowId, username, password, parameters);

                                if (started)
                                {
                                    Logger.InfoFormat("Workflow {0} started.", workflowId);
                                }
                                else
                                {
                                    Logger.ErrorFormat("Workflow {0} not started. Error: Unauthorized.", workflowId);
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.Error("An error occured while consuming queue message.", e);
                            }
                        };
                        channel.BasicConsume(queue: queueName,
                                             autoAck: true,
                                             consumer: consumer);

                        var host = new WebHostBuilder()
                                   .UseContentRoot(Directory.GetCurrentDirectory())
                                   .UseKestrel((context, options) =>
                        {
                            options.ListenAnyIP(port);
                        })
                                   .UseStartup <Startup>()
                                   .Build();

                        host.Run();
                    }
            }
            catch (Exception e)
            {
                Logger.Error("An error occured while starting Wexflow server.", e);
            }

            Console.WriteLine();
            Console.Write("Press any key to stop Wexflow server...");
            Console.ReadKey();
        }