Ejemplo n.º 1
0
        protected virtual void OnTestLoadSimpleRuntimeProcess()
        {
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();
            var processDefinition = BuildProcessdefinition();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);
            Md5CalcVisitor visitor = new Md5CalcVisitor();

            processDefinition.Accept(visitor);
            string md5 = visitor.CalculateMd5();
            IProcessRuntimeService pservice   = GetProcessRuntime();
            PropertySetCollection  collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            IProcessRuntime        runtime    = pservice.Create(processDefinition, collection);

            IProcessRuntime        ufRuntime;
            StepRuntime            nextStep;
            IPropertySetCollection ufCollection;
            bool val = pservice.TryUnfreeze(runtime.Id, out ufRuntime, out nextStep, out ufCollection);

            Assert.IsTrue(val);
            Assert.IsNotNull(ufRuntime);
            Assert.IsNotNull(ufCollection);
            Assert.AreEqual(ProcessStateEnum.NotStarted, ufRuntime.State);
            Assert.AreEqual(runtime.Id, ufRuntime.Id);
            string policyNumber = collection.Get <string>("PolicyNumber");

            Assert.IsTrue(string.IsNullOrEmpty(policyNumber));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create and persist runtime processor
        /// </summary>
        /// <param name="pd"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public override IProcessRuntime Create(ProcessDefinition pd, IPropertySetCollection collection)
        {
            IProcessRuntime runtime = base.Create(pd, collection);
            Md5CalcVisitor  visitor = new Md5CalcVisitor();

            pd.Accept(visitor);
            string md5 = visitor.CalculateMd5();

            using (var ctx = new ProcessDbContext())
            {
                var pdList = ctx.ProcessDefinition
                             .Where(p => p.FlowId == pd.FlowId && p.Md5 == md5).ToList();

                if (pdList.Count() != 1)
                {
                    throw new ArgumentException($"Process definition is not persisted.");
                }
                // save or update the collection
                PersistentPropertyCollection persistedCollection =
                    _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, collection);
                ProcessRuntimePersistence rtp = new ProcessRuntimePersistence
                {
                    Id = runtime.Id,
                    SuspendedStepId    = runtime.LastExecutedStep?.StepId,
                    Status             = (int)runtime.State,
                    LastUpdated        = DateTime.UtcNow,
                    PropertyCollection = persistedCollection,
                    ProcessDefinition  = pdList.ElementAt(0)
                };
                ctx.Process.Add(rtp);
                ctx.SaveChanges();
            }
            return(new ProcessRuntimePersistenProxy(runtime, this));
        }
        /// <summary>
        /// Continue the execution after freeze
        /// </summary>
        /// <param name="real"></param>
        /// <param name="result"></param>
        /// <param name="env"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void OnContinue(IProcessRuntime real, Tuple <ExecutionResult, StepRuntime> result, IProcessRuntimeEnvironment env)
        {
            var persistedCollection = CreatePersistentPropertyCollection(real, env.PropertySet);
            var filter = Builders <MongoProcessRuntimePersistence> .Filter.Eq(r => r.Id, real.Id);

            var updater = Builders <MongoProcessRuntimePersistence> .Update
                          .Set(r => r.Status, (int)real.State)
                          .Set(r => r.PropertyCollection, persistedCollection)
                          .CurrentDate(r => r.LastUpdated);

            if (result.Item1.Status == StepExecutionStatusEnum.Ready)
            {
                updater = updater.Set(r => r.NextStepId, result.Item2.StepId);
            }
            if (result.Item1.Status == StepExecutionStatusEnum.Suspend)
            {
                updater = updater.Set(r => r.NextStepId, null).Set(r => r.SuspendedStepId, result.Item2.StepId);
            }
            UpdateResult updateResult = _collection.UpdateOne(filter, updater);

            if (updateResult.ModifiedCount != 1)
            {
                throw new ArgumentException($"Cannot modify the process Id={real.Id}");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Unfreeze the process
 /// </summary>
 /// <param name="processRuntimeId"></param>
 /// <param name="runtime"></param>
 /// <param name="nextStep"></param>
 /// <param name="collection"></param>
 /// <returns></returns>
 public override bool TryUnfreeze(Guid processRuntimeId,
                                  out IProcessRuntime runtime,
                                  out StepRuntime nextStep,
                                  out IPropertySetCollection collection)
 {
     runtime    = null;
     collection = null;
     nextStep   = null;
     using (var ctx = new ProcessDbContext())
     {
         var rtp = ctx.Process.Find(processRuntimeId);
         if (rtp == null)
         {
             return(false);
         }
         var definition =
             JsonConvert.DeserializeObject <ProcessDefinition>(rtp.ProcessDefinition.JsonProcessDefinition);
         definition.Id = rtp.ProcessDefinition.Id;
         collection    = rtp.PropertyCollection.Deserialize();
         if (!string.IsNullOrEmpty(rtp.NextStepId))
         {
             StepDefinition   stepDef = definition.Steps.Single(s => s.StepId == rtp.NextStepId);
             StepDefinitionId sid     = new StepDefinitionId(stepDef.Id, stepDef.StepId);
             LinkDefinition[] links   = definition.Links.Where(l => l.Source == sid).ToArray();
             nextStep = new StepRuntime(stepDef, links.Select(l => new LinkRuntime(l)).ToArray());
         }
         runtime = Create(rtp.Id, definition, rtp.SuspendedStepId, (ProcessStateEnum)rtp.Status);
     }
     return(true);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessRuntimeEnvironment"/> class.
 /// </summary>
 /// <param name="propertySet">The property set.</param>
 public ProcessRuntimeEnvironment(
     IProcessRuntime runtime,
     IPropertySetCollection propertySet)
 {
     ProcessRuntime = runtime;
     PropertySet    = propertySet;
 }
Ejemplo n.º 6
0
        protected virtual void OnTestExecuteWorkflowFromSuspendedStep()
        {
            var processDefinition = BuildProcessWithTasks();
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);

            IProcessRuntimeService            pservice   = GetProcessRuntime();
            PropertySetCollection             collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            Mock <IProcessRuntimeEnvironment> mEnv       = new Mock <IProcessRuntimeEnvironment>();

            mEnv.SetupGet(m => m.PropertySet).Returns(collection).Verifiable();
            mEnv.Setup(m => m.TaskServiceAsync())
            .Returns(() =>
                     Task.FromResult(new ExecutionResult(StepExecutionStatusEnum.Suspend)))
            .Verifiable();

            IProcessRuntime runtime = pservice.Create(processDefinition, collection);

            string[] error;
            Assert.IsTrue(runtime.TryCompile(out error));
            var startStep = runtime.StartSteps.First();

            Assert.IsNotNull(startStep);
            var result = runtime.Execute(startStep, mEnv.Object);

            Assert.IsNotNull(result);
            Assert.AreEqual(StepExecutionStatusEnum.Ready, result.Item1.Status);
            Assert.AreEqual("task_1", result.Item2.StepId);
            // freeze the workflow
            pservice.Freeze(runtime, collection);
            // execute Task step
            result = runtime.Execute(result.Item2, mEnv.Object);
            Assert.IsNotNull(result);
            Assert.AreEqual(StepExecutionStatusEnum.Suspend, result.Item1.Status);
            Assert.AreEqual("task_1", result.Item2.StepId);
            mEnv.Verify(m => m.TaskServiceAsync(), Times.Once);
            Assert.IsNotNull(runtime.SuspendedInStep);
            Assert.AreEqual("task_1", runtime.SuspendedInStep.StepId);
            // freeze the process
            pservice.Freeze(runtime, collection);
            // unfreeze the process

            IProcessRuntime        unfrozenProcess;
            StepRuntime            nextStep;
            IPropertySetCollection unfrozenCollection;

            Assert.IsTrue(pservice.TryUnfreeze(runtime.Id, out unfrozenProcess, out nextStep, out unfrozenCollection));
            Assert.IsNotNull(unfrozenProcess);
            Assert.IsNotNull(unfrozenCollection);
            Assert.AreEqual(1, unfrozenCollection.Get <int?>("Count"));
            Assert.AreEqual("P12345", unfrozenCollection.Get <string>("PolicyNumber"));
            Assert.AreEqual(ProcessStateEnum.Suspended, unfrozenProcess.State);
            Assert.IsNotNull(unfrozenProcess.SuspendedInStep);
            Assert.AreEqual("task_1", unfrozenProcess.SuspendedInStep.StepId);
        }
        public void TestContinueAfterSuspending()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;

            builder.Start("s_1").Handler().HumanTask().Done().SetName("Start").Done()
            .Step("s_2").Handler().HumanTask().Done().Done()
            .Step("s_3").Handler().HumanTask().Done().Done()
            .End("e_1").SetName("End Process").Done()
            .Link().From("s_1").To("s_2").Name("s_1_s_2").Done()
            .Link().From("s_2").To("s_3").Name("s_2_s_3").Done()
            .Link().From("s_3").To("e_1").Name("end").Done()
            .TryValidate(out result);

            ProcessDefinition processDefinition          = builder.Build();
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);

            IProcessRuntimeService            pservice   = GetProcessRuntime();
            PropertySetCollection             collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            Mock <IProcessRuntimeEnvironment> mEnv       = new Mock <IProcessRuntimeEnvironment>();

            mEnv.SetupGet(m => m.PropertySet).Returns(collection).Verifiable();
            mEnv.Setup(m => m.TaskServiceAsync())
            .Returns(() =>
                     Task.FromResult(new ExecutionResult(StepExecutionStatusEnum.Suspend)))
            .Verifiable();

            IProcessRuntime runtime = pservice.Create(processDefinition, collection);

            string[] errors;
            runtime.TryCompile(out errors);

            IProcessRuntime        ufRuntime;
            StepRuntime            ufStep;
            IPropertySetCollection ufCollection;
            Tuple <ExecutionResult, StepRuntime> execute = runtime.Execute(runtime.StartSteps[0], mEnv.Object);

            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Suspend, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_1");
            execute = runtime.Continue(mEnv.Object);
            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Ready, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_2");

            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.IsNotNull(ufRuntime);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("s_2", ufStep.StepId);
        }
