who knows how to get the reference to workflowruntime in the customerAcitiviy?  
Author Message
zppro





PostPosted: Windows Workflow Foundation, who knows how to get the reference to workflowruntime in the customerAcitiviy? Top

I write a local service to like this

-----------------------------------------------------------------------------------------------------

Imports System.Workflow.Activities

<Serializable()> _
Public Class DocService
Implements IDocService


Public Sub RaiseDocCanceled(ByVal xDocumentContext As IDocument)

Dim e As New DocEventArgs(xDocumentContext)
RaiseEvent DocCanceled(Me, e)

End Sub

Public Sub RaiseDocCompleted(ByVal xDocumentContext As IDocument)

Dim e As New DocEventArgs(xDocumentContext)
RaiseEvent DocCompleted(Me, e)

End Sub

Public Sub RaiseDocCreated(ByVal xDocumentContext As IDocument)

Dim e As New DocEventArgs(xDocumentContext)
RaiseEvent DocCreated(Me, e)

End Sub

Public Sub RaiseDocReadying(ByVal xDocumentContext As IDocument)

Dim e As New DocEventArgs(xDocumentContext)
RaiseEvent DocReadying(Me, e)

End Sub

Public Sub RaiseDocSuspended(ByVal xDocumentContext As IDocument)

Dim e As New DocEventArgs(xDocumentContext)
RaiseEvent DocSuspended(Me, e)

End Sub

Public Sub RaiseDocTerminated(ByVal xDocumentContext As IDocument)

Dim e As New DocEventArgs(xDocumentContext)
RaiseEvent DocTerminated(Me, e)

End Sub

Public Sub RaiseDocTransfered(ByVal xDocumentContext As IDocument)

Dim e As New DocEventArgs(xDocumentContext)
RaiseEvent DocTransfered(Me, e)

End Sub

Public Event DocCanceled(ByVal sender As Object, ByVal e As DocEventArgs) Implements IDocService.DocCanceled

Public Event DocCompleted(ByVal sender As Object, ByVal e As DocEventArgs) Implements IDocService.DocCompleted

Public Event DocCreated(ByVal sender As Object, ByVal e As DocEventArgs) Implements IDocService.DocCreated

Public Event DocReadying(ByVal sender As Object, ByVal e As DocEventArgs) Implements IDocService.DocReadying

Public Event DocSuspended(ByVal sender As Object, ByVal e As DocEventArgs) Implements IDocService.DocSuspended

Public Event DocTerminated(ByVal sender As Object, ByVal e As DocEventArgs) Implements IDocService.DocTerminated

Public Event DocTransfered(ByVal sender As Object, ByVal e As DocEventArgs) Implements IDocService.DocTransfered
End Class

-----------------------------------------------------------------------------------------------------

Public Interface IDocument

''' <summary>
''' 文 --
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Property DocId() As Guid

''' <summary>
''' 工作流 例
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Property InstanceId() As Guid

''' <summary>
''' 工作流模型
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Property WorkflowId() As Guid

''' <summary>
''' 自定 据
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Function GetCustomerData() As IDictionary(Of String, Object)

End Interface

------------------------------------------------------------------------------------------------------

Imports System.Workflow.Activities

<Serializable()> _
Public Class DocEventArgs
Inherits ExternalDataEventArgs


Private _IDocumentInstance As IDocument

Public ReadOnly Property TheDoc() As IDocument
Get
Return _IDocumentInstance
End Get
End Property

Public Sub New(ByVal IDocumentInstance As IDocument)
MyBase.New(IDocumentInstance.InstanceId)
_IDocumentInstance = IDocumentInstance
End Sub

End Class

----------------------------------------------------------------------------------------------------

Public Class BaseWorkflow
Inherits StateMachineWorkflowActivity
Public Sub New()
MyBase.New()
InitializeComponent()

'here i want get the workflowruntime to load the object ---workflowinstance

End Sub


End Class

------------------------------------------------------------------------------------------------------

i can get this in host application but not in workflowlibrary

so how can i get this workflowruntime



Software Development for Windows Vista16  
 
 
zppro





PostPosted: Windows Workflow Foundation, who knows how to get the reference to workflowruntime in the customerAcitiviy? Top

ok ,I found :

Public Class BaseWorkflow
Inherits StateMachineWorkflowActivity
Public Sub New()
MyBase.New()
InitializeComponent()

End Sub

Public Sub codeActivity_ExecuteCode(ByVal sender As Object, ByVal e As EventArgs)
If (Runtime IsNot Nothing) Then
Console.WriteLine("get runtime")
Else
Console.WriteLine("not get runtime")
End If
End Sub


Private _workflowruntime As Workflow.Runtime.WorkflowRuntime

Public Property Runtime() As WorkflowRuntime
Get
Return _workflowruntime
End Get
Set(ByVal value As WorkflowRuntime)
_workflowruntime = value
End Set
End Property

End Class

-------------------------------------

Module Module1
Class Program

Shared WaitHandle As New AutoResetEvent(False)

Shared Sub Main()
Using workflowRuntime As New WorkflowRuntime()
AddHandler workflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted
AddHandler workflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated

Dim workflowInstance As WorkflowInstance
Dim parameters As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
parameters.Add("Runtime", workflowRuntime)
workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parameters)
workflowInstance.Start()

WaitHandle.WaitOne()
End Using
End Sub

Shared Sub OnWorkflowCompleted(ByVal sender As Object, ByVal e As WorkflowCompletedEventArgs)
WaitHandle.Set()
End Sub

Shared Sub OnWorkflowTerminated(ByVal sender As Object, ByVal e As WorkflowTerminatedEventArgs)
Console.WriteLine(e.Exception.Message)
WaitHandle.Set()
End Sub

End Class
End Module


 
 
Serge Luca





PostPosted: Windows Workflow Foundation, who knows how to get the reference to workflowruntime in the customerAcitiviy? Top

Pay attention to Paul post, however :

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=311606&SiteID=1

 
 
Tom Lake





PostPosted: Windows Workflow Foundation, who knows how to get the reference to workflowruntime in the customerAcitiviy? Top

You should not be passing the workflow runtime as a parameter to a workflow. Also, it is not serializable so you won't be able to use persistence. Why do you think you need the workflow instance from within the workflow Can you describe your scenario a little more