Save Workflow Image Example
Last changed: MauriceDeBeijer-


Required classes are the DesignSurface, WorkflowView and a custom WorkflowDesignerLoader.

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

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

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

    End Sub
End Module

Public Class WorkflowLoader
    Inherits WorkflowDesignerLoader

    Private _workflowDefinition As Activity

    Sub New(ByVal workflowDefinition As Activity)
        _workflowDefinition = workflowDefinition
    End Sub

    Protected Overrides Sub PerformLoad(ByVal serializationManager As IDesignerSerializationManager)

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

        For Each item As Activity In allActivities
            designerHost.Container.Add(item, item.QualifiedName)
    End Sub

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

    Public Overrides Function GetFileReader(ByVal filePath As String) As System.IO.TextReader
        Throw New NotSupportedException()
    End Function

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