Ejemplo n.º 8
0
 public override void Freeze(IProcessRuntime runtime, IPropertySetCollection collection)
 {
     using (var ctx = new ProcessDbContext())
     {
         ProcessRuntimePersistence persistence = ctx.Process.Find(runtime.Id);
         if (persistence == null)
         {
             throw new ArgumentException("Invalid Workflow Id:" + runtime.Id.ToString());
         }
         _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, collection);
         persistence.Status          = (int)runtime.State;
         persistence.LastUpdated     = DateTime.UtcNow;
         persistence.SuspendedStepId = runtime.SuspendedInStep?.StepId;
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 9
0
        protected virtual IProcessRuntime OnTestCreateSimplePersistentRuntime()
        {
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();
            var processDefinition = BuildProcessdefinition();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);
            Md5CalcVisitor visitor = new Md5CalcVisitor();

            processDefinition.Accept(visitor);
            string md5 = visitor.CalculateMd5();
            IProcessRuntimeService pservice   = GetProcessRuntime();
            PropertySetCollection  collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            IProcessRuntime        runtime    = pservice.Create(processDefinition, collection);

            Assert.IsNotNull(runtime);
            return(runtime);
        }
Ejemplo n.º 10
0
 protected virtual void OnExecute(IProcessRuntime runtime, Tuple <ExecutionResult, StepRuntime> result, IProcessRuntimeEnvironment env)
 {
     using (var ctx = new ProcessDbContext())
     {
         ProcessRuntimePersistence persistence = ctx.Process.Find(runtime.Id);
         if (persistence == null)
         {
             throw new ArgumentException("Invalid Workflow Id:" + runtime.Id);
         }
         _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, env.PropertySet);
         persistence.Status          = (int)runtime.State;
         persistence.LastUpdated     = DateTime.UtcNow;
         persistence.SuspendedStepId = runtime.SuspendedInStep?.StepId;
         persistence.NextStepId      = runtime.State == ProcessStateEnum.Completed? null: result.Item2?.StepId;
         ctx.SaveChanges();
     }
 }
        /// <summary>
        /// Freeze (persist) the runtime process
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="collection"></param>
        public override void Freeze(IProcessRuntime runtime, IPropertySetCollection collection)
        {
            var persistedCollection = CreatePersistentPropertyCollection(runtime, collection);
            var filter = Builders <MongoProcessRuntimePersistence> .Filter.Eq(r => r.Id, runtime.Id);

            var updater = Builders <MongoProcessRuntimePersistence> .Update
                          .Set(r => r.Status, (int)runtime.State)
                          .Set(r => r.SuspendedStepId, runtime.SuspendedInStep?.StepId)
                          .Set(r => r.PropertyCollection, persistedCollection)
                          .CurrentDate(r => r.LastUpdated);

            UpdateResult updateResult = _collection.UpdateOne(filter, updater);

            if (updateResult.ModifiedCount != 1)
            {
                throw new ArgumentException($"Cannot modify the process Id={runtime.Id}");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="result"></param>
        /// <param name="env"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void OnExecute(IProcessRuntime runtime, Tuple <ExecutionResult, StepRuntime> result, IProcessRuntimeEnvironment env)
        {
            var persistedCollection = CreatePersistentPropertyCollection(runtime, env.PropertySet);
            var filter = Builders <MongoProcessRuntimePersistence> .Filter.Eq(r => r.Id, runtime.Id);

            var updater = Builders <MongoProcessRuntimePersistence> .Update
                          .Set(r => r.Status, (int)runtime.State)
                          .Set(r => r.SuspendedStepId, runtime.SuspendedInStep?.StepId)
                          .Set(r => r.PropertyCollection, persistedCollection)
                          .Set(r => r.NextStepId, runtime.State == ProcessStateEnum.Completed? null: result.Item2?.StepId)
                          .CurrentDate(r => r.LastUpdated);

            UpdateResult updateResult = _collection.UpdateOne(filter, updater);

            if (updateResult.ModifiedCount != 1)
            {
                throw new ArgumentException($"Cannot modify the process Id={runtime.Id}");
            }
        }
        /// <summary>
        /// Un-freeze the runtime process
        /// </summary>
        /// <param name="processRuntimeId"></param>
        /// <param name="runtime"></param>
        /// <param name="nextStep"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        public override bool TryUnfreeze(Guid processRuntimeId, out IProcessRuntime runtime, out StepRuntime nextStep,
                                         out IPropertySetCollection collection)
        {
            runtime    = null;
            nextStep   = null;
            collection = null;
            var filter = Builders <MongoProcessRuntimePersistence> .Filter.Eq(r => r.Id, processRuntimeId);

            MongoProcessRuntimePersistence rtp = _collection.Find(filter).SingleOrDefault();

            if (rtp == null)
            {
                return(false);
            }
            var defFilter = Builders <ProcessDefinitionPersistence> .Filter.And(
                Builders <ProcessDefinitionPersistence> .Filter.Eq(r => r.FlowId, rtp.DefinitionFlowId),
                Builders <ProcessDefinitionPersistence> .Filter.Eq(r => r.Md5, rtp.DefinitionMd5)
                );

            ProcessDefinition    definition;
            ProcessDefStatusEnum status;

            AccountData[] accounts;
            if (!_processDefinitionService.TryFind(defFilter, out definition, out status, out accounts))
            {
                return(false);
            }
            collection = rtp.PropertyCollection.Deserialize();
            if (!string.IsNullOrEmpty(rtp.NextStepId))
            {
                StepDefinition   stepDef = definition.Steps.SingleOrDefault(s => s.StepId == rtp.NextStepId);
                StepDefinitionId sid     = new StepDefinitionId(stepDef.Id, stepDef.StepId);
                LinkDefinition[] links   = definition.Links.Where(l => l.Source == sid).ToArray();
                nextStep = new StepRuntime(stepDef, links.Select(l => new LinkRuntime(l)).ToArray());
            }
            runtime = Create(rtp.Id, definition, rtp.SuspendedStepId, (ProcessStateEnum)rtp.Status);
            return(true);
        }
        /// <summary>
        /// Create process runtime definition
        /// </summary>
        /// <param name="pd"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public override IProcessRuntime Create(ProcessDefinition pd, IPropertySetCollection collection)
        {
            IProcessRuntime runtime = base.Create(pd, collection);
            Md5CalcVisitor  visitor = new Md5CalcVisitor();

            pd.Accept(visitor);
            string md5 = visitor.CalculateMd5();
            // save the collection
            var processDefinitions      = _processDefinitionService.ActivetWorkflows();
            var processDefinitionDigest = processDefinitions.SingleOrDefault(d => d.FlowId == pd.FlowId && d.Md5 == md5 && d.Status == ProcessDefStatusEnum.Active);

            if (processDefinitionDigest == null)
            {
                throw new ArgumentException($"Error find Process Definition Id={pd.FlowId} Md5={md5}");
            }
            var rtp = CreateMongoProcessRuntimePersistence(runtime, collection,
                                                           null,
                                                           null,
                                                           processDefinitionDigest);

            _collection.InsertOne(rtp);
            return(new ProcessRuntimePersistenProxy(runtime, this));
        }
        /// <summary>
        /// Create persistent element
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="collection"></param>
        /// <param name="errors"></param>
        /// <param name="processDefinitionDigest"></param>
        /// <param name="nextStepId"></param>
        /// <returns></returns>
        private MongoProcessRuntimePersistence CreateMongoProcessRuntimePersistence(
            IProcessRuntime runtime,
            IPropertySetCollection collection,
            string nextStepId,
            List <string> errors,
            ProcessDefinitionDigest processDefinitionDigest)
        {
            var persistedCollection            = CreatePersistentPropertyCollection(runtime, collection);
            MongoProcessRuntimePersistence rtp = new MongoProcessRuntimePersistence
            {
                Id = runtime.Id,
                SuspendedStepId    = runtime.LastExecutedStep?.StepId,
                Status             = (int)runtime.State,
                LastUpdated        = DateTime.UtcNow,
                PropertyCollection = persistedCollection,
                DefinitionFlowId   = processDefinitionDigest.FlowId,
                DefinitionMd5      = processDefinitionDigest.Md5,
                NextStepId         = null,
                Errors             = errors
            };

            return(rtp);
        }
 public ProcessRuntimePersistenProxy(IProcessRuntime real,
                                     MongoProcessRuntimePersistenceService persistenceService)
 {
     _real = real;
     _persistenceService = persistenceService;
 }
        private static PersistentPropertyCollection CreatePersistentPropertyCollection(IProcessRuntime runtime,
                                                                                       IPropertySetCollection collection)
        {
            List <PersistentSchemaElement>   schemaElements;
            List <PersistentPropertyElement> dataElements;

            collection.CreatePersistentSchemaElements(out schemaElements, out dataElements);
            PersistentPropertyCollection persistedCollection = new PersistentPropertyCollection
            {
                Id       = runtime.Id,
                Version  = 1,
                Elements = dataElements,
                Schemas  = schemaElements
            };

            return(persistedCollection);
        }
Ejemplo n.º 18
0
        protected virtual void OnTestExecuteMultipleStepsSaveStateBetweenSteps()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;

            builder.Variables()
            .Name("Count")
            .Type(VariableTypeEnum.Int)
            .Done()
            .Start("s_1")
            .SetName("Start")
            .OnEntry()
            .Language(ScriptLanguage.CSharpScript)
            .Body("" +
                  " PropertySet.Set(\"Count\",(int?)1);" +
                  " return 1;")
            .Done()
            .Done()
            .Step("s_2")
            .OnEntry()
            .Language(ScriptLanguage.CSharpScript)
            .Body("" +
                  " PropertySet.Set(\"Count\",(int?)2);" +
                  " return 1;")
            .Done()
            .Done()
            .Step("s_3")
            .OnEntry()
            .Language(ScriptLanguage.CSharpScript)
            .Body("" +
                  " PropertySet.Set(\"Count\",(int?)3);" +
                  " return 1;")
            .Done()
            .Done()
            .End("e_1")
            .SetName("End Process")
            .Done()
            .Link()
            .From("s_1")
            .To("s_2")
            .Name("s_1_s_2")
            .Done()
            .Link()
            .From("s_2")
            .To("s_3")
            .Name("s_2_s_3")
            .Done()
            .Link()
            .From("s_3")
            .To("e_1")
            .Name("end")
            .Done()
            .TryValidate(out result);
            ProcessDefinition processDefinition          = builder.Build();
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);

            IProcessRuntimeService            pservice   = GetProcessRuntime();
            PropertySetCollection             collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            Mock <IProcessRuntimeEnvironment> mEnv       = new Mock <IProcessRuntimeEnvironment>();

            mEnv.SetupGet(m => m.PropertySet).Returns(collection).Verifiable();
            mEnv.Setup(m => m.TaskServiceAsync())
            .Returns(() =>
                     Task.FromResult(new ExecutionResult(StepExecutionStatusEnum.Suspend)))
            .Verifiable();
            IProcessRuntime runtime = pservice.Create(processDefinition, collection);

            string[] errors;
            runtime.TryCompile(out errors);
            IProcessRuntime        ufRuntime;
            StepRuntime            ufStep;
            IPropertySetCollection ufCollection;

            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.IsNotNull(ufRuntime);
            Assert.IsNotNull(ufCollection);
            Assert.IsNull(ufStep);
            Assert.IsNull(ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.NotStarted, ufRuntime.State);

            Tuple <ExecutionResult, StepRuntime> exResult = runtime.Execute(runtime.StartSteps[0], mEnv.Object);

            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(1, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Ready, ufRuntime.State);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("s_2", ufStep.StepId);

            exResult = runtime.Execute(exResult.Item2, mEnv.Object);
            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(2, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Ready, ufRuntime.State);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("s_3", ufStep.StepId);

            exResult = runtime.Execute(exResult.Item2, mEnv.Object);
            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(3, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Ready, ufRuntime.State);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("e_1", ufStep.StepId);

            exResult = runtime.Execute(exResult.Item2, mEnv.Object);
            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(3, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Completed, ufRuntime.State);
            Assert.IsNull(ufStep);
        }
 /// <summary>
 /// Unfreeze the process
 /// </summary>
 /// <param name="processRuntimeId"></param>
 /// <param name="runtime"></param>
 /// <param name="nextStep"></param>
 /// <param name="collection"></param>
 /// <returns></returns>
 public virtual bool TryUnfreeze(Guid processRuntimeId, out IProcessRuntime runtime, out StepRuntime nextStep, out IPropertySetCollection collection)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Freeze thw process
 /// </summary>
 /// <param name="runtime"></param>
 /// <param name="collection"></param>
 public virtual void Freeze(IProcessRuntime runtime, IPropertySetCollection collection)
 {
 }
        public void TestContinueTaskWithLinkAnVariables()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;

            builder
            .Variables().Name("v_1").Type(VariableTypeEnum.String).Done()
            .Variables().Name("v_2").Type(VariableTypeEnum.String).Done()
            .Start("s_1").Handler().HumanTask().Done().SetName("Start")
            .Vars().Name("v_1").Done()
            .Vars().Name("v_2").Done()
            .Done()
            .Step("s_2").Handler().HumanTask().Done()
            .Done()
            .Step("s_3").Handler().HumanTask().Done()
            .Vars().Name("v_1").OnExit().Done()
            .Vars().Name("v_2").OnExit().Done()
            .Done()
            .End("e_1").SetName("End Process").Done()
            .Link().From("s_1").To("s_2").Name("s_1_s_2").Done()
            .Link().From("s_1").To("s_3").Name("s_1_s_3").Done()
            .Link().From("s_2").To("e_1").Name("s2_end").Done()
            .Link().From("s_3").To("e_1").Name("s3_end").Done()
            .TryValidate(out result);

            ProcessDefinition processDefinition          = builder.Build();
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);
            // retrieve process definition
            var flows = service.ActivetWorkflows();

            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
            ProcessDefinition    loadedPd;
            ProcessDefStatusEnum status;

            Assert.IsTrue(service.TryFind(flows[0].Id, flows[0].Version, out loadedPd, out status, out accounts));

            IProcessRuntimeService            pservice   = GetProcessRuntime();
            PropertySetCollection             collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            Mock <IProcessRuntimeEnvironment> mEnv       = new Mock <IProcessRuntimeEnvironment>();

            mEnv.SetupGet(m => m.PropertySet).Returns(collection).Verifiable();
            mEnv.Setup(m => m.TaskServiceAsync())
            .Returns(() =>
                     Task.FromResult(new ExecutionResult(StepExecutionStatusEnum.Suspend)))
            .Verifiable();
            mEnv.SetupGet(m => m.Transition).Returns("s_1_s_3");
            IProcessRuntime runtime = pservice.Create(loadedPd, collection);

            string[] errors;
            runtime.TryCompile(out errors);
            Tuple <ExecutionResult, StepRuntime> execute = runtime.Execute(runtime.StartSteps[0], mEnv.Object);

            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Suspend, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_1");
            collection.Set("v_1", "v_1");
            collection.Set("v_2", "v_2");
            execute = runtime.Continue(mEnv.Object);
            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Ready, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_3");
            Assert.IsNotNull(execute.Item2.StepDefinition.VariablesMap);
            Assert.AreEqual(2, execute.Item2.StepDefinition.VariablesMap.Length);
            Assert.AreEqual(VarRequiredEnum.OnExit, execute.Item2.StepDefinition.VariablesMap[0].Required);
            Assert.AreEqual(VarRequiredEnum.OnExit, execute.Item2.StepDefinition.VariablesMap[1].Required);
        }
Ejemplo n.º 22
0
 protected virtual void OnContinue(IProcessRuntime real, Tuple <ExecutionResult, StepRuntime> result, IProcessRuntimeEnvironment env)
 {
     throw new NotImplementedException();
 }