- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
As the title suggests, what would be the best practice for checking in thousands of renamed files? I've searched all over the net and handling multiple file check-ins is not really discussed, only single file check-ins.
With Acquiring files we are able to nicely add to the AcquireFilesSettings using the .AddFileToAcquire method to download many files, but whats the check-in version of that? How does the Vault addin for Inventor handle this?
Reason I ask is because I'm finding my self getting one of several errors...
1021 "CheckoutAlreadyCheckedOut" <
1103 "CheckinFailedAssociatedFileCheckedout"
or file in use by another process.
I should mention I am multi threading my check-in to try and speed things up, but clearly I'm running into collisions with other threads before they can finish.
I've even tried starting with .ipt -> .iam -> .idw, but still no luck.
Just for reference here is how I'm acquiring files...
Private Function AcquireFiles() As Boolean Try 'Setup the acquire options. Dim Settings As New AcquireFilesSettings(VConn) With Settings .OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = VersionGatheringOption.Latest .OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = True .OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = True .OptionsResolution.OverwriteOption = AcquireFileResolutionOptions.OverwriteOptions.ForceOverwriteAll .CheckoutComment = "Checked out by the Vault Batch Rename application." .AddFileToAcquire(RenameableObject.FileIteration, AcquisitionOption.Checkout Or AcquisitionOption.Download) End With RETRY: 'Download and checkout the files. AcqResults = VConn.FileManager.AcquireFiles(Settings) For Each FileResult As FileAcquisitionResult In AcqResults.FileResults If Not FileResult.Status = FileAcquisitionResult.AcquisitionStatus.Success Then RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | A child file could not be downloaded " & FileResult.File.EntityName & ", retrying.") ELog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | A child file could not be downloaded " & FileResult.File.EntityName & ". Error: " & FileResult.Exception.ToString) GoTo RETRY End If Next RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | Successfully downloaded and checked out " & RenameableObject.OriginalName & ".") Return True Catch ex As Exception If ex.Message = "1103" Then 'This error means that another associated file is still checked out, so wait and try again. Threading.Thread.Sleep(1000) GoTo RETRY End If SetResultType(eResultType.Download) ELog.AppendLine(Date.Now & " | Could not acquire " & RenameableObject.OriginalName & " from vault. Vault: " & VConn.Vault & " on Server: " & UCase(VConn.Server) & "returned error: " & ex.Message) RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | Could not acquire " & RenameableObject.OriginalName & " from vault. Error Message: " & ex.Message) Return False End Try End Function
Here is how I'm gathering my associations...
Private Function GetFileAssociations(FileIt As FileIteration) As FileAssocParam() Dim Settings As New FileRelationshipGatheringSettings With Settings .IncludeChildren = True .IncludeAttachments = True .VersionGatheringOption = VersionGatheringOption.Latest End With Try Dim FileAssocs As IEnumerable(Of FileAssocLite) = VConn.FileManager.GetFileAssociationLites(New Long() {FileIt.EntityIterationId}, Settings) 'If we didn't return anything with the previous call then return true so its not logged as an error. If FileAssocs.Count = 0 Then RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | There were no file associations for " & RenameableObject.OriginalName & ".") Return New List(Of FileAssocParam)().ToArray End If 'Create the new list. 'SetFileAssocParams(New List(Of FileAssocParam)) Dim FAPArray As New List(Of FileAssocParam) 'Convert the file association to File association parameter. For Each Item In FileAssocs 'If item is the current rename file then do not add. If Item.CldFileId = RenameableObject.VaultFile.Id Then Continue For 'Create and load the FileAssocParam. Dim FAP As New FileAssocParam With FAP .CldFileId = Item.CldFileId .ExpectedVaultPath = Item.ExpectedVaultPath .RefId = Item.RefId .Source = Item.Source .Typ = Item.Typ End With FAPArray.Add(FAP) Next RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | Successfully retrieved " & FileAssocs.Count & " file associations for " & RenameableObject.OriginalName & ".") Return FAPArray.ToArray Catch ex As Exception SetResultType(eResultType.Associations) ELog.AppendLine(Date.Now & " | File associations could not be retrieved for " & RenameableObject.OriginalName & ". Vault: " & VConn.Vault & " on Server: " & UCase(VConn.Server) & "returned error: " & ex.Message) RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | File associations could not be retrieved for " & RenameableObject.OriginalName & ". Error Message: " & ex.Message) 'Just return a null array. Return New List(Of FileAssocParam)().ToArray End Try End Function
And here is my check-in method...
Private Function RenameAndCheckIn() For Each AcqFile As FileAcquisitionResult In AcqResults.FileResults 'If the file has been previously checked out by the current user then we can proceed. If AcqFile.File.IsCheckedOutToCurrentUser Then GoTo CHECK_IN 'If the file was just checked out during our file acquisition then it will create a NewFileIteration object. 'If a NewFileIteration object was not created then we nee to skip the checkin. If AcqFile.NewFileIteration Is Nothing Then Continue For CHECK_IN: 'Set the comment for check-in. Dim RenameComment As String = "File renamed by Vault Batch Rename from " & RenameableObject.OriginalName & " to " & RenameableObject.NewName & "." Try ROT.StatusBarText = "Refreshing file associations for " & IO.Path.GetDirectoryName(RenameableObject.VaultPath) & RenameableObject.NewName ROT.UpdateStatusBarReadout() Dim AssocArray As FileAssocParam() 'Get the file associations and Check in the file with th new name. If AcqFile.NewFileIteration Is Nothing Then Dim NewFileIt As FileIteration = New FileIteration(VConn, AcqFile.File) AssocArray = GetFileAssociations(NewFileIt) Dim RF As FileIteration = VConn.FileManager.CheckinFile(NewFileIt, RenameComment, False, AssocArray, Nothing, True, RenameableObject.NewName, NewFileIt.FileClassification, False, New FilePathAbsolute(NewFileIt.CheckedOutSpec)) Else AssocArray = GetFileAssociations(AcqFile.NewFileIteration) Dim RF As FileIteration = VConn.FileManager.CheckinFile(AcqFile.NewFileIteration, RenameComment, False, AssocArray, Nothing, True, RenameableObject.NewName, AcqFile.NewFileIteration.FileClassification, False, New FilePathAbsolute(AcqFile.NewFileIteration.CheckedOutSpec)) End If RNILog.AppendLine(Date.Now & ", Successfully renamed " & RenameableObject.OriginalName & " to " & RenameableObject.NewName & ". , " & VConn.Vault & "' " & UCase(VConn.Server)) RNILogCount += 1 RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | Successfully renamed " & RenameableObject.OriginalName & " to " & RenameableObject.NewName & ".") Return True Catch ex As Exception SetResultType(eResultType.Checkin) ELog.AppendLine(Date.Now & " | Could not rename " & RenameableObject.OriginalName & " to " & RenameableObject.NewName & ". Vault: " & VConn.Vault & " on Server: " & UCase(VConn.Server) & "returned error: " & ex.Message) RLog.AppendLine(Date.Now & " | " & UCase(VConn.Server) & " | " & VConn.Vault & " | Could not rename " & RenameableObject.OriginalName & ". Error Message: " & ex.Message) Return False End Try Next Return True End Function
Any help would be appreciated!
Automation is key!
Solved! Go to Solution.