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

Question

Question

How can make the Matching Templates and Fields in Briefcase Importer using DSK .Net v9?

asked on August 15, 2014

 Hello,

 

We have written a code to import briefcases using SDK .net version 9.

 

The import is working fine, but in my case the Matching Templates and Fields part is not working, and the result is that each new briefcase is creating duplicated templates and fields all the time.

 

I know that the part to handle this issue is inside the following piece of code

 

Case BriefcaseRequestType.MatchTemplates

 

But i have tried many options and I couldnt make it work.

 

Here you have my actual code for this section:

 

Case BriefcaseRequestType.MatchTemplates

Dim templates As System.Collections.ObjectModel.ReadOnlyCollection(Of BriefcaseTemplateInfo) = request.MatchTemplates

 

For Each temp As BriefcaseTemplateInfo In templates

Dim validtemps As Collections.IList = temp.GetValidMatches

Next

' MsgBox(templates.Count)

For i As Integer = 0 To templates.Count - 1

 Dim template As BriefcaseTemplateInfo = templates.Item(i)

 Dim validmatches As System.Collections.ObjectModel.ReadOnlyCollection(Of TemplateInfo) = template.GetValidMatches

 

 For j As Integer = 0 To validmatches.Count - 1

  Dim matchedTemp As TemplateInfo = validmatches.Item(j)

  If matchedTemp.Name = "General" Then

  template.MatchTemplate = matchedTemp                   <=== This is not valid

  End If

 Next

Next

 

Dim fields As Collections.IList = request.MatchFields

For k As Integer = 0 To fields.Count - 1

Dim ffield As BriefcaseFieldInfo = fields.Item(k)

Dim validfieldmatches As Collections.IList = ffield.ValidMatches

 For l As Integer = 0 To validfieldmatches.Count - 1

  'MsgBox(validfieldmatches.Item(l))

  Dim matchedfield As FieldInfo = Field.GetInfo(validfieldmatches.Item(l), session)

  If matchedfield.Name = "Branch" And ffield.Name = "Branch" Then

  Field.MatchField = matchedfield                   <=== This is not valid

  End If

 Next

Next

request = imp.FinishedMatchingTemplates

 

Attached you have the entire solution.

 

Could anyone help?

 

Thank you very much in advance and best reagards,

 

Ignacio PdeA

BMB sal

0 0

Replies

replied on August 15, 2014

The attached file is .zip, but i renamed it as .txt to upload it.

Thank you!

Ignacio PdeA

0 0
replied on August 15, 2014

Lets start by removing the ref to the LFSO and DocumentProcessor since you are not using them.

 

Below is how I modified your code to make it work for me:

Imports System.IO
Imports Laserfiche.RepositoryAccess

