// (non-Javadoc) // * @see org.cip4.jdflib.util.HotFolderListener#hotFile(java.io.File) // public virtual void hotFile(FileInfo hotFile) { FileInfo storedFile = FileUtil.moveFileToDir(hotFile, storageDir); if (storedFile == null) { return; // not good } string stringURL = UrlUtil.fileToUrl(storedFile, false); JDFDoc jmfDoc = new JDFDoc("JMF"); JDFJMF jmfRoot = jmfDoc.getJMFRoot(); JDFCommand newCommand = (JDFCommand)jmfRoot.copyElement(queueCommand, null); newCommand.removeAttribute(AttributeName.ID); newCommand.appendAnchor(null); EnumType cType = newCommand.getEnumType(); JDFDoc jdfDoc = JDFDoc.parseFile(storedFile.FullName); JDFNode jdfRoot = jdfDoc == null ? null : jdfDoc.getJDFRoot(); if (EnumType.ReturnQueueEntry.Equals(cType)) { extractReturnParams(stringURL, newCommand, jdfRoot); } else if (EnumType.SubmitQueueEntry.Equals(cType)) { extractSubmitParams(stringURL, newCommand, jdfRoot); } qhfl.submitted(jmfRoot); }
public virtual void testBuildMimePackageDocJMF() { JDFDoc docJMF = new JDFDoc("JMF"); docJMF.setOriginalFileName("JMF.jmf"); JDFJMF jmf = docJMF.getJMFRoot(); JDFCommand com = (JDFCommand)jmf.appendMessageElement(JDFMessage.EnumFamily.Command, JDFMessage.EnumType.SubmitQueueEntry); com.appendQueueSubmissionParams().setURL("TheJDF"); JDFDoc doc = new JDFDoc("JDF"); doc.setOriginalFileName("JDF.jdf"); JDFNode n = doc.getJDFRoot(); n.setType(EnumType.ColorSpaceConversion); JDFColorSpaceConversionParams cscp = (JDFColorSpaceConversionParams)n.addResource(ElementName.COLORSPACECONVERSIONPARAMS, null, EnumUsage.Input, null, null, null, null); JDFFileSpec fs0 = cscp.appendFinalTargetDevice(); fs0.setURL(StringUtil.uncToUrl(sm_dirTestData + "test.icc", true)); JDFRunList rl = (JDFRunList)n.addResource(ElementName.RUNLIST, null, EnumUsage.Input, null, null, null, null); rl.addPDF(StringUtil.uncToUrl(sm_dirTestData + "url1.pdf", false), 0, -1); for (int i = 0; i < 100; i++) { rl.addPDF(StringUtil.uncToUrl(sm_dirTestData + "url?.pdf", false), 0, -1); } AttachmentCollection m = MimeUtil.buildMimePackage(docJMF, doc, true); MimeUtil.writeToFile(m, sm_dirTestDataTemp + "testMimePackageDoc.mjm", null); }
public static void submitMimeToHDM(JDFNode n) { // build SubmitQueueEntry JDFDoc docJMF = new JDFDoc("JMF"); JDFJMF jmf = docJMF.getJMFRoot(); JDFCommand com = (JDFCommand)jmf.appendMessageElement(JDFMessage.EnumFamily.Command, JDFMessage.EnumType.SubmitQueueEntry); com.appendQueueSubmissionParams().setURL("dummy"); System.Net.Mail.AttachmentCollection mp = MimeUtil.buildMimePackage(docJMF, n.getOwnerDocument_JDFElement(), true); try { MIMEDetails md = new MIMEDetails(); md.transferEncoding = UrlUtil.BASE64; md.httpDetails.chunkSize = -1; HttpWebRequest response = MimeUtil.writeToURL(mp, "http://192.168.40.71:8889/jmfportal", md); // Java to C# Converstion - What is the ResponseCode for HttpWebRequest? //Assert.AreEqual(200, response.GetResponse().getResponseCode()); MimeUtil.writeToURL(mp, UrlUtil.fileToUrl(new FileInfo("C:\\data\\test.mim"), false), md); } catch (Exception e) { Assert.Fail(e.Message); // fail on exception } }
public virtual void testWritePerformance() { long start = JDFDate.ToMillisecs(DateTime.Now); string big = sm_dirTestData + "big.pdf"; string bigger = sm_dirTestDataTemp + "bigger.pdf"; JDFDoc docJMF = new JDFDoc("JMF"); docJMF.setOriginalFileName("JMF.jmf"); JDFJMF jmf = docJMF.getJMFRoot(); JDFCommand com = (JDFCommand)jmf.appendMessageElement(JDFMessage.EnumFamily.Command, JDFMessage.EnumType.SubmitQueueEntry); com.appendQueueSubmissionParams().setURL("TheJDF"); FileInfo fBigger = new FileInfo(bigger); SupportClass.FileSupport.CreateNewFile(fBigger); FileStream fis = new FileStream(big, FileMode.Open); FileStream fos = new FileStream(bigger, FileMode.Create); byte[] b = new byte[10000]; while (true) { int i = fis.Read(b, 0, 10000); if (i <= 0) { break; } for (int j = 0; j < 3; j++) { fos.Write(b, 0, i); } } fis.Close(); fos.Flush(); fos.Close(); JDFDoc doc = new JDFDoc("JDF"); doc.setOriginalFileName("JDF.jdf"); JDFNode n = doc.getJDFRoot(); n.setType(EnumType.Interpreting); JDFRunList rl = (JDFRunList)n.addResource(ElementName.RUNLIST, EnumUsage.Input); rl.addPDF(StringUtil.uncToUrl(bigger, false), 0, -1); long setup = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("Setup time: " + (setup - start)); AttachmentCollection m = MimeUtil.buildMimePackage(null, doc, true); long build = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("Build time: " + (build - setup)); Assert.IsNotNull(MimeUtil.writeToFile(m, sm_dirTestDataTemp + "performance.mjm", null)); long write = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("Write time: " + (write - build)); }
/// /// <summary> * overwrite this method in case you want to customize the hotfolder for submitqueentry and paramtetrizing /// * the QueueSubmissionParams template is insufficient /// * </summary> /// * <param name="stringURL"> the file url of the hotfolder jdf in the local storage directory (NOT the hf) </param> /// * <param name="newCommand"> the command that was generated from the template </param> /// * <param name="jdfRoot"> the root jdfnode of the dropped file </param> /// protected internal virtual void extractSubmitParams(string stringURL, JDFCommand newCommand, JDFNode jdfRoot) { JDFQueueSubmissionParams sqp = newCommand.getCreateQueueSubmissionParams(0); sqp.setURL(stringURL); JDFAuditPool ap = jdfRoot == null ? null : jdfRoot.getCreateAuditPool(); if (ap != null) { ap.createSubmitProcessRun(null); } }
/// /// <summary> * Get all Command from the current element /// * </summary> /// * <returns> Collection<JDFCommand> </returns> /// public virtual ICollection <JDFCommand> getAllCommand() { List <JDFCommand> v = new List <JDFCommand>(); JDFCommand kElem = (JDFCommand)getFirstChildElement(ElementName.COMMAND, null); while (kElem != null) { v.Add(kElem); kElem = (JDFCommand)kElem.getNextSiblingElement(ElementName.COMMAND, null); } return(v); }
public virtual void testGetJMFSubmission() { JDFDoc d1 = new JDFDoc("JMF"); d1.setOriginalFileName("JMF.jmf"); JDFJMF jmf = d1.getJMFRoot(); jmf.setDeviceID("gr?n?"); JDFCommand com = (JDFCommand)jmf.appendMessageElement(JDFMessage.EnumFamily.Command, JDFMessage.EnumType.SubmitQueueEntry); com.appendQueueSubmissionParams().setURL("TheJDF"); JDFDoc doc = new JDFDoc("JDF"); doc.setOriginalFileName("JDF.jdf"); JDFNode n = doc.getJDFRoot(); n.setType(EnumType.ColorSpaceConversion); JDFColorSpaceConversionParams cscp = (JDFColorSpaceConversionParams)n.addResource(ElementName.COLORSPACECONVERSIONPARAMS, null, EnumUsage.Input, null, null, null, null); JDFFileSpec fs0 = cscp.appendFinalTargetDevice(); fs0.setURL(StringUtil.uncToUrl(sm_dirTestData + "test.icc", true)); JDFRunList rl = (JDFRunList)n.addResource(ElementName.RUNLIST, null, EnumUsage.Input, null, null, null, null); rl.addPDF(StringUtil.uncToUrl(sm_dirTestData + "url1.pdf", false), 0, -1); for (int i = 0; i < 100; i++) { rl.addPDF("gr?n?" + i + ".pdf", 0, -1); } AttachmentCollection m = MimeUtil.buildMimePackage(d1, doc, true); JDFDoc[] d2 = MimeUtil.GetJMFSubmission(m); Assert.IsNotNull(d2); Assert.AreEqual("cid:JDF.jdf", d2[0].getJMFRoot().getCommand(0).getQueueSubmissionParams(0).getURL()); Assert.AreEqual(EnumType.ColorSpaceConversion, d2[1].getJDFRoot().getEnumType()); // now serialize to file and reread - should still work MimeUtil.writeToFile(m, sm_dirTestDataTemp + "test2.mjm", null); AttachmentCollection m2 = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "test2.mjm"); Assert.IsNotNull(m2); d2 = MimeUtil.GetJMFSubmission(m); Assert.IsNotNull(d2); Assert.AreEqual("cid:JDF.jdf", d2[0].getJMFRoot().getCommand(0).getQueueSubmissionParams(0).getURL()); Assert.AreEqual(EnumType.ColorSpaceConversion, d2[1].getJDFRoot().getEnumType()); }
/// /// <summary> * overwrite this method in case you want to customize the hotfolder for returnqueueentryparams and paramtetrizing /// * the ReturnQueueEntryParams template is insufficient /// * </summary> /// * <param name="stringURL"> the file url of the hotfolder jdf in the local storage directory (NOT the hf) </param> /// * <param name="newCommand"> the command that was generated from the template </param> /// * <param name="jdfRoot"> the root jdfnode of the dropped file </param> /// protected internal virtual void extractReturnParams(string stringURL, JDFCommand newCommand, JDFNode jdfRoot) { JDFReturnQueueEntryParams rqp = newCommand.getCreateReturnQueueEntryParams(0); rqp.setURL(stringURL); JDFAuditPool ap = jdfRoot == null ? null : jdfRoot.getCreateAuditPool(); if (ap != null) { JDFProcessRun pr = (JDFProcessRun)ap.getAudit(-1, EnumAuditType.ProcessRun, null, null); string queueEID = pr == null ? null : pr.getAttribute(AttributeName.QUEUEENTRYID); if (!KElement.isWildCard(queueEID)) { rqp.setQueueEntryID(queueEID); } } }
private readonly JDFCommand queueCommand; // the jdf command template that is used to generate a new message for each dropped file /// /// <summary> * /// * constructor for a simple queue based hotfolder watcher that is automagically started in its own thread /// * </summary> /// * <param name="_hotFolderDir"> the hot folder directory to watch </param> /// * <param name="_storageDir"> the storage directory wher hot files are moved to </param> /// * <param name="ext"> the file extensions that are moved - if null no filtering </param> /// * <param name="hfListener"> callback that receives the generated JMF - the location of the stored file will be found in the standard command parameters </param> /// * <param name="_queueCommand"> the jmf template that will be used to generate a new message, null creates an empty SubmitQueueEntry template </param> /// public QueueHotFolder(DirectoryInfo _hotFolderDir, DirectoryInfo _storageDir, string ext, QueueHotFolderListener hfListener, JDFJMF _queueCommand) { JDFJMF _queueCommandLocal = _queueCommand; storageDir = _storageDir; if (!storageDir.Exists) { storageDir.Create(); // just in case } qhfl = hfListener; if (_queueCommandLocal == null) { _queueCommandLocal = JDFJMF.createJMF(JDFMessage.EnumFamily.Command, JDFMessage.EnumType.SubmitQueueEntry); } queueCommand = _queueCommandLocal.getCommand(0); hf = new HotFolder(_hotFolderDir, ext, this); }
public virtual void testGetLinkRootJMF() { JDFDoc d = new JDFDoc("JMF"); JDFJMF jmf = d.getJMFRoot(); jmf.setSenderID("Elvis"); JDFCommand c = jmf.appendCommand(); c.setType("PipePull"); JDFPipeParams pp = c.appendPipeParams(); pp.setAttribute(AttributeName.PIPEID, "foo", null); JDFRunList ruli = (JDFRunList)pp.appendResource(ElementName.RUNLIST); JDFResourceLink rl = pp.appendResourceLink("RunListLink", true); rl.setrRef(ruli.getID()); Assert.IsTrue(jmf.isValid(EnumValidationLevel.Complete), "valid param"); Assert.AreEqual(rl.getTarget(), ruli); }
public virtual void testStatusEquals() { // test if the auto classes implement the correct status // compare EnumNodeStatus JDFAuditPool myAuditPool = null; JDFDoc jdfDoc = new JDFDoc(ElementName.JDF); JDFNode jdfRoot = (JDFNode)jdfDoc.getRoot(); Assert.IsTrue(jdfRoot != null, "No Root found"); if (jdfRoot == null) { return; // soothe findbugs ;) } JDFAncestor ancestor = jdfRoot.appendAncestorPool().appendAncestor(); ancestor.setStatus(EnumNodeStatus.Completed); myAuditPool = jdfRoot.getCreateAuditPool(); JDFPhaseTime phaseTime = myAuditPool.addPhaseTime(JDFElement.EnumNodeStatus.Completed, null, null); JDFSpawned spawned = myAuditPool.addSpawned(jdfRoot, null, null, null, null); spawned.setStatus(JDFElement.EnumNodeStatus.Completed); Assert.AreEqual(spawned.getStatus(), phaseTime.getStatus()); Assert.AreEqual(spawned.getStatus(), ancestor.getStatus()); JDFDoc jmfDoc = new JDFDoc(ElementName.JMF); JDFJMF jmfRoot = jmfDoc.getJMFRoot(); Assert.IsTrue(jmfRoot != null, "No Root found"); if (jmfRoot == null) { return; // soothe findbugs ;) } JDFAcknowledge acknowledge = jmfRoot.appendAcknowledge(); acknowledge.setType("PipePush"); // Type is required and its existance // is validated for messages JDFJobPhase jobPhase = acknowledge.appendJobPhase(); jobPhase.setStatus(EnumNodeStatus.Completed); JDFMessage message = jmfRoot.appendMessageElement(EnumFamily.Command, null); message.setType("PipePush"); // Type is required and its existance is // validated for messages JDFPipeParams pipeParams = message.appendPipeParams(); pipeParams.setStatus(EnumNodeStatus.Completed); Assert.AreEqual(jobPhase.getStatus(), pipeParams.getStatus()); Assert.AreEqual(spawned.getStatus(), pipeParams.getStatus()); // compare EnumResStatus JDFDoc responseDoc = new JDFDoc(ElementName.RESPONSE); JDFResponse responseRoot = (JDFResponse)responseDoc.getRoot(); Assert.IsTrue(responseRoot != null, "No Root found"); if (responseRoot == null) { return; // soothe findbugs ;) } responseRoot.setType(ElementName.RESOURCE); JDFResourceInfo resInfo = responseRoot.appendResourceInfo(); resInfo.setResStatus(EnumResStatus.Available); JDFDoc commandDoc = new JDFDoc(ElementName.COMMAND); JDFCommand commandRoot = (JDFCommand)commandDoc.getRoot(); Assert.IsTrue(commandRoot != null, "No Root found"); if (commandRoot == null) { return; // soothe findbugs ;) } commandRoot.setType(ElementName.RESOURCE); JDFResourceCmdParams resCmdParams = commandRoot.appendResourceCmdParams(); resCmdParams.setResStatus(EnumResStatus.Available); Assert.AreEqual(resInfo.getStatus(), resCmdParams.getStatus()); // check EnumQueueStatus JDFDoc queueDoc = new JDFDoc(ElementName.QUEUE); JDFQueue queueRoot = (JDFQueue)queueDoc.getRoot(); Assert.IsTrue(queueRoot != null, "No Root found"); if (queueRoot == null) { return; // soothe findbugs ;) } queueRoot.setQueueStatus(EnumQueueStatus.Running); // check EnumQueueEntryStatus JDFQueueEntry queueEntry = queueRoot.appendQueueEntry(); queueEntry.setQueueEntryStatus(EnumQueueEntryStatus.Running); }