コード例 #1
0
        /// <summary>
        /// Start the activity running
        /// </summary>
        /// <returns>True if the activity has completed, false if it is paused. Along with a sequence number of if it is paused</returns>
        public override bool OnStart(IRunState context, ActivityInputs inputs)
        {
            var assignedTo         = GetArgumentEntity <Person>(inputs, "inPromptUserForPerson");
            var promptMessage      = GetArgumentValue <string>(inputs, "inPromptUserMessage");
            var activityInstanceAs = ActivityInstance.Cast <PromptUserActivity>();

            var userTask = new PromptUserTask
            {
                Name                   = ActivityInstance.Name ?? "User input required",
                AssignedToUser         = assignedTo,
                TaskStatus_Enum        = TaskStatusEnum_Enumeration.TaskStatusNotStarted,
                UserTaskDueOn          = DateTime.UtcNow, // dueDate
                KeepAfterCompletion    = false,           // keepTask
                WaitForNextTask        = true,            // waitForNext
                PromptForTaskMessage   = promptMessage,
                PromptForTaskArguments = new EntityCollection <ActivityPrompt>(activityInstanceAs.PromptForArguments)
            };

            // move current state information on to the task for pre-population of any arguments for prompt
            var argValues = context.GetArgValues().ToList();

            foreach (var arg in activityInstanceAs.PromptForArguments)
            {
                var argValue = argValues.FirstOrDefault(a => a.Item2.Id == arg.ActivityPromptArgument.Id);
                if (argValue != null)
                {
                    var valueArg = ActivityArgumentHelper.ConvertArgInstValue(argValue.Item1, argValue.Item2, argValue.Item3);
                    userTask.PromptForTaskStateInfo.Add(new StateInfoEntry
                    {
                        Name = valueArg.Name,
                        StateInfoActivity = ActivityInstance,
                        StateInfoArgument = argValue.Item2,
                        StateInfoValue    = valueArg
                    });

                    continue;
                }

                var emptyArg = ActivityArgumentHelper.ConvertArgInstValue(ActivityInstance, arg.ActivityPromptArgument, null);
                userTask.PromptForTaskStateInfo.Add(new StateInfoEntry
                {
                    Name = emptyArg.Name,
                    StateInfoActivity = ActivityInstance,
                    StateInfoArgument = arg.ActivityPromptArgument,
                    StateInfoValue    = emptyArg
                });
            }

            context.SetUserTask(userTask.Cast <BaseUserTask>());

            return(false);
        }