Esempio n. 1
0
        static void Main(string[] args)
        {
            CamundaEngineClient camunda = new CamundaEngineClient(new System.Uri("http://localhost:8080/engine-rest/engine/default/"), null, null);

            camunda.Startup();
            //string processInstanceId = camunda.BpmnWorkflowService.StartProcessInstance("calculate", new Dictionary<string, object>()
            //{
            //    {"x", 25 },
            //    {"y", 20 }
            //},new Dictionary<string, Action<IDictionary<string, object>>> {
            //    {"calculate",
            //        (x) => {
            //            Console.WriteLine("Tan dep trai");
            //        }
            //    }
            //});

            //System.Threading.Thread.Sleep(20000);

            var processInstanceId1 = camunda.BpmnWorkflowService.StartProcessInstanceAsync("calculate", new Dictionary <string, object>()
            {
                { "x", 25 },
                { "y", 30 }
            }, "calculate").Result;

            var processInstanceId2 = camunda.BpmnWorkflowService.StartProcessInstanceAsync("calculate", new Dictionary <string, object>()
            {
                { "x", 35 },
                { "y", 30 }
            }, "calculate").Result;
            var a = 1;

            Console.ReadLine();
            camunda.Shutdown();
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            var auth = new HubConnectionBuilder()
                       .WithUrl("http://localhost:5051/authenticationhub")
                       .Build();

            auth.StartAsync();
            var s = auth.InvokeAsync <User>("Authenticate", "serviceaccount", "test").Result;

            connection = new HubConnectionBuilder()
                         .WithUrl("http://localhost:5051/eventhub", options => {
                options.AccessTokenProvider = () => Task.FromResult(s.Token);
            })
                         .Build();

            connection.StartAsync().GetAwaiter();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(logo + "\n\n" + "Starting redis client.\n\n");

            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");

            Db = redis.GetDatabase();

            Console.WriteLine("Deploying models and start External Task Workers.\n\nPRESS Ctrl-C TO STOP WORKERS.\n\n");

            CamundaEngineClient camunda = new CamundaEngineClient();

            camunda.Startup(); // Deploys all models to Camunda and Start all found ExternalTask-Workers
            Console.CancelKeyPress += new ConsoleCancelEventHandler(OnExit);
            _closing.WaitOne();
            camunda.Shutdown(); // Stop Task Workers
            connection.DisposeAsync();
        }
        private static void Main(string[] args)
        {
            Console.WriteLine(logo + "\n\n" + "Deploying models and start workers.\n\nPRESS ANY KEY TO STOP WORKERS.\n\n");

            camunda = new CamundaEngineClient(
                new System.Uri("http://localhost:8080/engine-rest/engine/default/"), "demo", "demo");

            // Alternative way of doing it: Search assembly and automatically deploy all models to Camunda and start all found workers
            // camunda.Startup();

            DeployModel();
            RegisterWorker();

            // start some instances:
            for (int i = 0; i < 1; i++)
            {
                string processInstanceId = camunda.BpmnWorkflowService.StartProcessInstance("FlowingTripBookingSaga", new Dictionary <string, object>()
                {
                    { "someBookingData", "..." }
                });
                Console.WriteLine("Started trip booking saga " + processInstanceId);
            }

            Console.ReadLine(); // wait for ANY KEY
            camunda.Shutdown(); // Stop Task Workers
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            CamundaEngineClient camunda = new CamundaEngineClient();

            camunda.Startup();  // Deploys all models and Start all found ExternalTask-Workers​
            Console.ReadLine(); // wait for ANY KEY​
            camunda.Shutdown();
        }
        private static void Main(string[] args)
        {
            Console.WriteLine(logo + "\n\n" + "Deploying Models + Forms and start External Task Workers.\n\nPRESS ANY KEY TO STOP WORKERS.\n\n");

            CamundaEngineClient camunda = new CamundaEngineClient();

            camunda.Startup();  // Deploys all models to Camunda and Start all found ExternalTask-Workers
            Console.ReadLine(); // wait for ANY KEY
            camunda.Shutdown(); // Stop Task Workers
        }