Public Class Form1

    Public server As String
    Public rep As String
    Public user As String
    Public pass As String
    Public volum As String
    Public briefcasePath As String
    Public pathInLF As String

    Public Sub ParmFunction(ByVal path As String)
        ' Only process if ini file exists
        If File.Exists(path) Then
            ' Open ini file with stream reader
            Using srParmReader As New StreamReader(path)
                ' Process ini until end is reached
                Do While Not srParmReader.EndOfStream
                    ' Read 1 line at a time
                    Dim sParmLine As String = srParmReader.ReadLine
                    ' Split the line on the "="
                    Dim saParmParts() As String = sParmLine.Split("=")
                    ' Use the first part of the line to determin what parm is being processed
                    Select Case saParmParts(0).ToLower.Trim
                        ' Save each value to proper parm object
                        Case "server"
                            server = saParmParts(1).Trim
                        Case "rep"
                            rep = saParmParts(1).Trim
                        Case "user"
                            user = saParmParts(1).Trim
                        Case "pass"
                            pass = saParmParts(1).Trim
                        Case "volum"
                            volum = saParmParts(1).Trim
                        Case "briefcasepath"
                            briefcasePath = saParmParts(1).Trim
                        Case "pathinlf"
                            pathInLF = saParmParts(1).Trim
                    End Select
                Loop
            End Using
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ParmFunction(".\param.ini")
        If Directory.Exists(briefcasePath) Then
            Try
                Dim dirInfo As New IO.DirectoryInfo(briefcasePath)
                Using CurSession As New Session
                    Try
                        Dim repo As New RepositoryRegistration(server, rep)
                        CurSession.LogIn(user, pass, repo)
                        If CurSession.IsAuthenticated Then
                            Dim fol As FolderInfo = Folder.GetFolderInfo(pathInLF, CurSession)
                            Dim vol As VolumeInfo = Volume.GetInfo(volum, CurSession)
                            Dim BCCount As Integer = 0
                            For Each file As FileInfo In dirInfo.GetFiles("*.lfb", SearchOption.TopDirectoryOnly)
                                BCCount = BCCount + 1
                                TextBox1.Text = BCCount
                                Windows.Forms.Application.DoEvents()
                                Try
                                    Dim imp As BriefcaseImporter = New BriefcaseImporter(fol, vol, CurSession)

                                    Dim briefcase As System.IO.FileStream = System.IO.File.OpenRead(briefcasePath & "\" & file.Name)
                                    Dim request As BriefcaseRequest = imp.Import

                                    While Not request Is Nothing
                                        Select Case request.RequestType
                                            Case BriefcaseRequestType.WriteData
                                                Dim buffer(request.DataRequested - 1) As Byte
                                                Dim AmountRead As Integer = briefcase.Read(buffer, 0, buffer.Length)
                                                request = imp.WriteData(buffer, AmountRead)
                                            Case BriefcaseRequestType.Finished
                                                request = Nothing
                                            Case BriefcaseRequestType.MatchTemplates
                                                Dim mTemplates As IList(Of BriefcaseTemplateInfo) = request.MatchTemplates
                                                For i As Integer = 0 To mTemplates.Count - 1
                                                    Dim mTemp As BriefcaseTemplateInfo = mTemplates(i)
                                                    mTemp.MatchStrategy = If(mTemp.MatchTemplate IsNot Nothing, BriefcaseFieldMatchStrategy.Match, BriefcaseFieldMatchStrategy.Create)
                                                Next
                                                Dim mFields As IList(Of BriefcaseFieldInfo) = request.MatchFields
                                                For i As Integer = 0 To mFields.Count - 1
                                                    Dim mTemp As BriefcaseFieldInfo = mFields(i)
                                                    mTemp.MatchStrategy = If(mTemp.MatchField IsNot Nothing, BriefcaseFieldMatchStrategy.Match, BriefcaseFieldMatchStrategy.Create)
                                                Next
                                                request = imp.FinishedMatchingTemplates
                                            Case BriefcaseRequestType.Seek
                                                Select Case request.SeekOrigin
                                                    Case SeekOrigin.Current
                                                        briefcase.Seek(request.SeekOffset, IO.SeekOrigin.Current)
                                                    Case SeekOrigin.End
                                                        briefcase.Seek(request.SeekOffset, IO.SeekOrigin.End)
                                                    Case SeekOrigin.Begin
                                                        briefcase.Seek(request.SeekOffset, IO.SeekOrigin.Begin)
                                                    Case Else
                                                        Console.WriteLine("Seek_Origin" + request.SeekOrigin.ToString)
                                                End Select
                                                request = imp.FinishedSeek()

                                            Case BriefcaseRequestType.TellPosition
                                                request = imp.TellPosition(briefcase.Position)
                                            Case BriefcaseRequestType.Wait
                                                System.Threading.Thread.Sleep(1000)
                                                request = imp.FinishedWait()
                                        End Select
                                    End While
                                Catch ex As Exception
                                    MsgBox("Error importing briefcase : " & file.Name & " = " & ex.Message)
                                End Try
                            Next
                        End If
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                    If CurSession.IsConnected Then
                        CurSession.LogOut()
                    End If
                End Using
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
        MsgBox("Done")

    End Sub

End Class

 

0 0
replied on August 15, 2014

Hi Berth,

 

Thanks so much for your reply, really appreciated!

I still have a problem with the code, which is when the Template name matches but the fields are not exactly the same.

Is there any way to force a match between fields that have the same name but maybe a slight difference?

 

For instance I already have a Template Bank, with 2 fields Branch (char50) and Teller (char50)

I import a Briefcase having also Template Bank, with the same fields, but Branch (char10) and Teller (char10)

 

The names are the same, but their lenght is different.

 

Can I "force" the incoming documents to use the same fields already existing, instead of creating new ones, even if they differ in lenght?

 

Thanks a lot for your help, once again.

 

Best regards,

 

Ignacio PdeA

BMB sal

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

Sign in to reply to this post.