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

Question

Question

entry is locked during move pages in SDK

asked on July 29, 2016

Hello

We are attempting by SDK merge a viewed document into another.   We are getting an entry lock error when attempting to use the document.move method or entry.MovePagesTo.    Before instruction we have issued document.unlockobject or  set lfplockdata.islock to false.   Is there reliable way to release an document or entry so we can move the pages to another document?

 

Error Message

 

Current code snippets

 

If Mid(OldBatchNo, 1, 1) = "L" Or Mid(OldBatchNo, 1, 1) = "M" Or

            Mid(OldBatchNo, 1, 1) = "R" Or Mid(OldBatchNo, 1, 1) = "H" Then

            Try

                Dim currentdoc As Integer = Doc.ID

                Dim olddocid As Integer = Integer.Parse(OldBatchNo.Substring(1))

                releaseByID(currentdoc)

 

                MovePages(olddocid, currentdoc, False)

 

                OldDoc = DB.GetEntryByID(CInt(Mid(OldBatchNo, 2)))

 

                Try

                    OldDoc.Move(ChildFolder, True)

                    OldDoc.Update()

                Catch ex As Exception

                    System.Threading.Thread.Sleep(10)  '10 ms

                    If OldDoc.IsLocked Then

                        OldDoc.UnlockObject()

                    End If

                    OldDoc.Move(ChildFolder, True)

                Finally

                    OldDoc.Dispose()

                    ParentFolder.Dispose()

                    ChildFolder.Dispose()

                End Try

 

                ParentFolder = DB.GetEntryByPath("\Duplicate Bills")

                Try

                    ChildFolder = DB.GetEntryByPath("\Duplicate Bills\" &

                        cboQuickName.Text)

                Catch ex As Exception

                    ChildFolder.Create(cboQuickName.Text, ParentFolder, False)

                End Try

                Try

                    Doc.Move(ChildFolder, True)

                    Doc.Name = DocFields.FieldByIndex(8) & "-" & Doc.ID

                    Doc.Update()

                Catch ex As Exception

                    System.Threading.Thread.Sleep(10)  '10 ms

                    If Doc.IsLocked Then

                        Doc.UnlockObject()

                    End If

                    Doc.MoveEx(ChildFolder, DocFields.FieldByIndex(8) & "-" & Doc.ID, Entry_Flag.ENTRY_FLAG_INDEXED)

                End Try

 

            Catch ex As Exception

                System.Threading.Thread.Sleep(10)  '10 ms

                If Doc.IsLocked Then

                    Doc.UnlockObject()

                End If

                Doc.Move(ChildFolder, True)

                Doc.Name = DocFields.FieldByIndex(8) & "-" & Doc.ID

                Doc.Update()

            End Try

        Else

            Doc.Move(ChildFolder, True)

            Doc.Name = DocFields.FieldByIndex(8) & "-" & Doc.ID

            Doc.Update()

        End If

 

Public Sub releaseByID(ByVal idToUnlock As Integer)

        Dim locklisting As LFPLockListing = DB.GetLockListing(Conn.ID, 100, PLock_Column.PLOCK_COLUMN_ID, Sort_Direction.SORT_DIRECTION_ASC)

        Dim i As Integer

        For i = 1 To locklisting.RowCount

            Dim lockdata As LFPLockData = locklisting.PLockData(i)

            If lockdata.Lifetime = Lock_Lifetime_Scope.LOCK_LIFETIME_SESSION Then

                Dim entry As ILFEntry = lockdata.Entry

                If entry.ID = idToUnlock Then ' Found the entry by id

                    lockdata.IsLocked = False

                    lockdata.Update()

                End If

            End If

        Next

    End Sub

 

Public Sub MovePages(ByVal sourceID As Integer, ByVal targetID As Integer, Optional ByVal Deleteflag As Boolean = True)

 

 

        Dim servername As String = My.Settings.RepoServer

        Dim repositoryname As String = My.Settings.RepoName

        Dim username As String = System.Environment.UserName

        Dim password As String = "#######”

 

 

        'Make sure we wrap the code in a Try Catch to catch errors...

        Try

            'Instantiate a new session...

            Dim lfSession As Session = New Session()

 

 

            'Connect to the repository and login...

            lfSession.Connect(New RepositoryRegistration(servername, repositoryname))

            lfSession.LogIn(username, password)

 

            'Get references to both the source and target documents...

            Dim docSource As DocumentInfo = Document.GetDocumentInfo(sourceID, lfSession)

            Dim docTarget As DocumentInfo = Document.GetDocumentInfo(targetID, lfSession)

 

            'Lock them both...

            docSource.Lock(LockType.Exclusive)

            docTarget.Lock(LockType.Exclusive)

 

            'Move all of the pages from the source document to the target document...

            'NOTE: MovePages method parameters;

            'Parameter1 = page range to copy.  In this example we will copy all of the pages...

            'Parameter2 = the reference to the target document

            'Parameter3 = the destination page number.  In this example we want to move the copied pages to the end of the target document...

            docSource.MovePagesTo(New PageRange(1, docSource.PageCount), docTarget, docTarget.PageCount + 1)

 

            If Deleteflag Then

                'Delete the source document...

                docSource.Delete()

            End If

            docSource.Save()

 

            'Unlock the target document...

            docTarget.Unlock()

 

            'Cleanup...

            docTarget.Dispose()

            docSource.Dispose()

            lfSession.Close()

 

        Catch ex As Exception

 

            'Show any errors...

            MessageBox.Show(ex.Message, "Error in MovePages")

        Finally

 

 

        End Try

 

 

    End Sub

 

We are using  LFSO and RA 9.0 depending on the module.

0 0

Replies

replied on July 29, 2016

Try calling Lock on the source & target document outside of MovePages (passing in the LFDocument objects instead of just the IDs), leave them both locked until after OldDoc.Move and Doc.Move are called. The Dispose() method will release any locks so avoid calling it until the moves complete.

Persistent locks shouldn't be an issue here, you will get a different error if the move is blocked by a persistent lock (document locked with a persistent lock [9167])

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

Sign in to reply to this post.