Esempio n. 6
0
        private static void Main(string[] args)
        {
            Console.WriteLine(logo + "\n\n" + "Deploying models and start External Task Workers.\n\nPRESS Ctrl-C TO STOP WORKERS.\n\n");

            CamundaEngineClient camunda = new CamundaEngineClient();

            camunda.Startup(); // Deploys all models to Camunda and Start all found ExternalTask-Workers
            Console.CancelKeyPress += new ConsoleCancelEventHandler(OnExit);
            _closing.WaitOne();
            camunda.Shutdown(); // Stop Task Workers
        }
        public static void Main(string[] args)
        {
            CamundaEngineClient Camunda = new CamundaEngineClient(
                new Uri("http://localhost:8080/engine-rest/engine/default/"),
                "demo",
                "demo");

            Camunda.Startup();  // Deploys all models to Camunda and Start all found ExternalTask-Workers
            Console.ReadLine(); // wait for ANY KEY
            Camunda.Shutdown(); // Stop Task Workers
        }
Esempio n. 8
0
        public object createNewFile([FromBody] Dictionary <string, object> file)
        {
            var     o      = (Newtonsoft.Json.Linq.JObject)file["file"];
            dynamic od     = (dynamic)o;
            Guid    fileId = Guid.NewGuid();

            // Save it to Postgresql
            using (var connection = new NpgsqlConnection(Startup.databaseConnection))
            {
                const string stmt = @"INSERT INTO dbo.incidents(id, tenant_id, patient_id, unit_id, type, severity, state, details, created_by, created_on, last_modified_by, last_modified_on)
	                VALUES (@id, @tenant_id, @patient_id, @unit_id, @type, @severity, @state, @details, @cb, @co, @mb, @mo);"    ;
                connection.Open();
                try
                {
                    using (var cmd = new NpgsqlCommand(stmt, connection))
                    {
                        cmd.Parameters.AddWithValue("@id", fileId);
                        cmd.Parameters.AddWithValue("@tenant_id", Guid.Parse((string)od.tenantId.Value));
                        cmd.Parameters.AddWithValue("@patient_id", DBNull.Value);
                        cmd.Parameters.AddWithValue("@unit_id", Guid.Parse((string)od.unitId.Value));
                        cmd.Parameters.AddWithValue("@type", (string)od.type.Value);
                        cmd.Parameters.AddWithValue("@severity", (string)od.severity.Value);
                        cmd.Parameters.AddWithValue("@state", "new");
                        cmd.Parameters.AddWithValue("@details", od.details.ToString()).NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
                        cmd.Parameters.AddWithValue("@cb", (string)od.submittedBy.Value);
                        cmd.Parameters.AddWithValue("@co", DateTime.Now);
                        cmd.Parameters.AddWithValue("@mb", (string)od.submittedBy.Value);
                        cmd.Parameters.AddWithValue("@mo", DateTime.Now);
                        cmd.ExecuteNonQuery();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }

            // Post it to Camunda
            var camunda = new CamundaEngineClient(new System.Uri(Startup.camundaUrl), null, null);

            camunda.Startup();
            try
            {
                var ft = o.ToObject <Dictionary <string, object> >();
                ft["fileId"] = fileId;
                string processInstanceId = camunda.BpmnWorkflowService.StartProcessInstance("dodoAppRule", ft);
            }
            finally
            {
                camunda.Shutdown();
            }
            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
Esempio n. 9
0
        public static void CompleteTask(Guid taskId)
        {
            string wfId = null;

            using (var connection = new NpgsqlConnection(Startup.databaseConnection))
            {
                //Ignore user for now...
                connection.Open();
                try
                {
                    string stmt1 = @"SELECT wf_task_id FROM dbo.tasks WHERE id=@id";
                    using (var cmd = new NpgsqlCommand(stmt1, connection))
                    {
                        cmd.Parameters.AddWithValue("@id", taskId);
                        wfId = (string)cmd.ExecuteScalar();
                    }
                    string stmt2 = @"UPDATE dbo.tasks SET status='completed', complete_date=@dt1";
                    using (var cmd2 = new NpgsqlCommand(stmt2, connection))
                    {
                        cmd2.Parameters.AddWithValue("@dt1", DateTime.UtcNow);
                        cmd2.ExecuteNonQuery();
                    }
                }
                finally
                {
                    connection.Close();
                }

                if (wfId != null)
                {
                    var camunda = new CamundaEngineClient(new System.Uri(Startup.camundaUrl), null, null);
                    camunda.Startup();
                    try
                    {
                        camunda.HumanTaskService.Complete(wfId, new Dictionary <string, object>()
                        {
                            { "completed", true }
                        });
                    }
                    finally
                    {
                        camunda.Shutdown();
                    }
                }
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appSettings.json", optional: false, reloadOnChange: true);
            var configuration = builder.Build();

            connectionString = configuration.GetSection("database").Value;
            camundaUrl       = configuration.GetSection("camunda").Value;

            if (FetchBPMN())
            {
                Console.WriteLine("workflow found");
                var camunda = new CamundaEngineClient(new System.Uri(camundaUrl), null, null);
                camunda.Startup();
                try
                {
                    DateTime lastCheck = DateTime.Now.AddDays(-1);
                    while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
                    {
                        var tasks = camunda.HumanTaskService.LoadTasks(new Dictionary <string, string>()
                        {
                            { "createdAfter", lastCheck.ToString("yyyy-MM-ddTHH:mm:ss") },
                            { "processDefinitionName", "Incident" }
                        });
                        lastCheck = DateTime.Now;
                        if (tasks != null && tasks.Count != 0)
                        {
                            Console.WriteLine("Human task detected");
                            using (var connection = new NpgsqlConnection(connectionString))
                            {
                                const string stmtInsertTask = @"INSERT INTO dbo.tasks(id, user_id, wf_task_id, task_type, status, created_by, due_date, complete_date, subject, entity, entity_id, action_type, details)
	                                VALUES ( @id, @uid, @wf_task_id, @type, 'assigned', 'workflow', @due_date, null, @subject, 'incident', @file_id, @action_type, @details);"    ;
                                connection.Open();
                                try
                                {
                                    using (var cmd = new NpgsqlCommand(stmtInsertTask, connection))
                                    {
                                        foreach (var task in tasks)
                                        {
                                            var vs = camunda.HumanTaskService.LoadVariables(task.Id);
                                            var ps = Program.GetTaskVariables("userTask", task.TaskDefinitionKey);

                                            string roleName = ps["roleName"];
                                            string unitId   = (string)vs["unitId"];
                                            Guid   uid      = FindUserByParams(unitId, roleName);

                                            string expiry = ps["expiry"];
                                            int    days;

                                            if (!Int32.TryParse(expiry, out days))
                                            {
                                                days = 0;
                                            }

                                            cmd.Parameters.Clear();
                                            cmd.Parameters.AddWithValue("@id", Guid.NewGuid());
                                            cmd.Parameters.AddWithValue("@uid", uid);
                                            cmd.Parameters.AddWithValue("@wf_task_id", task.Id);
                                            cmd.Parameters.AddWithValue("@type", ps["taskType"]);
                                            if (days > 0)
                                            {
                                                cmd.Parameters.AddWithValue("@due_date", DateTime.UtcNow.AddDays(days));
                                            }
                                            else
                                            {
                                                cmd.Parameters.AddWithValue("@due_date", DBNull.Value);
                                            }

                                            cmd.Parameters.AddWithValue("@subject", "someText");
                                            cmd.Parameters.AddWithValue("@file_id", Guid.Parse((string)vs["fileId"]));
                                            cmd.Parameters.AddWithValue("@action_type", "fakeFormName");
                                            cmd.Parameters.AddWithValue("@details", "Something else");
                                            cmd.ExecuteNonQuery();
                                            // Some log?
                                        }
                                    }
                                }
                                finally
                                {
                                    connection.Close();
                                }
                            }
                        }
                        System.Threading.Thread.Sleep(2000);
                    }
                }
                finally
                {
                    camunda.Shutdown();
                }
            }
            else
            {
                Console.WriteLine("No workflow found");
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            const string ruleName = "testRule";
            var          fileName = Directory.GetCurrentDirectory() + "\\" + "testRule.bpmn";

            byte[] ruleContent = System.IO.File.ReadAllBytes(fileName);


            var camunda = new CamundaEngineClient(new System.Uri("http://*****:*****@b.com" },
                { "details", new Dictionary <string, object> {
                      { "patient", "Smith" },
                      { "age", 17 },
                      { "gender", "Male" }
                  } }
            };

            string processInstanceId = camunda.BpmnWorkflowService.StartProcessInstance(ruleName, fakeFile);

            DateTime lastCheck = DateTime.Now.AddDays(-1);

            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                var tasks = camunda.HumanTaskService.LoadTasks(new Dictionary <string, string>()
                {
                    { "createdAfter", lastCheck.ToString("yyyy-MM-ddTHH:mm:ss") },
                    { "processDefinitionName", "Incident" }
                });
                lastCheck = DateTime.Now;
                if (tasks != null && tasks.Count() != 0)
                {
                    Console.WriteLine("Human task detected");
                    foreach (var task in tasks)
                    {
                        var vs = camunda.HumanTaskService.LoadVariables(task.Id);
                        var ps = Program.GetTaskVariables("userTask", task.TaskDefinitionKey);
                        System.Threading.Thread.Sleep(5000);
                        camunda.HumanTaskService.Complete(task.Id, new Dictionary <string, object>()
                        {
                            { "completed", true }
                        });
                        Console.WriteLine("Complete human task " + ps["taskType"] + "on " + vs["fileId"].ToString());
                    }
                }
                System.Threading.Thread.Sleep(5000);
            }

            camunda.Shutdown(); // Stop Task Workers
        }
Esempio n. 12
0
        public static void PublishWorkflow(string bpmn)
        {
            bpmn = bpmn.Trim();
            string connectionString = Startup.databaseConnection;

            using (var connection = new NpgsqlConnection(connectionString))
            {
                connection.Open();
                try
                {
                    Guid         id   = Guid.Empty;
                    const string stmt = @"SELECT id FROM dbo.workflows WHERE entity='Incident'";
                    using (var cmd = new NpgsqlCommand(stmt, connection))
                    {
                        using (var reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                id = reader.GetGuid(0);
                            }
                        }
                    }
                    if (id == Guid.Empty)
                    {
                        string stmtInsert = @"INSERT INTO dbo.workflows( id, tenant_id, entity, process_id, bpmn_details, created_by, created_on, last_modified_by, last_modified_on)
                                            VALUES(@id, @tid, 'Incident', null, @bpmn, 'Jian', current_timestamp, 'Jian', current_timestamp)";
                        using (var cmd = new NpgsqlCommand(stmtInsert, connection))
                        {
                            cmd.Parameters.AddWithValue("@id", Guid.NewGuid());
                            cmd.Parameters.AddWithValue("@tid", Guid.Parse("fef554a9-e234-4177-8dac-0680702d4ec7"));
                            var p = cmd.Parameters.AddWithValue("@bpmn", bpmn);
                            p.DbType = DbType.Xml;
                            cmd.ExecuteNonQuery();
                        }
                    }
                    else
                    {
                        string stmtUpdate = @"UPDATE dbo.workflows set bpmn_details = @bpmn WHERE id = @id";
                        using (var cmd = new NpgsqlCommand(stmtUpdate, connection))
                        {
                            cmd.Parameters.AddWithValue("@id", id);
                            var p = cmd.Parameters.AddWithValue("@bpmn", bpmn);
                            p.DbType = DbType.Xml;
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                finally
                {
                    connection.Close();
                }
            }

            string camundaUrl = Startup.camundaUrl;
            var    camunda    = new CamundaEngineClient(new System.Uri(camundaUrl), null, null);

            camunda.Startup();
            try
            {
                string deploymentId = camunda.RepositoryService.Deploy("DodoAppRule", new List <object> {
                    new FileParameter(System.Text.Encoding.UTF8.GetBytes(bpmn), "DodoAppRule.bpmn")
                });
            }
            finally
            {
                camunda.Shutdown();
            }
        }