You are viewing limited content. For full access, please sign in.

Question

Question

Converting SDK script to Custom Workflow Activity

asked on December 23, 2020 Show version history

We have a workflow with a SDK Script that we are trying to turn into a Custom workflow activity before we deliver to the customer. We are running into compile errors when porting the working SDK script into the Custom Activity. I have been working in Visual studio 2019 in VB. Even after bringing in the required references, Boundentryinfo and SetActivityTokenValue are not recognized, and are causing compile errors. 

If these features are only available in the SDK script, how do I manually pull in Entries and  set Token values?

 

0 0

Replies

replied on December 23, 2020

Did you follow the instruction found in Building Custom Activities in Workflow (C#)?  Since this is a custom activity, you have different ways to pass the token values in and out.

1 0
replied on December 31, 2020

 

I made some changes to my code, but I am still getting some errors with using tokens and referencing the entry. How can I get the "SetActivityTokenValue"  working in with the custom workflow Activity?  Any guidance on how to proceed would be appreciated.

0 0
replied on December 31, 2020

What is not obvious from the documentation is that they are using the COM DLLs (LFSO and not RA).  When you created your custom activity from template, under LFSO Support, you can select to support LFSO or RA.  By default, it is set to LFSO90.  If you did not change this, you will need to use the LFSO objects to export your document.  If you did, then you will use RA objects to export your document.  

Create a Custom Activity and set it to use RA.  Add a Reference to the matching version of Laserfiche.DocumentServices to be able to export.  I have not compiled and tested this code, but it should be close to working:

Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Workflow.ComponentModel

Imports Laserfiche.Workflow.Activities
Imports Laserfiche.Custom.Activities
Imports Laserfiche.Workflow.ComponentModel
Imports Laserfiche.RepositoryAccess
Imports Laserfiche.DocumentServices
Imports LFSO90Lib

Namespace CustomActivity1

    Public Class CustomActivity1
        Inherits CustomSingleEntryActivity

        ' User Input to specify to export Laserfiche documents (image pages) as PDF
        Private _ExportImageAsPDF As String = Nothing
        Public Property ExportImageAsPDF As String
            Get
                Return _ExportImageAsPDF
            End Get
            Set(value As String)
                _ExportImageAsPDF = value
            End Set
        End Property

        ' Internal Property to convert user input to boolean
        Private ReadOnly Property bExportImageAsPDF As Boolean
            Get
                If _ExportImageAsPDF.ToLower() = "true" Then
                    Return True
                Else
                    Return False
                End If
            End Get
        End Property

        ''' <summary>
        ''' Called when the activity is run by the workflow server. Implement the logic of your activity in this method. 
        ''' Access methods for setting tokens, getting token values, and other functions from the base class or the execution 
        ''' context parameter. 
        ''' </summary>
        Protected Overrides Function Execute(ByVal executionContext As System.Workflow.ComponentModel.ActivityExecutionContext) As System.Workflow.ComponentModel.ActivityExecutionStatus
            Dim Base64ExportedDoc As String = Nothing
            Using wrapper As ConnectionWrapper = executionContext.OpenConnectionRA92()
                Dim RASession As Session = CType(wrapper.Connection, Session)
                ' Note: You must add the Laserfiche.RepositoryAccess reference to this project for this to work.
                ' TODO: Your code here
                Dim iDocID As Integer = 0
                Using CurrentEntry As EntryInfo = Entry.GetEntryInfo(Me.GetEntryInformation(executionContext).Id, RASession)
                    If CurrentEntry.EntryType = EntryType.Document Then
                        iDocID = CurrentEntry.Id
                    End If
                End Using

                If iDocID > 0 Then
                    Using Doc As DocumentInfo = Document.GetDocumentInfo(iDocID, RASession)
                        If IsElectronicDocument(Doc) Then
                            Base64ExportedDoc = ExportElectronicToBase64(Doc)
                        ElseIf HasImagePages(Doc) Then
                            If bExportImageAsPDF Then
                                'Export images to PDF
                                Base64ExportedDoc = ExportImageDocumentToPDFToBase64(Doc)
                            Else
                                'Export images to TIFF
                                Base64ExportedDoc = ExportImageDocumentToBase64(Doc)
                            End If
                        Else
                            If HasText(Doc) Then
                                Base64ExportedDoc = ExportTextDocumentToBase64(Doc)
                            End If
                        End If
                    End Using
                End If
            End Using
            Me.SetToken(executionContext, "Base64ExportedDoc", True, Base64ExportedDoc)
            Return MyBase.Execute(executionContext)
        End Function

        Private Function ExportTextDocumentToBase64(ByVal LFDoc As DocumentInfo) As String
            Dim base64String As String = Nothing
            Try
                Dim sTxt As String = Nothing
                Using LF_PageInfos As PageInfoReader = LFDoc.GetPageInfos()
                    For Each PI As PageInfo In LF_PageInfos
                        If PI.HasText Then
                            Using reader As System.IO.StreamReader = PI.ReadTextPagePart()
                                If String.IsNullOrEmpty(sTxt) Then
                                    sTxt = reader.ReadToEnd()
                                Else
                                    sTxt = sTxt + Environment.NewLine + reader.ReadToEnd()
                                End If
                            End Using
                        End If
                    Next
                End Using
                Using MS As System.IO.MemoryStream = New System.IO.MemoryStream()
                    Using file As System.IO.StreamWriter = New System.IO.StreamWriter(MS)
                        file.Write(sTxt)
                    End Using
                    base64String = Convert.ToBase64String(MS.ToArray())
                End Using
            Catch ex As Exception
                Me.TrackError(ex)
                base64String = Nothing
            End Try
            Return base64String
        End Function

        Private Function ExportImageDocumentToBase64(ByVal LFDoc As DocumentInfo) As String
            Dim base64String As String = Nothing
            Try
                Dim docExporter As DocumentExporter = New DocumentExporter()
                docExporter.PageFormat = DocumentPageFormat.Tiff
                Using MS As System.IO.MemoryStream = New System.IO.MemoryStream()
                    docExporter.ExportPages(LFDoc, GetImagePageSet(LFDoc), MS)
                    base64String = Convert.ToBase64String(MS.ToArray())
                End Using
            Catch ex As Exception
                Me.TrackError(ex)
                base64String = Nothing
            End Try
            Return base64String
        End Function

        Private Function ExportImageDocumentToPDFToBase64(ByVal LFDoc As DocumentInfo) As String
            Dim base64String As String = Nothing
            Try
                Dim docExporter As DocumentExporter = New DocumentExporter()
                Using MS As System.IO.MemoryStream = New System.IO.MemoryStream()
                    docExporter.ExportPdf(LFDoc, GetImagePageSet(LFDoc), PdfExportOptions.None, MS)
                    base64String = Convert.ToBase64String(MS.ToArray())
                End Using
            Catch ex As Exception
                Me.TrackError(ex)
                base64String = Nothing
            End Try
            Return base64String
        End Function

        Private Function ExportElectronicToBase64(ByVal LFDoc As DocumentInfo) As String
            Dim base64String As String = Nothing
            Try
                Dim docExporter As DocumentExporter = New DocumentExporter()
                Using MS As System.IO.MemoryStream = New System.IO.MemoryStream()
                    docExporter.ExportElecDoc(LFDoc, MS)
                    base64String = Convert.ToBase64String(MS.ToArray())
                End Using
            Catch ex As Exception
                Me.TrackError(ex)
                base64String = Nothing
            End Try
            Return base64String
        End Function

        Private Function GetImagePageSet(ByVal LFDoc As DocumentInfo) As PageSet
            Dim psReturn As PageSet = New PageSet()
            Try
                Using LF_PageInfos As PageInfoReader = LFDoc.GetPageInfos()
                    For Each PI As PageInfo In LF_PageInfos
                        Using lrs As LaserficheReadStream = PI.ReadPagePart(New PagePart())
                            If lrs.Length > 0 Then
                                psReturn.AddPage(PI.PageNumber)
                            End If
                        End Using
                    Next
                End Using
            Catch ex As Exception
                Me.TrackError(ex)
                psReturn = New PageSet()
            End Try
            Return psReturn
        End Function

        Private Function HasText(ByVal LFDoc As DocumentInfo) As Boolean
            Dim bReturn As Boolean = False
            Try
                Using LF_PageInfos As PageInfoReader = LFDoc.GetPageInfos()
                    For Each PI As PageInfo In LF_PageInfos
                        If PI.HasText Then
                            bReturn = True
                            Exit For
                        End If
                    Next
                End Using
            Catch ex As Exception
                Me.TrackError(ex)
                bReturn = False
            End Try
            Return bReturn
        End Function

        Private Function HasImagePages(ByVal LFDoc As DocumentInfo) As Boolean
            Dim bReturn As Boolean
            Try
                Using LF_PageInfos As PageInfoReader = LFDoc.GetPageInfos()
                    For Each PI As PageInfo In LF_PageInfos
                        Using lrs As LaserficheReadStream = PI.ReadPagePart(New PagePart())
                            If lrs.Length > 0 Then
                                bReturn = True
                                Exit For
                            End If
                        End Using
                    Next
                End Using
            Catch ex As Exception
                Me.TrackError(ex)
                bReturn = False
            End Try
            Return bReturn
        End Function

        Private Function IsElectronicDocument(ByVal LFDoc As DocumentInfo) As Boolean
            Dim bReturn As Boolean
            Try
                bReturn = LFDoc.IsElectronicDocument
            Catch ex As Exception
                Me.TrackError(ex)
                bReturn = False
            End Try
            Return bReturn
        End Function

        Private Function IsEntryDocument(ByVal LFEnt As EntryInfo) As Boolean
            Dim bReturn As Boolean
            Try
                If LFEnt.EntryType = EntryType.Document Then
                    bReturn = True
                Else
                    bReturn = False
                End If
            Catch ex As Exception
                Me.TrackError(ex)
                bReturn = False
            End Try
            Return bReturn
        End Function

    End Class
End Namespace

Then in the Proxy Generator, in the Activity Proxy Properties page, you will have a Tokens tab where you will set up the user input for "ExportImageAsPDF".

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.