besley / Slickflow

.NET Open Source Workflow Engine, .NET 开源工作流
http://www.slickflow.net
Other
795 stars 248 forks source link

Auto advancing workflow to next step until it finishes #13

Closed nitinjs closed 2 years ago

nitinjs commented 4 years ago

hi,

    public class Doc1ScannerService : ExternalServiceBase, IExternalService
    {
        public override void Execute()
        {
            //get variable from runner
            //var amount = this.DynamicVariables["amount"];

            //get varaible from WfProcessVariable table
            var id = DelegateService.GetProcessInstanceID();

            System.Console.Error.WriteLine("I am scanning doc1");
        }
    }

    public class Doc2ScannerService : ExternalServiceBase, IExternalService
    {
        public override void Execute()
        {
            //get variable from runner
            //var amount = this.DynamicVariables["amount"];

            //get varaible from WfProcessVariable table
            var id = DelegateService.GetProcessInstanceID();

            System.Console.Error.WriteLine("I am scanning doc2");
        }
    }

I wonder if I have followed correct steps:

    public class LocalMethodActionEntity<T> : ActionEntity where T: IExternalService
    {
        public LocalMethodActionEntity()
        {
            ActionMethod = ActionMethodEnum.LocalMethod;
            ActionType = ActionTypeEnum.Event;
            FireType = FireTypeEnum.Before;
            SubMethod = SubMethodEnum.None;
            Expression = typeof(T).FullName;
        }
    }

workflow definition

            var pmb = ProcessModelBuilder.CreateProcess("PersonIdentification", "P001");
            var process = pmb.Start("Start", "K000")
                .Task(VertexBuilder.CreateTask("Scan doc1", "K001")
                    .AddAction(new LocalMethodActionEntity<Doc1ScannerService>()))
                .Task(VertexBuilder.CreateTask("Scan doc2", "K002")
                    .AddAction(new LocalMethodActionEntity<Doc2ScannerService>()))
                .End("End", "K003")
                .Store();

starting workflow and running till end task:

WfAppRunner runner = new WfAppRunner();
            runner.Version = "1";
            runner.UserID = "10";
            runner.UserName = "NS";
            runner.AppName = "Test APP";
            runner.AppInstanceID = System.Guid.NewGuid().ToString();
            runner.AppInstanceCode = "TX002";
            runner.ProcessGUID = process.ProcessGUID;
            runner.Conditions.Add("isApc", "1");

            IWorkflowService wfService = new WorkflowService();
            var app = wfService.CreateRunner(runner.UserID, runner.UserName)
                     .UseApp(runner.AppInstanceID, runner.AppName, runner.AppInstanceCode)
                     .UseProcess(runner.ProcessGUID, runner.Version);
            var wfResult = app.Start();

        ExecuteNextStep:
            var wfResultRun = app
                .NextStepInt(runner.UserID, runner.UserName)
                .Run();

            if (wfResultRun.Status == Engine.Core.Result.WfExecutedStatus.Success)
            {
                var nextStep = app.GetRunningNode(runner);

                if (nextStep.ActivityType != (short)ActivityTypeEnum.EndNode)
                    goto ExecuteNextStep;
            }

my problem is that workflow never reaches the last stage, it just repeats the first stage.

if there is no user interaction required or conditions meet as per requirements then workflow should auto advance to next step and so on..

how do I achieve this?

help

besley commented 4 years ago

The runner object should be reset taskid property everytime. We have updated this method.

        public IWorkflowService CreateRunner(string userID, string userName)
        {
            _wfAppRunner.UserID = userID;
            _wfAppRunner.UserName = userName;
            _wfAppRunner.TaskID = null;
            return this;
        }