JDF Blog

Tools, techniques and advice for real-world JDF integrations

Fluent JDF 0.3.0.9 Released to NuGet

leave a comment »

This release has a number of minor bug fixes and one major new feature: Fluent JDF can now transmit to file URLs so you can use it to submit jobs to devices that only support hot folders. As usual, I’m going to use LinqPad to demonstrate the functionality.

Let’s take a closer look at the new file transmitter. By default, the entire transmission will be sent as a multipart mime file. For example:

void Main() 
{
  var HotFolder = "file://myMachineName/myShareName";
  var ticket = Ticket.CreateIntent().WithInput().BindingIntent().Ticket;
  var message = Message.Create().AddCommand().SubmitQueueEntry().With().Ticket(ticket).Message;
  var result = message.Transmit(HotFolder + "myFile.mim");
  result.Dump();
}

The code above writes a mime file named myFile.mim to the UNC path \\myMachineName\myShareName.

Unfortunately, there is not a standardized way that applications expect to receive JDF via files. Therefore, Fluent JDF gives you many ways to refine how files get dropped. You can send each part (i.e. JDF, JMF and attachments) independently, you can change the order in which the individual parts get dropped, you can suppress any part and you can even change the references from one part to the other to reflect specific rules the receiving application requires. You do this by configuring a file transmission encoder. For example, the following code configures transmissions to the URL file://myMachineName/myShareName to send individual parts dropping attachments, then JDF and finally JMF:

void Main() 
{
  var HotFolder = "file://myMachineName/myShareName";

  //Configure settings for transmissions to the folder (this can be done once during startup)
  FluentJdfLibrary.Settings.WithEncodingSettings()
    .FileTransmitterEncoder("id", HotFolder);
  
  //Send it (notice the destination name 'myFile' means nothing here.  We just need it
  //to make a valid file URL)
  var result = message.Transmit(HotFolder + "myFile.mim");
  result.Dump();
}

The configuration is global and is setup for each destination folder. You can refine the configuration by setting up rules for each kind of part. The next code sample illustrates many of the more advanced configuration options. It does the following:

  • Drops the attachments in \\myMachineName\myShareName\Attachments first
  • Fixes the references to the attachments in the JDF to be file references based on the local destination path e:\HotFolder\Attachments
  • Drops the JDF in \\myMachineName\myShareName\${JobId} second. ${JobId} gets replaced with the JobID of the job. You can also use ${Root} (refers to the executable folder), ${Guid} (a unique GUID), and ${JobKey} (A string “JDF_” + the ID of the root node)
  • Fixes the references to the JDF in the JMF to be file references based on the local destination path e:\HotFolder\${JobId}
  • Drops the JMF in \\myMachineName\myShareName last
void Main()
{
  var HotFolder = "file://myMachineName/myShareName";

  //set configuration for the URL (can be done once at startup)
  FluentJdfLibrary.Settings.WithEncodingSettings()
    .FileTransmitterEncoder("id", HotFolder)
      .FolderInfo(FolderInfoTypeEnum.Attachment, HotFolder + @"Attachments/", 
 	  @"e:\HotFolder\attachments", 1)
      .FolderInfo(FolderInfoTypeEnum.Jdf, HotFolder + @"${JobId}/", 
          @"e:\HotFolder\${JobId}\", 2)
    .FolderInfo(FolderInfoTypeEnum.Jmf, HotFolder, 
        @"e:\HotFolder\", 3);
		
  //Create a sample ticket
  var ticket = Ticket.CreateIntent()
    .WithInput().BindingIntent()
    .WithInput().RunList()
      .AddNode(Element.LayoutElement)
        .AddNode(Element.FileSpec).With().Attribute("URL", "cid:assetName").Ticket;
				
  var message = Message.Create().AddCommand().SubmitQueueEntry().With().Ticket(ticket).Message;

  //Attach the asset for transmission.  Notice that the ID of the part matches the value in the
  //cid url in the FileSpec\@URL
  message.AddRelatedPart(new TransmissionPart(Path.Combine(FilesFolder, "signs.jpg"), "assetName"));
	
  //Send it (notice the destination name 'myFile' means nothing here.  We just need it
  //to make a valid file URL)
  var result = message.Transmit(HotFolder + "myFile");
  result.Dump();
}

In the very near future you will be able to override the configuration when you call Transmit. There will also be a way to load the configuration from a configuration source like the application configuration file.

File transmission will throw an exception if the URL is invalid, the application does not have permission to create the directory if it does not exist, the application does not have permission to write the file or the file already exists in the destination location. File transmissions do not receive a response so the TransmissionPartCollection in the result will always be empty.

Advertisements

Written by Tom Cabanski

July 24, 2011 at 3:22 pm

Posted in FluentJDF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: