简体   繁体   中英

.NET - Workflow, End-User Diagrams, Reflection

Are there any tools which can reflect over Windows Workflow or SharePoint Workflow assemblies and generate a .png or some other image type to present to a user? Dynmically via ASP.NET? Or if there isn't anything like this... how do you provide documentation / end-user documentation?

I would be interested in free or non-free tools.

`Depending on your needs/desires there are several ways using the workflow designer.

First of all you can save an image of the workflow using one of the menus. This is rather static and something you need to do at design time.

More flexible is the option to rehost the workflow designer in your app and generate the image on the fly. The code below is from a console app but I have done the same inside of ASP.NET. The main issue is that the designer was created for use in Visual Studio which runs in everything in an MTA thread whereas ASP.NET uses STA threads. Just create a new MTA thread, execute the code and wait for it to be finished in the main ASP.NET STA thread and you are good to go.

Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.
Imports System.Drawing.Imaging
Imports System.Workflow.Activities
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design

Module Module1
Sub Main()
    Dim workflow AsNew SequentialWorkflowActivity
    workflow.Activities.Add(New DelayActivity())

    Dim loader AsNew WorkflowLoader(workflow)
    Dim surface AsNew DesignSurface
    surface.BeginLoad(loader)
    Dim view AsNew WorkflowView(CType(surface, IServiceProvider))
    view.SaveWorkflowImage("workflow.png", ImageFormat.Png)

    Process.Start("workflow.png")
End Sub
End Module


Public Class WorkflowLoader
Inherits WorkflowDesignerLoader

Private _workflowDefinition As Activity

SubNew(ByVal workflowDefinition As Activity)
    _workflowDefinition = workflowDefinition
EndSub

ProtectedOverridesSub PerformLoad(ByVal serializationManager As IDesignerSerializationManager)
    MyBase.PerformLoad(serializationManager)

    Dim designerHost As IDesignerHost = Me.GetService(GetType(IDesignerHost))
    Dim allActivities As List(Of Activity) = WorkflowUtils.GetAllActivities(_workflowDefinition)

    ForEach item As Activity In allActivities
        designerHost.Container.Add(item, item.QualifiedName)
    Next
EndSub

Public Overrides ReadOnly Property FileName() As String
    Get
        Return""
    EndGet
End Property

PublicOverridesFunction GetFileReader(ByVal filePath AsString) As System.IO.TextReader
    ThrowNew NotSupportedException()
End Function

Public Overrides Function GetFileWriter(ByVal filePath AsString) As System.IO.TextWriter
    Throw New NotSupportedException()
End Function
End Class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM