I have created a custom activity implementing IActivityEventListener
interface. Then a EventArgs derived class which delivers the queue message.
Then, from host application I send a queue item to the workflow calling the workflowinstance's EnqueueItem method : how can I intercept the message in the OnEvent method instead of Execute method
I have also tried to create the custom activity as IEventActivity to be hosted inside an EventDrivent one, but the effect is still the same: only Execute method is called when message is received.
Thank you very much in advance.

IActivityEventListener custom activity
Terry Smith
Zafar Ullah
Great!
BioGeek
The following show how to combine both IEventActivity and IActivityEventListener
Public Class Activity1
Inherits Activity
Implements IEventActivity, IActivityEventListener(Of QueueEventArgs)
Public Sub OnEvent(ByVal sender As Object, ByVal e As QueueEventArgs) Implements IActivityEventListener(Of QueueEventArgs).OnEvent
Dim executionContext As ActivityExecutionContext = CType(sender, ActivityExecutionContext)
Dim wqs As WorkflowQueuingService = executionContext.GetService(Of WorkflowQueuingService)()
Dim queue As WorkflowQueue = wqs.GetWorkflowQueue(QueueName)
Dim item As Object = queue.Dequeue()
' ToDo: Implement
executionContext.CloseActivity()
End Sub
Protected Overrides Function Execute(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
Dim status As ActivityExecutionStatus
If IsInEventActivityMode Then
status = ActivityExecutionStatus.Closed
Else
InternalSubscribe(executionContext, Me, False)
status = ActivityExecutionStatus.Executing
End If
Return status
End Function
Public ReadOnly Property QueueName() As IComparable Implements IEventActivity.QueueName
Get
Return "MyQueueName"
End Get
End Property
Public Sub Subscribe(ByVal parentContext As ActivityExecutionContext, ByVal parentEventHandler As IActivityEventListener(Of QueueEventArgs)) Implements IEventActivity.Subscribe
InternalSubscribe(parentContext, parentEventHandler, True)
End Sub
Public Sub Unsubscribe(ByVal parentContext As ActivityExecutionContext, ByVal parentEventHandler As IActivityEventListener(Of QueueEventArgs)) Implements IEventActivity.Unsubscribe
End Sub
Private Sub InternalSubscribe(ByVal executionContext As ActivityExecutionContext, ByVal eventHandler As IActivityEventListener(Of QueueEventArgs), ByVal eventActivityMode As Boolean)
Dim wqs As WorkflowQueuingService = executionContext.GetService(Of WorkflowQueuingService)()
Dim queue As WorkflowQueue = wqs.CreateWorkflowQueue(QueueName, True)
queue.RegisterForQueueItemAvailable(eventHandler, QualifiedName)
IsInEventActivityMode = eventActivityMode
End Sub
Public Shared IsInEventActivityModeProperty As DependencyProperty = DependencyProperty.Register("IsInEventActivityMode", GetType(Boolean), GetType(Activity1))
<Description("This is the description which appears in the Property Browser")> _
<Category("This is the category which will be displayed in the Property Browser")> _
<Browsable(True)> _
<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property IsInEventActivityMode() As Boolean
Get
Return (CType((MyBase.GetValue(Activity1.IsInEventActivityModeProperty)), Boolean))
End Get
Set(ByVal Value As Boolean)
MyBase.SetValue(Activity1.IsInEventActivityModeProperty, Value)
End Set
End Property
End Class
Maurice
cgraus
Public class Activity1
Inherits Activity
Implements IActivityEventListener(Of QueueEventArgs)
Public Sub OnEvent(ByVal sender As Object, ByVal e As System.Workflow.ComponentModel.QueueEventArgs) Implements System.Workflow.ComponentModel.IActivityEventListener(Of System.Workflow.ComponentModel.QueueEventArgs).OnEvent
Dim context As ActivityExecutionContext
context = CType(sender, ActivityExecutionContext)
context.CloseActivity()
End Sub
Protected Overrides Sub Initialize(ByVal provider As System.IServiceProvider)
Dim context As ActivityExecutionContext
context = CType(provider, ActivityExecutionContext)
Dim wqs As WorkflowQueuingService = context.GetService(Of WorkflowQueuingService)()
Dim queue As WorkflowQueue = wqs.CreateWorkflowQueue("MyQueueName", True)
queue.RegisterForQueueItemAvailable(Me, QualifiedName)
MyBase.Initialize(provider)
End Sub
Protected Overrides Function Execute(ByVal executionContext As System.Workflow.ComponentModel.ActivityExecutionContext) As System.Workflow.ComponentModel.ActivityExecutionStatus
Return ActivityExecutionStatus.Executing
End Function
End Class
Maurice
claydevin
I have followed your example, but the workflow designer doesn't permit me to drag and drop this activity like a normal code activity. How can I do that
Thank you!
Nick__A.
Exposing the custom activity also as IEventActivity:
i.e.
public partial class MyEventActivity: Activity, IEventActivity, IActivityEventListener<QueueEventArgs>
{
...
}
is there a similar way to pass throught the OnEvent method once the event is pushed into the workflow queue
Thank you!
clint 2
I can drag the activity just fine from the toolbox into the workflow and once there move it around using drag and drop.
Maurice
WXS123
Maurice