Beispiel #1
0
        protected virtual IProcessEngine BuildProcessEngine()
        {
            var contextFactory = new ContextFactory();

            contextFactory.Configure(builder =>
            {
                // builder.UseLoggerFactory(loggerFactory);
                builder.UseLazyLoadingProxies(true);
                builder.UseMySql("server=localhost;uid=root;pwd=123456;database=bpmtk3");
            });

            var engine = new ProcessEngineBuilder()
                         .SetContextFactory(contextFactory)
                         .SetLoggerFactory(loggerFactory)
                         .Build();

            return(engine);

            //return builder.AddHibernateStores(cfg =>
            //{
            //    cfg.SetInterceptor(new XUnitSqlCaptureInterceptor(this.output));
            //}).Build();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Setup LoggerFactory.
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddConsole(
                //LogLevel.Debug //Warning  //filter logger level.
                );

            //Create Bpmtk-Context Factory, and configure database.
            var conextFactory = new ContextFactory();

            conextFactory.Configure(builder =>
            {
                builder.EnableSensitiveDataLogging();
                builder.UseLoggerFactory(loggerFactory);
                builder.UseLazyLoadingProxies(true);
                builder.UseMySql("server=localhost;uid=root;pwd=123456;database=bpmtk4");
            });

            //Create custom ProcessEventListener.
            var processEventListener = new DemoProcessEventListener();

            //Build Process Engine.
            var engine = new ProcessEngineBuilder()
                         .SetContextFactory(conextFactory)
                         .SetLoggerFactory(loggerFactory)
                         .AddProcessEventListener(processEventListener)
                         //.Configure(options =>
                         //{
                         //    options.SetValue("isActivityRecorderDisabled", false);
                         //})
                         .Build();

            //init process-engine props. (optional)
            //engine.SetValue("isActivityRecorderDisabled", false);

            //Create new context.
            var context = engine.CreateContext();

            //Start db transaction.
            var transaction = context.DbSession.BeginTransaction();

            //Register current context. (optional)
            Context.SetCurrent(context);

            //Create one test user.
            var identityManager = context.IdentityManager;

            //Check if test user exists.
            var user = identityManager.FindUserById("test");

            if (user == null)
            {
                user = new User()
                {
                    Id = "test", Name = "Test"
                };
                identityManager.CreateUser(user);
            }

            //Set current authenticated user id.
            context.SetAuthenticatedUser(user.Id);

            var deploymentManager = context.DeploymentManager;

            //var q = deploymentManager.CreateDefinitionQuery()
            //    .FetchLatestVersionOnly()
            //    .FetchDeployment()
            //    .FetchIdentityLinks()
            //    .SetName("Script")
            //    .List().Result;

            //var rx = x.ToList();

            //Deploy BPMN 2.0 Model.
            var modelContent = GetBpmnModelContentFromResource("ConsoleApp.resources.ParallelGatewayTest.testNestedForkJoin.bpmn20.xml");

            var deploymentBuilder = deploymentManager.CreateDeploymentBuilder();
            var deployment        = deploymentBuilder
                                    .SetCategory("demo")
                                    .SetName("Demo deployment")
                                    .SetMemo("A simple process demo for BPMTK.")
                                    .SetBpmnModel(modelContent)
                                    .Build();

            var processDefinitions = deployment.ProcessDefinitions;

            foreach (var procDef in processDefinitions)
            {
                Console.WriteLine($"Process '{procDef.Key}' has been deployed.");
            }

            var processId = "nestedForkJoin"; //processDefinitionKey

            //Start new process-instance.
            var runtimeManager = context.RuntimeManager;
            var pi             = runtimeManager.StartProcessByKeyAsync(processId)
                                 .Result;

            HumanTasksInteraction(context, pi)
            .GetAwaiter().GetResult();

            //Verify Process Completed.
            pi = runtimeManager.Find(pi.Id);
            Assert.True(pi.State == ExecutionState.Completed);

            //Commit db transaction.
            transaction.Commit();

            //Dispose context. (close databse connection)
            context.Dispose();

            Console.WriteLine("It's OK.");
            Console.ReadKey();
        }