Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var workflow = new Workflow();

            workflow.AddActivity(new VideoUpload());
            workflow.AddActivity(new SendEmail());

            var workflowEngine = new WorkflowEngine();

            workflowEngine.Run(workflow);
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            var engine   = new WorkflowEngine();
            var workflow = new Workflow();

            workflow.AddActivity(new VideoUploader());
            workflow.AddActivity(new WebServiceConnection());
            workflow.AddActivity(new SendMail());
            workflow.AddActivity(new VideoProcessor());
            engine.Run(workflow);
        }
Ejemplo n.º 3
0
        public static Workflow AddPromptUser(this Workflow wf, string name, string personExpression = null, string fromNamed = null, string fromExit = null, string[] promptFor = null)
        {
            var act = new PromptUserActivity
            {
                Name = name
            };

            var actAs = act.As <WfActivity>();

            AddExpressionToActivityArgument(wf, actAs, "For Person", personExpression ?? "[Triggering Person]");

            foreach (var argument in wf.InputArguments.Union(wf.Variables, new EntityIdComparer()))
            {
                if (promptFor == null || promptFor.Contains(argument.Name))
                {
                    act.PromptForArguments.Add(new ActivityPrompt {
                        Name = argument.Name, ActivityPromptArgument = argument
                    });
                }
            }

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add display form with an exit point called "First Exit" that is the default;
        /// </summary>
        public static Workflow AddDisplayForm(this Workflow wf, string name, string[] exits, string formExpression = null, string recordExpression = null, string personExpression = null, string fromNamed = null, string fromExit = null)
        {
            var act = new DisplayFormActivity()
            {
                Name = name
            };
            var actAs = act.As <WfActivity>();

            if (formExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Form", formExpression);
            }

            if (recordExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Record", recordExpression);
            }

            if (personExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "For Person", personExpression);
            }
            else
            {
                AddExpressionToActivityArgument(wf, actAs, "For Person", "[Triggering Person]");
            }


            AddExits(act.ExitPoints, exits);

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add a a log activity
        /// </summary>
        public static Workflow AddUpdateField(this Workflow wf, string name, Resource fieldOrRel = null, string resourceExpression = null, string valueExpression = null, string fromNamed = null, string fromExit = null)
        {
            var uf = new UpdateFieldActivity {
                Name = name
            };
            var ufAs = uf.As <WfActivity>();

            if (resourceExpression != null)
            {
                AddExpressionToActivityArgument(wf, ufAs, "Record", resourceExpression);
            }

            if (fieldOrRel != null)
            {
                uf.InputArguments.Add(new ResourceArgument {
                    Name = "1"
                }.Cast <ActivityArgument>());
                SetActivityArgumentToResource(wf, ufAs, "1", fieldOrRel);
            }


            if (valueExpression != null)
            {
                uf.InputArguments.Add(new ObjectArgument {
                    Name = "1_value"
                }.Cast <ActivityArgument>());
                AddExpressionToActivityArgument(wf, ufAs, "1_value", valueExpression);
            }

            wf.AddActivity(ufAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 6
0
        public static Workflow AddLaunchTargetCampaign(
            this Workflow wf,
            string name,
            string surveyExpression,
            string targetsExpression,
            string surveyTakerExpression,
            string targetExpression   = null,
            string taskNameExpression = null,
            string dueDaysExpression  = null,
            string pauseExpression    = null,
            string fromNamed          = null,
            string fromExit           = null)
        {
            var act = new LaunchTargetCampaignActivity
            {
                Name = name
            };
            var actAs = act.As <WfActivity>();

            if (surveyExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Survey", surveyExpression);
            }

            if (targetsExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Targets", targetsExpression);
            }

            if (surveyTakerExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Survey Taker", surveyTakerExpression);
            }

            if (targetExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Target Object", targetExpression);
            }

            if (taskNameExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Task name", taskNameExpression);
            }

            if (dueDaysExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Due in (Days)", dueDaysExpression);
            }

            if (pauseExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Pause Until Completed", pauseExpression);
            }

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            // TestStopwatch();
            // TestStackoverflowPost();
            // TestDBConnection();
            //TestDbCommand();

            var workFlow = new Workflow();

            workFlow.AddActivity(new UploadActivity {
                Name = "Upload Activity", Value = "To upload a file/video"
            });
            workFlow.AddActivity(new SendEmailActivity {
                Name = "Send Email Activity", Value = "To send an email after uploadingvideo"
            });
            var workflowEngine = new WorkflowEngine();

            workflowEngine.Run(workFlow);
        }
Ejemplo n.º 8
0
        public static Workflow AddWorkflowProxy(this Workflow wf, string name, Workflow wfToProxy, string fromNamed = null, string fromExit = null)
        {
            var proxy = ActivityTestHelper.CreateWorkflowProxy(wfToProxy);

            proxy.Name = name;

            var proxyAs = proxy.As <WfActivity>();

            wf.AddActivity(proxyAs, fromNamed, fromExit);

            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            //string input = "";

            //   1
            //var stopwatch = new Stopwatch();
            //stopwatch.Work(input);

            //   2
            //var post = new Post("Example", "An interesting text.");
            //post.Work(input);

            //   3
            //var stack = new Stack();
            //stack.Push(1);
            //stack.Push(2);
            //stack.Push(3);
            //Console.WriteLine(stack.Pop());
            //Console.WriteLine(stack.Pop());
            //Console.WriteLine(stack.Pop());
            //Console.WriteLine(stack.Pop()); // Exception trigger

            //   4
            //var dbCommand = new DbCommand(new SqlConnection("*****@*****.**"), "Maintain");
            //dbCommand.Execute();
            //dbCommand = new DbCommand(new OracleConnection("*****@*****.**"), "Test");
            //dbCommand.Execute();

            //   5
            var workflowEngine = new WorkflowEngine();
            var workflow       = new Workflow();

            workflow.AddActivity(new SendEmail());
            workflow.AddActivity(new CallService());
            workflow.AddActivity(new UploadVideo());
            workflowEngine.Run(workflow);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Add a notify activity
        /// </summary>
        public static Workflow AddNotify(
            this Workflow wf,
            string name,
            string peopleExpression,
            string messageExpression,
            bool waitForReplies,
            Dictionary <string, Workflow> replyMap = null,
            string linkToRecordExpression          = null,
            string fromNamed = null, string fromExit = null)
        {
            var act = new NotifyActivity()
            {
                Name = name
            };
            var actAs = act.As <WfActivity>();

            if (peopleExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "People", peopleExpression);
            }

            if (messageExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Message", messageExpression);
            }

            if (linkToRecordExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Link to record", linkToRecordExpression);
            }

            AddExpressionToActivityArgument(wf, actAs, "Wait for replies", waitForReplies ? "true" : "false");
            AddExpressionToActivityArgument(wf, actAs, "Wait for", "1");

            if (replyMap != null)
            {
                foreach (var entry in replyMap)
                {
                    act.NReplyMap.Add(new ReplyMapEntry {
                        Name = entry.Key, RmeWorkflow = entry.Value
                    });
                }
            }

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 11
0
        static Workflow AddLog_imp(this Workflow wf, string name, string template, string fromNamed, string fromExit, bool isTemplate)
        {
            var log = new LogActivity
            {
                Name = name
            };
            var logAs = log.As <WfActivity>();

            AddExpressionToActivityArgument(wf, logAs, "Message", template, isTemplate);


            wf.AddActivity(logAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add a switch activity
        /// </summary>
        public static Workflow AddSwitch(this Workflow wf, string name, string switchExpression, string[] exits, string fromNamed = null, string fromExit = null)
        {
            var act = new SwitchActivity()
            {
                Name = name
            };
            var actAs = act.As <WfActivity>();

            AddExpressionToActivityArgument(wf, actAs, "Value to Switch On", switchExpression);

            AddExits(act.ExitPoints, exits);

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Add Clone activity
        /// </summary>
        public static Workflow AddClone(this Workflow wf, string name, string resourceExpression = null, string fromNamed = null, string fromExit = null)
        {
            var ca = new CloneActivity {
                Name = name
            };
            var caAs = ca.As <WfActivity>();

            if (resourceExpression != null)
            {
                AddExpressionToActivityArgument(wf, caAs, "Record", resourceExpression);
            }

            wf.AddActivity(caAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Add a delete activity
        /// </summary>
        public static Workflow AddDelete(this Workflow wf, string name, string resourceExpression = null, string fromNamed = null, string fromExit = null)
        {
            var uf = new DeleteActivity()
            {
                Name = name
            };
            var ufAs = uf.As <WfActivity>();


            if (resourceExpression != null)
            {
                ActivityTestHelper.AddExpressionToActivityArgument(wf, ufAs, "Record", resourceExpression, false);
            }

            wf.AddActivity(ufAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Add a assign to var activity
        /// </summary>
        public static Workflow AddAssignToVar(this Workflow wf, string name, string expression, string targetVarName, string fromNamed = null, string fromExit = null)
        {
            var targetVar = wf.Variables.Union(wf.OutputArguments).First(v => v.Name == targetVarName);

            var assign = new AssignToVariable()
            {
                Name           = name,
                TargetVariable = targetVar
            };
            var assignAs = assign.As <WfActivity>();

            AddExpressionToActivityArgument(wf, assignAs, "Value", expression);

            wf.AddActivity(assignAs, fromNamed, fromExit);

            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Add a foreach activity
        /// </summary>
        public static Workflow AddForEach(this Workflow wf, string name, string listExpression, EntityType listType, string fromNamed = null, string fromExit = null)
        {
            var forEach = new ForEachResource()
            {
                Name = name
            };
            var forEachAs = forEach.As <WfActivity>();

            AddExpressionToActivityArgument(wf, forEachAs, "List", listExpression);

            wf.AddActivity(forEachAs, fromNamed, fromExit);

            AddMissingExpressionParametersToWorkflow(wf);

            var resourceArgInst = forEachAs.GetOutputArgumentInstances().First(ai => ai.Name == name + "_Record");

            resourceArgInst.InstanceConformsToType = listType;

            return(wf);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Add a get records activity
        /// </summary>
        public static Workflow AddGetRecords(this Workflow wf, string name, string definitionExpression, string reportExpression = null, string fromNamed = null, string fromExit = null)
        {
            var act = new GetResourcesActivity()
            {
                Name = name
            };
            var actAs = act.As <WfActivity>();

            ActivityTestHelper.AddExpressionToActivityArgument(wf, actAs, "Object", definitionExpression, false);


            if (reportExpression != null)
            {
                ActivityTestHelper.AddExpressionToActivityArgument(wf, actAs, "Report", reportExpression, false);
            }

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fieldAliasExpressionPairs">An array of field-alias, expression pairs</param>
        public static Workflow AddUpdate(this Workflow wf, string name, string resourceExpression, string[] fieldAliasExpressionPairs,
                                         string fromNamed = null, string fromExit = null)
        {
            var update = new UpdateFieldActivity()
            {
                Name = name
            };
            var updateAs = update.As <WfActivity>();

            ActivityTestHelper.AddExpressionToActivityArgument(wf, updateAs, "Record", resourceExpression, false);

            wf.AddActivity(updateAs, fromNamed, fromExit);

            var count = 0;

            for (int i = 0; i < fieldAliasExpressionPairs.Count(); i += 2)
            {
                var argName      = "input" + count++;
                var argValueName = argName + "_value";

                var result1 = (new StringArgument()
                {
                    Name = argName
                }).As <ActivityArgument>();;
                update.InputArguments.Add(result1);
                AddExpressionToActivityArgument(wf, updateAs, argName, fieldAliasExpressionPairs[i]);

                var result2 = (new ObjectArgument {
                    Name = argValueName
                }).As <ActivityArgument>();
                update.InputArguments.Add(result2);
                AddExpressionToActivityArgument(wf, updateAs, argValueName, fieldAliasExpressionPairs[i + 1]);
            }

            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Add display form with an exit point called "First Exit" that is the default;
        /// </summary>
        public static Workflow AddStartSurvey(
            this Workflow wf,
            string name,
            string campaignExpression,
            string fromNamed = null,
            string fromExit  = null)
        {
            var act = new StartSurveyActivity
            {
                Name = name
            };
            var actAs = act.As <WfActivity>();

            if (campaignExpression != null)
            {
                AddExpressionToActivityArgument(wf, actAs, "Campaign", campaignExpression);
            }

            wf.AddActivity(actAs, fromNamed, fromExit);
            AddMissingExpressionParametersToWorkflow(wf);

            return(wf);
        }
Ejemplo n.º 20
0
        public void TestMultipleNestedWorkflowActivities_Bug_24928()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                Workflow wfA = null, wfB = null, wfC = null, wfD = null;

                #region Arrange
                var exitA = Entity.Create <ExitPoint>();
                exitA.Name = "TEST Exit A";
                exitA.IsDefaultExitPoint = true;
                exitA.Save();

                var exitB = Entity.Create <ExitPoint>();
                exitB.Name = "TEST Exit B";
                exitB.IsDefaultExitPoint = true;
                exitB.Save();

                var exitC = Entity.Create <ExitPoint>();
                exitC.Name = "TEST Exit C";
                exitC.IsDefaultExitPoint = true;
                exitC.Save();

                var exitD = Entity.Create <ExitPoint>();
                exitD.Name = "TEST Exit D";
                exitD.IsDefaultExitPoint = true;
                exitD.Save();

                wfA      = Entity.Create <Workflow>();
                wfA.Name = "TEST WF A";
                wfA.ExitPoints.Add(exitA);

                var logA = Entity.Create <LogActivity>().As <WfActivity>();
                logA.Name = "TEST Log A";
                wfA.AddActivity(logA);

                ActivityTestHelper.AddExpressionToActivityArgument(wfA, logA, "Message", "'WF A'");
                wfA.Save();

                wfB      = Entity.Create <Workflow>();
                wfB.Name = "TEST WF B";
                wfB.ExitPoints.Add(exitB);

                var logB = Entity.Create <LogActivity>().As <WfActivity>();
                logB.Name = "TEST Log B";
                wfB.AddActivity(logB);

                ActivityTestHelper.AddExpressionToActivityArgument(wfB, logB, "Message", "'WF B'");
                wfB.Save();

                wfC      = Entity.Create <Workflow>();
                wfC.Name = "TEST WF C";
                wfC.ExitPoints.Add(exitC);

                var proxyA = Entity.Create <WorkflowProxy>();
                proxyA.Name            = "TEST Run WF A";
                proxyA.WorkflowToProxy = wfA;
                var exitProxyA = Entity.Create <ExitPoint>();
                exitProxyA.Name = "TEST Exit A";
                exitProxyA.IsDefaultExitPoint = true;
                proxyA.ExitPoints.Add(exitProxyA);
                wfC.AddActivity(proxyA.As <WfActivity>());

                var logCa = Entity.Create <LogActivity>().As <WfActivity>();
                logCa.Name = "TEST Log C A";
                wfC.AddActivity(logCa);

                ActivityTestHelper.AddExpressionToActivityArgument(wfC, logCa, "Message", "'WF C A'");

                var proxyB = Entity.Create <WorkflowProxy>();
                proxyB.Name            = "TEST Run WF B";
                proxyB.WorkflowToProxy = wfB;
                var exitProxyB = Entity.Create <ExitPoint>();
                exitProxyB.Name = "TEST Exit B";
                exitProxyB.IsDefaultExitPoint = true;
                proxyB.ExitPoints.Add(exitProxyB);
                wfC.AddActivity(proxyB.As <WfActivity>());

                var logCb = Entity.Create <LogActivity>().As <WfActivity>();
                logCb.Name = "TEST Log C B";
                wfC.AddActivity(logCb);

                ActivityTestHelper.AddExpressionToActivityArgument(wfC, logCb, "Message", "'WF C B'");
                wfC.Save();

                wfD      = Entity.Create <Workflow>();
                wfD.Name = "TEST WF D";
                wfD.ExitPoints.Add(exitD);

                var proxyA2 = Entity.Create <WorkflowProxy>();
                proxyA2.Name            = "TEST Run WF A";
                proxyA2.WorkflowToProxy = wfA;
                var exitProxyA2 = Entity.Create <ExitPoint>();
                exitProxyA2.Name = "TEST Exit A";
                exitProxyA2.IsDefaultExitPoint = true;
                proxyA2.ExitPoints.Add(exitProxyA2);
                wfD.AddActivity(proxyA2.As <WfActivity>());

                var logDa = Entity.Create <LogActivity>().As <WfActivity>();
                logDa.Name = "TEST Log D A";
                wfD.AddActivity(logDa);

                ActivityTestHelper.AddExpressionToActivityArgument(wfD, logDa, "Message", "'WF D A'");

                var proxyB2 = Entity.Create <WorkflowProxy>();
                proxyB2.Name            = "TEST Run WF B";
                proxyB2.WorkflowToProxy = wfB;
                var exitProxyB2 = Entity.Create <ExitPoint>();
                exitProxyB2.Name = "TEST Exit B";
                exitProxyB2.IsDefaultExitPoint = true;
                proxyB2.ExitPoints.Add(exitProxyB2);
                wfD.AddActivity(proxyB2.As <WfActivity>());

                var logDb = Entity.Create <LogActivity>().As <WfActivity>();
                logDb.Name = "TEST Log D B";
                wfD.AddActivity(logDb);

                ActivityTestHelper.AddExpressionToActivityArgument(wfD, logDb, "Message", "'WF D B'");

                var proxyC = Entity.Create <WorkflowProxy>();
                proxyC.Name            = "TEST Run D C";
                proxyC.WorkflowToProxy = wfC;
                var exitProxyC = Entity.Create <ExitPoint>();
                exitProxyC.Name = "TEST Exit C";
                exitProxyC.IsDefaultExitPoint = true;
                proxyC.ExitPoints.Add(exitProxyC);
                wfD.AddActivity(proxyC.As <WfActivity>());

                var logDc = Entity.Create <LogActivity>().As <WfActivity>();
                logDc.Name = "TEST Log D C";
                wfD.AddActivity(logDc);

                ActivityTestHelper.AddExpressionToActivityArgument(wfD, logDc, "Message", "'WF D C'");
                wfD.Save();
                #endregion

                // Act
                WorkflowRun run;
                using (new WorkflowRunContext(true))
                {
                    run = RunWorkflow(wfD);
                }

                // Assert
                run.Should().NotBeNull();
                run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunCompleted);
                run.Id.Should().Be(run.Id);
                run.RunStepCounter.Should().Be(7);
            }
        }
        public void EditPausedWorkflowUnderHobbledSecurityAccount_Bug_25246()
        {
            Workflow wf = null, wfClone = null;

            try
            {
                #region Arrange
                var dogBreedType = Entity.GetByName <EntityType>("AA_DogBreeds").FirstOrDefault();
                dogBreedType.Should().NotBeNull("Couldn't locate the type for dog breeds.");

                var poodle = Entity.GetByName("Poodle").FirstOrDefault();
                poodle.Should().NotBeNull("Couldn't locate poodle.");

                wf      = Entity.Create <Workflow>();
                wf.Name = "Pet the poodle.";
                wf.AddDefaultExitPoint();
                wf.AddInput <ResourceArgument>("Input", dogBreedType);
                wf.InputArgumentForAction = wf.InputArguments.First();

                var i = Entity.Create <WfExpression>();
                i.ArgumentToPopulate = wf.InputArgumentForAction;
                wf.ExpressionMap     = new EntityCollection <WfExpression> {
                    i
                };
                wf.InputArgumentForAction.PopulatedByExpression = new EntityCollection <WfExpression> {
                    i
                };

                var exitPoint = Entity.Create <ExitPoint>();
                exitPoint.Name = "Pet";
                exitPoint.IsDefaultExitPoint = true;
                exitPoint.Save();

                var userAction = Entity.Create <DisplayFormActivity>();
                userAction.Name = "Do Action";
                userAction.ExitPoints.Add(exitPoint);

                var act = userAction.As <WfActivity>();
                wf.AddActivity(act);

                ActivityTestHelper.AddExpressionToActivityArgument(wf, act, "Record", "[Input]");
                ActivityTestHelper.AddEntityExpression(wf, act, act.GetInputArgument("For Person"), new EntityRef("core", "administratorPerson"));
                act.Save();

                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

                wf.Save();
                #endregion

                // Act
                using (new SetUser(Entity.Get <UserAccount>("core:administratorUserAccount")))
                {
                    // Hobbled.

                    var wfInput = new Dictionary <string, object> {
                        { "Input", poodle }
                    };

                    var run = RunWorkflow(wf, wfInput);

                    run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                    run.PendingActivity.Should().NotBeNull();
                    run.PendingActivity.Name.Should().Be("Do Action");
                    run.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    run.WorkflowBeingRun.Should().NotBeNull();
                    run.WorkflowBeingRun.FirstActivity.Should().NotBeNull();
                    run.WorkflowBeingRun.RunningInstances.Should().NotBeNull();
                    run.WorkflowBeingRun.RunningInstances.Count.Should().Be(1);

                    // Edit
                    WorkflowUpdateHelper.Update(wf.Id, () =>
                    {
                        var wfEdit         = Entity.Get <Workflow>(wf.Id, true).AsWritable <Workflow>();
                        wfEdit.Description = "What?";

                        var actEdit   = wfEdit.FirstActivity.AsWritable <WfActivity>();
                        actEdit.Name += "2";
                        actEdit.Save();

                        wfEdit.Save();
                    });

                    // Assert
                    var wfOriginal = Entity.Get <Workflow>(wf.Id);
                    wfOriginal.Should().NotBeNull();
                    wfOriginal.Description.Should().Be("What?");
                    wfOriginal.FirstActivity.Should().NotBeNull();
                    wfOriginal.FirstActivity.Name.Should().Be("Do Action2"); // i guess?
                    wfOriginal.RunningInstances.Should().NotBeNull().And.BeEmpty();
                    wfOriginal.WfOlderVersion.Should().NotBeNull();
                    wfOriginal.WfNewerVersion.Should().BeNull();

                    wfClone = wfOriginal.WfOlderVersion;
                    wfClone.Description.Should().BeNullOrEmpty();
                    wfClone.FirstActivity.Should().NotBeNull();
                    wfClone.FirstActivity.Name.Should().Be("Do Action");
                    wfClone.RunningInstances.Should().NotBeNull();
                    wfClone.RunningInstances.Count.Should().Be(1);
                }
            }
            finally
            {
                if (wf != null)
                {
                    ToDelete.Add(wf.Id);
                }
                if (wfClone != null)
                {
                    ToDelete.Add(wfClone.Id);
                }
            }
        }
Ejemplo n.º 22
0
        public void TestDisplayFormDeleteInputParameter_Bug_25116()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                IEntity  driver = null;
                Workflow wf     = null;

                try
                {
                    WorkflowRun run, run2;


                    #region Arrange
                    var driverType = new EntityRef("test", "driver");

                    driver = Entity.Create(driverType);
                    driver.SetField("core:name", "Test Delete Driver");
                    driver.Save();

                    wf      = Entity.Create <Workflow>();
                    wf.Name = "TEST WF";
                    wf.AddDefaultExitPoint();
                    wf.AddInput <ResourceArgument>("Input", Entity.Get <EntityType>(driverType));
                    wf.InputArgumentForAction = wf.InputArguments.First();

                    var i = Entity.Create <WfExpression>();
                    i.ArgumentToPopulate = wf.InputArgumentForAction;
                    wf.ExpressionMap     = new EntityCollection <WfExpression> {
                        i
                    };
                    wf.InputArgumentForAction.PopulatedByExpression = new EntityCollection <WfExpression> {
                        i
                    };

                    var uAExitA = Entity.Create <ExitPoint>();
                    uAExitA.Name = "Exit A";
                    uAExitA.ExitPointActionSummary = "Exit A action summary";
                    uAExitA.IsDefaultExitPoint     = true;
                    uAExitA.Save();

                    var userActionA = Entity.Create <DisplayFormActivity>();
                    userActionA.Name = "A";
                    userActionA.ExitPoints.Add(uAExitA);

                    var uA = userActionA.As <WfActivity>();
                    wf.AddActivity(uA);

                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Record", "[Input]");
                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Wait for next form", "true");
                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Hide comment field", "true");
                    ActivityTestHelper.AddExpressionToActivityArgument(wf, uA, "Record history", "false");
                    ActivityTestHelper.AddEntityExpression(wf, uA, uA.GetInputArgument("For Person"), new EntityRef("core", "administratorPerson"));
                    ActivityTestHelper.AddEntityExpression(wf, uA, uA.GetInputArgument("Form"), new EntityRef("test", "personForm"));
                    uA.Save();

                    var delete = Entity.Create <DeleteActivity>();
                    delete.Name = "Delete";

                    var d = delete.As <WfActivity>();
                    wf.AddActivity(d);

                    ActivityTestHelper.AddExpressionToActivityArgument(wf, d, "Record", "[Input]");
                    d.Save();

                    var uBExitC = Entity.Create <ExitPoint>();
                    uBExitC.Name = "Exit C";
                    uBExitC.ExitPointActionSummary = "Exit C action summary";
                    uBExitC.IsDefaultExitPoint     = true;
                    uBExitC.Save();

                    var userActionB = Entity.Create <DisplayFormActivity>();
                    userActionB.Name = "B";
                    userActionB.ExitPoints.Add(uBExitC);

                    var uB = userActionB.As <WfActivity>();
                    wf.AddActivity(uB);

                    ActivityTestHelper.AddEntityExpression(wf, uB, uB.GetInputArgument("For Person"), new EntityRef("core", "administratorPerson"));
                    uB.Save();

                    ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);

                    wf.Save();
                    #endregion

                    // Act
                    var wfInput = new Dictionary <string, object> {
                        { "Input", driver }
                    };

                    using (new WorkflowRunContext(true))
                    {
                        run = RunWorkflow(wf, wfInput);
                    }
                    run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                    run.PendingActivity.Should().NotBeNull();
                    run.PendingActivity.Name.Should().Be("A");
                    run.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    var userTaskA = run.TaskWithinWorkflowRun.First().AsWritable <DisplayFormUserTask>();
                    userTaskA.AvailableTransitions.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);
                    userTaskA.WorkflowRunForTask.Id.Should().Be(run.Id);

                    var resumeEvent = new UserCompletesTaskEvent
                    {
                        CompletionStateId = userTaskA.AvailableTransitions.First(t => t.Name == "Exit A").Id,
                        UserTaskId        = run.TaskWithinWorkflowRun.First().Id
                    };

                    using (new WorkflowRunContext(true))
                    {
                        run2 = WorkflowRunner.Instance.ResumeWorkflow(run, resumeEvent);
                    }

                    // Assert
                    run2.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                    run2.PendingActivity.Should().NotBeNull();
                    run2.PendingActivity.Name.Should().Be("B");
                    run2.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    var deletedDriver = Entity.Exists(new EntityRef(driver.Id));
                    deletedDriver.Should().BeFalse();
                }
                finally
                {
                    if (wf != null)
                    {
                        ToDelete.Add(wf.Id);
                    }
                    if (driver != null && Entity.Exists(new EntityRef(driver.Id)))
                    {
                        ToDelete.Add(driver.Id);
                    }
                }
            }
        }
Ejemplo n.º 23
0
        public void TestPromptActivityLowSecurityUser_Bug_27134()
        {
            Workflow       wf = null;
            PromptUserTask p  = null;

            try
            {
                // Arrange
                var dummyPerson = Entity.Create <Person>();
                dummyPerson.Name      = "Dummy Person" + DateTime.Now + Rand.Next();
                dummyPerson.FirstName = "Dummy";
                dummyPerson.LastName  = "Dummy";
                dummyPerson.Save();

                var dummyAccount = Entity.Create <UserAccount>();
                dummyAccount.Name          = "Dummy" + DateTime.Now + Rand.Next();
                dummyAccount.AccountHolder = dummyPerson;
                dummyAccount.Save();

                wf      = Entity.Create <Workflow>();
                wf.Name = "Test User Input Workflow" + DateTime.Now + Rand.Next();
                //wf.WorkflowRunAsOwner = true;
                //wf.SecurityOwner = dummyAccount;
                wf.AddWfExitPoint("Test User Input Workflow Exit Point", true);
                wf.AddInput <ResourceArgument>("input", Resource.Resource_Type);

                var act = Entity.Create <PromptUserActivity>();
                act.Name = "Test User Input" + DateTime.Now + Rand.Next();
                act.PromptForArguments.Add(new ActivityPrompt {
                    Name = "input", ActivityPromptArgument = wf.InputArguments.First()
                });
                var actAs = act.Cast <WfActivity>();

                wf.AddActivity(actAs);
                wf.AddEntityExpressionToInputArgument(actAs, "For Person", dummyPerson);
                wf.Save();

                // Act
                WorkflowRun run;
                using (new WorkflowRunContext {
                    RunTriggersInCurrentThread = true
                })
                {
                    run = RunWorkflow(wf);
                }

                // Assert
                run.WorkflowRunStatus_Enum.Should().Be(WorkflowRunState_Enumeration.WorkflowRunPaused);
                run.PendingActivity.Should().NotBeNull();
                run.PendingActivity.Name.Should().Be(act.Name);
                run.TaskWithinWorkflowRun.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                var task = run.TaskWithinWorkflowRun.FirstOrDefault();
                task.Should().NotBeNull();

                using (new SetUser(dummyAccount))
                {
                    p = Entity.Get <PromptUserTask>(task.Id);
                    p.Should().NotBeNull();

                    p.PromptForTaskArguments.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1);

                    var arg = p.PromptForTaskArguments.First();
                    arg.ActivityPromptArgument.Should().NotBeNull();
                    arg.ActivityPromptArgument.Name.Should().Be("input");
                }
            }
            finally
            {
                if (p != null)
                {
                    ToDelete.Add(p.Id);
                }
                if (wf != null)
                {
                    ToDelete.Add(wf.Id);
                }
            }
        }