Hi
I'm new to the Job Server API (worked a lot with Inventor and Vault API though) and need some help to get this kickstarted.
I'm currently trying to get the "FolderPublish" sample files that comes with the SDK to run from a lifecycle event. I've installed the files as instructed in the readme. The "Queue Publish Job" is present in the right click menu on files in Vault Pro 2012. If I select this action the job is sent to the Job Server queue and executed without errors. Using the "LifecycleEventEditor" I've added the same job to a few lifecycle transitions. When I then run a couple of files through those transitions, the job still get added to the Job Server queue, but this time it produces an error when processed: "The given key was not present in the dictionary."
I've tried searching this forum and googled for solutions. I've also tried to get some more information about the "LifecycleEventEditor" tool itself, but have been unsuccessfull.
My guess is that some of the attributes are different when the job is triggered from a lifecycleevent. The code should be available in the SDK, but I'll paste it here anyway:
FolderPublishJobHandler.vb
Imports Autodesk.Connectivity.JobProcessor.Extensibility Imports Autodesk.Connectivity.WebServices Imports Autodesk.Connectivity.WebServicesTools Public Class FolderPublishJobHandler Implements IJobHandler Private Property TargetFolder() As String Get Return m_TargetFolder End Get Set m_TargetFolder = Value End Set End Property Private m_TargetFolder As String Public Sub New() TargetFolder = "C:\PublishFolder\" End Sub #Region "IJobHandler Members" Public Function CanProcess(jobType As String) As Boolean Implements IJobHandler.CanProcess If jobType.ToLower().Equals("MyCompany.File.Publish".ToLower()) Then Return True End If Return False End Function Public Function Execute(context As IJobProcessorServices, job As IJob) As JobOutcome Implements IJobHandler.Execute Dim fileMasterId As Long = Convert.ToInt64(job.Params("FileMasterId")) Try Dim credentials As New UserIdTicketCredentials(context.VaultContext.RemoteBaseUrl.ToString(), context.VaultContext.VaultName, context.VaultContext.UserId, context.VaultContext.Ticket) Using serviceManager As New WebServiceManager(credentials) ' Retrieve the file object from the server ' Dim file As File = serviceManager.DocumentService.GetLatestFileByMasterId(fileMasterId) ' Download and publish the file ' Publish(file, serviceManager) End Using Return JobOutcome.Success Catch Return JobOutcome.Failure End Try End Function #End Region Private Sub Publish(file As File, serviceManager As WebServiceManager) Dim targetDir As New System.IO.DirectoryInfo(TargetFolder) If Not targetDir.Exists Then targetDir.Create() End If Dim bytes As Byte() Dim fileName As String = serviceManager.DocumentService.DownloadFile(file.Id, True, bytes) Dim fileFullName As String = TargetFolder & fileName System.IO.File.WriteAllBytes(fileFullName, bytes) End Sub End Class
QueuePublishJobCommandExtension.vb
Imports System Imports System.Reflection Imports Autodesk.Connectivity.Extensibility.Framework Imports Autodesk.Connectivity.Explorer.Extensibility Imports Autodesk.Connectivity.WebServices Imports Autodesk.Connectivity.WebServicesTools <Assembly: AssemblyCompany("Autodesk")> <Assembly: AssemblyProduct("JobProcessorApiSamples")> <Assembly: AssemblyDescription("A sample that queues and handles a job")> <Assembly: ApiVersion("4.0")> <Assembly: ExtensionId("0C22C400-9002-49ef-95B9-9B7B97A32A0D")> Public Class QueuePublishJobCommandExtension Implements IExtension 'private JobService mJobSvc; Private m_serviceManager As WebServiceManager Public Sub QueuePublishJobCommandHandler(s As Object, e As CommandItemEventArgs) ' Queue a ShareDwf job ' Const PublishJobTypeName As String = "MyCompany.File.Publish" Const PublishJob_FileMasterId As String = "FileMasterId" Const PublishJob_FileName As String = "FileName" For Each vaultObj As ISelection In e.Context.CurrentSelectionSet Dim paramList As JobParam() = New JobParam(1) {} Dim masterIdParam As New JobParam() masterIdParam.Name = PublishJob_FileMasterId masterIdParam.Val = vaultObj.Id.ToString() paramList(0) = masterIdParam Dim fileNameParam As New JobParam() fileNameParam.Name = PublishJob_FileName fileNameParam.Val = vaultObj.Label paramList(1) = fileNameParam ' Add the job to the queue ' m_serviceManager.JobService.AddJob(PublishJobTypeName, [String].Format("Publish File - {0}", fileNameParam.Val), paramList, 10) Next End Sub #Region "IExtension Members" Public Function CommandSites() As IEnumerable(Of CommandSite) Implements IExtension.CommandSites Dim sites As New List(Of CommandSite)() ' Describe user history command item ' Dim queuePublishJobCmdItem As New CommandItem("Command.QueuePublishJob", "Queue Publish Job") queuePublishJobCmdItem.NavigationTypes = New SelectionTypeId() {SelectionTypeId.File} queuePublishJobCmdItem.MultiSelectEnabled = False AddHandler queuePublishJobCmdItem.Execute, AddressOf QueuePublishJobCommandHandler ' deploy user history command on file context menu ' Dim queuePublishContextMenu As New CommandSite("Menu.FileContextMenu", "Queue Publish Job") queuePublishContextMenu.Location = CommandSiteLocation.FileContextMenu queuePublishContextMenu.DeployAsPulldownMenu = False queuePublishContextMenu.AddCommand(queuePublishJobCmdItem) sites.Add(queuePublishContextMenu) Return sites End Function Public Function DetailTabs() As IEnumerable(Of DetailPaneTab) Implements IExtension.DetailTabs Return Nothing End Function Public Sub OnLogOn(application As IApplication) Implements IExtension.OnLogOn m_serviceManager = New WebServiceManager(New UserIdTicketCredentials(application.VaultContext.RemoteBaseUrl.ToString(), application.VaultContext.VaultName, application.VaultContext.UserId, application.VaultContext.Ticket)) End Sub Public Sub OnLogOff(application As IApplication) Implements IExtension.OnLogOff m_serviceManager = Nothing End Sub Public Sub OnShutdown(application As IApplication) Implements IExtension.OnShutdown ' NoOp; End Sub Public Sub OnStartup(application As IApplication) Implements IExtension.OnStartup ' NoOp; End Sub Public Function HiddenCommands() As IEnumerable(Of String) Implements IExtension.HiddenCommands Return Nothing End Function #End Region End Class
Any help or pointers to documentation\example code would be greatly appreciated.
Thanks
Regards
Bredo Norhall
Edit: Pasted the entire code into the post
Solved! Go to Solution.
Solved by Redmond.D. Go to Solution.
Hi again
Helps to get the question out there
Just found something that I believe will get me going again.
Dim fileMasterId As Long = Convert.ToInt64(job.Params("FileMasterId"))
As I understand "job.Params" only contain "FileId" and "LifeCyleTransitionId" when job is created from a lifecycletransition. Edited the code accordingly, and it now ran as it should.
I think this page helpful: http://justonesandzeros.typepad.com/blog/2012/04/lifecycle-event-job-parameters.html
Hi There,
I know this thread is a couple years old, but I'm coming across the exact same situation mentioned above.
I have a custom job that works when run on a file in the vault, but not when run as a lifecycle event. And I get the same error message.
I see that the issue has been resolved, but could you please be more specific about how to resolve it?
I'm working with Vault Pro 2015.
Thanks!
V.
Hi
My issue was that I expected to recieve the "FileMasterID" (se my code example), but the only thing passed from a lifecycle event was the "FileID". Once I worked around that limitation I got it working. Dont know if the same is true for 2015 though.
Thanks for the quick response bredo!
So, reading the thread, I gathered that was the issue, but I was hoping to find out how to specifically work around the issue.
This is the original line (as it still shows up in the SDK samples, but I gather it is not passing anything...
Dim fileMasterId As Long = Convert.ToInt64(job.Params("FileMasterId"))
Per the responses above, I tried the following...
Dim fileMasterId As Long = Convert.ToInt64(job.Params("FileId"))
and...
Dim fileMasterId As Long = Convert.ToInt64(job.Params("EntityId"))
with no perceived success. So, it seems I am missing something obvious, and would appreciate knowing the work-around you came up with.
Thanks!
V
Hi again
Sorry I didn't explain better 🙂 Anyway here is the code I used. Guess it could use some optimization, but it gets the job done. I've left the original line in the code, just commented it out for reference.
Public Function Execute(ByVal context As IJobProcessorServices, ByVal job As IJob) As JobOutcome Implements IJobHandler.Execute 'Dim fileMasterId As Long = Convert.ToInt64(job.Params("FileMasterId")) Dim fileId As Long = Convert.ToInt64(job.Params("FileId")) Dim fileIds As Long() ReDim fileIds(0) fileIds(0) = fileId Try Dim credentials As New UserIdTicketCredentials(context.VaultContext.RemoteBaseUrl.ToString(), context.VaultContext.VaultName, context.VaultContext.UserId, context.VaultContext.Ticket) Using serviceManager As New WebServiceManager(credentials) ' Retrieve the file object from the server ' Dim file As Autodesk.Connectivity.WebServices.File() = serviceManager.DocumentService.GetLatestFilesByIds(fileIds) ' Download and publish the file ' Publish(file(0), serviceManager) End Using Return JobOutcome.Success Catch ' Closes Inventor session _invApp.Quit() Return JobOutcome.Failure End Try End Function
I dont know why the command you tried don't seem to pass a value, as it seems identical to what I'm doing.
Regards
Bredo
I've found a solution that works for me for now, I'll just lay it out here for any code hunters from the future.
I replaced this line...
Dim filemasterid As Long = Convert.ToInt64(job.Params("FileMasterId"))
with this line...
Dim EntityId As Long = Convert.ToInt64(job.Params("EntityId"))
and this line...
Dim file As ACW.File = context.Connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(filemasterid )
with this line...
Dim file As ACW.File = context.Connection.WebServiceManager.DocumentService.GetFileById(EntityId)
and the function ran through as desired.
Thanks for your help bredo,
V.