Custom Activities -- Event activity not invoking other event activity?

Topics: Core, Customizing Orchard, Writing modules
Dec 9, 2014 at 6:33 AM
I have created two Event Activities A and B. Both linked in workflow such that when the first activity "Execute()" method executes it is suppose to call or invoke the following activity B. But it does not. If I convert activity B to Task Activity, I works fine.

Also, If I attach my activity A with "UserTask" Activity, which is also an event activty, it works fine.

Thanks
Developer
Dec 9, 2014 at 7:42 AM
Could you share some code to show us how you're invoking Activity B?
Dec 9, 2014 at 9:29 AM
Edited Dec 9, 2014 at 9:29 AM
I am simply calling Yeild return T("Done") at the end of the Execute() method. The same activity is working fine when attached to "UserTaskActivity". But with my activity its not working.
public class CustomContentActivity : ContentActivity
    {
        public CustomContentActivity()
        {
            
        }

        public override string Name
        {
            get { return "XXXXX"; }
        }

        public override LocalizedString Description
        {
            get { return T("description"); }
        }

        public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext,
                                                              ActivityContext activityContext)
        {
           // some code here 
           // and done

            yield return T("Done");
        }
    }
Thanks
Developer
Dec 9, 2014 at 9:41 AM
I think that explains it all. If the next activity in the workflow is an Event, your workflow will be suspended until that event is triggered.
Dec 9, 2014 at 10:16 AM
Edited Dec 9, 2014 at 10:18 AM
Yes, it makes sense. But if you see "User Task" activity, it is also an event. If you place "User Task" activity right after any Content Event Activity like Content Created, Content Updated activities, the "User Task" activity is executed just fine. And, so it does with my CustomContentActivity.

The activity which I am trying to execute after the above give activity is as follows:
public class MySecondCustomActivity : Event
    {
       public MySecondCustomActivity ()
        {
            T = NullLocalizer.Instance;
         
        }

        public Localizer T { get; set; }

        public override bool CanStartWorkflow
        {
            get { return true; }
        }

        public override string Name
        {
            get
            {
                return "XXXXXXX";
            }
        }

        public override LocalizedString Category
        {
            get
            {
                return T("XXXX XXXX");
            }
        }

        public override LocalizedString Description
        {
            get
            {
                return T("Description");
            }
        }        

        public override string Form
        {
            get
            {
                return "FormName";
            }
        }

        public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext)
        {
            return new[] { T("One"), T("Two"), T("Three") };
        }

        public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext)
        {
            return true;
        }

        public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
        {
           // some code here
    
       if(condition)
        yeild return T("One")

            yeild return T("Two")
        }
    }
Thanks
Developer
Dec 9, 2014 at 10:34 AM
I'm afraid you're mistaken. The "User Task" activity is only executed after the user clicks on any of the buttons as configured for that activity. Clicking any such button will trigger an event, which causes your suspended workflow to resume execution.

In your case, you will have to do the same: when workflow execution enters an event activity, execution will be suspended. Only when the event is triggered will your workflow resume execution.

So, if your event activity is named "XXXXXXX", you will need to do something like:
// Triggering the "XXXXXXX" event will cause your suspended workflow to resume execution.
_workflowManager.TriggerEvent("XXXXXXX", () => { /*Provide any additional data specific to your event*/ });
If you look at UserTaskDriver.cs in the Orchard.Roles module, you'll see how it resumes workflows containing the "User Task" activity:
_workflowManager.TriggerEvent("UserTask", part, () => new Dictionary<string, object> { { "Content", part.ContentItem}, { "UserTask.Action", name } });
Hope this helps.
Marked as answer by cloudsurfer on 12/9/2014 at 3:15 AM