R__Rennie
I think I might have found a way around this, and maybe this can be updated in the InputActivity, but I did it in my derivative in any event. Please let me know if this is not the "right" way. My case is, specifically, I have a Dictionary<Guid,Subscription> in my local service which records a subscription id -> (workflow instance id, queuename) mapping. On Execute(), my custom InputActivity derivative registers as a listener with the local service. Thus, if the local service (i.e. the host) is shut down and then restarted, the InputActivity stops working because my external event is not reset.
To fix this, I simply overrode the OnActivityExecutionContextLoad() method in my custom InputActivity (i.e. in the derivative) and then reregistered as a listener based on the activity's ExecutionStatus and EventSubscriptionId. Since EventSubscriptionId is set when the listener is registered, this is used to check if we need to reregister. Note, this also required fixing the UnregisterListener in the InputActivity derivative.
InputActivity derivative code:
private void UnregisterListener(ActivityExecutionContext context)
{
MyWorkflowService wfService = context.GetService<MyWorkflowService>();
wfService.UnregisterListener(this.EventSubscriptionId);
this.EventSubscriptionId = Guid.Empty;
}
protected override void OnActivityExecutionContextLoad(IServiceProvider provider)
{
base.OnActivityExecutionContextLoad(provider);
if (ExecutionStatus == ActivityExecutionStatus.Executing ||
ExecutionStatus == ActivityExecutionStatus.Initialized )
{
MyWorkflowService wfService =
(MyWorkflowService)provider.GetService(typeof(MyWorkflowService));
if (wfService == null)
throw new ApplicationException("MyWorkflowService is not available.");
wfService.ReregisterListener(this.EventSubscriptionId, this.WorkflowInstanceId, this.QueueName);
}
}
Then, "ReregisterListener" in the localservice checks to see if the event subscription id is not already registered and is not Guid.Empty, and will reregister it if both are (i.e. not) true.
So, it's basically the same as the "SubscribeExternalEvent()" method, except IServiceProvider is used instead of the execution context.