Esempio n. 1
0
 public virtual void testURLPerformance()
 {
     // testWritePerformance();
     try
     {
         long write = JDFDate.ToMillisecs(DateTime.Now);
         AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "performance.mjm");
         long getMP = JDFDate.ToMillisecs(DateTime.Now);
         Console.WriteLine("get multipart time: " + (getMP - write));
         Attachment bp     = MimeUtil.GetPartByCID(mp, "bigger.pdf");
         long       getCID = JDFDate.ToMillisecs(DateTime.Now);
         Console.WriteLine("get big time: " + (getCID - getMP));
         Assert.IsNotNull(bp);
         Assert.AreEqual("bigger.pdf", bp.Name);
         HttpWebRequest uc  = MimeUtil.writeToURL(mp, "http://localhost:8080/JDFUtility/dump");
         Stream         @is = uc.GetRequestStream();
         IOUtils.CopyStream(@is, System.Console.OpenStandardOutput());
         @is.Close();
         Console.WriteLine();
         // System.out.println("extracted "+l+" bytes in time: "+(extract-
         // getCID));
         long extract = JDFDate.ToMillisecs(DateTime.Now);
         Console.WriteLine("sent  bytes in time: " + (extract - getCID));
     }
     catch (Exception)
     {
         // nop
     }
 }
Esempio n. 2
0
        public virtual void testPerformance()
        {
            testWritePerformance();

            long write = JDFDate.ToMillisecs(DateTime.Now);
            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "performance.mjm");
            long getMP = JDFDate.ToMillisecs(DateTime.Now);

            Console.WriteLine("get multipart time: " + (getMP - write));
            Attachment bp     = MimeUtil.GetPartByCID(mp, "bigger.pdf");
            long       getCID = JDFDate.ToMillisecs(DateTime.Now);

            Console.WriteLine("get big time: " + (getCID - getMP));
            Assert.IsNotNull(bp);
            Assert.AreEqual("bigger.pdf", bp.Name);
            FileInfo outFile = FileUtil.streamToFile(bp.ContentStream, sm_dirTestDataTemp + "performance.pdf");

            Assert.IsNotNull(outFile);
            //
            //		 * InputStream is=bp.getInputStream(); byte[] b=new byte[1000]; int l=0;
            //		 * while (true) { int i=is.read(b); if(i<=0) break; l+=i; }
            //
            long extract = JDFDate.ToMillisecs(DateTime.Now);

            //System.out.println("extracted "+l+" bytes in time: "+(extract-getCID))
            // ;
            Console.WriteLine("extracted  bytes in time: " + (extract - getCID));
        }
Esempio n. 3
0
        public virtual void testBuildMimePackageDoc()
        {
            for (int i = 0; i < 2; i++)
            {
                JDFDoc doc = new JDFDoc("JDF");
                if (i == 1)
                {
                    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);
                rl.addPDF(StringUtil.uncToUrl(sm_dirTestData + "url1.pdf", false), 0, -1);
                rl.addPDF(StringUtil.uncToUrl(sm_dirTestData + "url2.pdf", false), 0, -1);
                AttachmentCollection m = MimeUtil.buildMimePackage(null, doc, true);

                string mimeFile = sm_dirTestDataTemp + "testMimePackageDoc" + (i == 0 ? "0" : "") + ".mjm";
                MimeUtil.writeToFile(m, mimeFile, null);

                AttachmentCollection mp = MimeUtil.GetMultiPart(mimeFile);
                Assert.AreEqual(4, mp.Count, "JDF, 2* rl, 1 icc");
            }
        }
Esempio n. 4
0
        public virtual void testGetMultiPart()
        {
            testBuildMimePackageDocJMF();
            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");

            MimeUtil.writeToFile(mp, sm_dirTestDataTemp + "testMimePackageDoc_out.mjm", null);
        }
Esempio n. 5
0
        public virtual void testGetPartByCID()
        {
            testBuildMimePackageDocJMF();
            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");
            Attachment           bp = MimeUtil.GetPartByCID(mp, "JDF.jdf");

            Assert.IsNotNull(bp);
            Assert.AreEqual("JDF.jdf", bp.Name);
        }
Esempio n. 6
0
        public virtual void testWriteToURLFile()
        {
            testBuildMimePackageDocJMF();

            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");
            FileInfo             f1 = new FileInfo(sm_dirTestDataTemp + "testMimePackageDoc3.mjm");

            MimeUtil.writeToURL(mp, UrlUtil.fileToUrl(f1, false));
            FileInfo f2 = new FileInfo(sm_dirTestDataTemp + "testMimePackageDoc.mjm");

            Assert.IsTrue(f1.Exists);
            Assert.AreEqual(f1.Length, f2.Length, 100);
        }
Esempio n. 7
0
        public virtual void testPerformanceGet()
        {
            long write = JDFDate.ToMillisecs(DateTime.Now);
            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "performance.mjm");
            long getMP = JDFDate.ToMillisecs(DateTime.Now);

            Console.WriteLine("get multipart time: " + (getMP - write));
            Attachment bp     = MimeUtil.GetPartByCID(mp, "bigger.pdf");
            long       getCID = JDFDate.ToMillisecs(DateTime.Now);

            Console.WriteLine("get big time: " + (getCID - getMP));
            Assert.IsNotNull(bp);
            Assert.AreEqual("bigger.pdf", bp.Name);
        }
Esempio n. 8
0
        public virtual void testWriteToDir()
        {
            testBuildMimePackageDocJMF();

            AttachmentCollection mp        = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");
            DirectoryInfo        directory = new DirectoryInfo(sm_dirTestDataTemp + "TestWriteMime");

            if (directory.Exists)
            {
                directory.Delete();
            }
            MimeUtil.WriteToDir(mp, directory);
            Assert.IsTrue(new FileInfo(sm_dirTestDataTemp + "TestWriteMime/" + "test.icc").Exists);
        }
Esempio n. 9
0
        public virtual void testReplaceContents()
        {
            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));
            AttachmentCollection mp = MimeUtil.buildMimePackage(null, doc, true);

            Assert.AreEqual(2, mp.Count, "JDF,  1 icc");

            Attachment bp = mp[1];

            Assert.IsNotNull(bp);
            MimeUtil.SetAttachmentContent(bp, "hello World");

            Attachment bp2 = mp[1];

            Assert.AreEqual("hello World", MimeUtil.GetAttachmentContent(bp2));

            string mimeFile = sm_dirTestDataTemp + "testReplaceContents";

            MimeUtil.writeToFile(mp, mimeFile + ".mjm", null);

            AttachmentCollection mp2  = MimeUtil.GetMultiPart(mimeFile + ".mjm");
            Attachment           bp21 = mp2[1];

            Assert.AreEqual("hello World", MimeUtil.GetAttachmentContent(bp21));

            Attachment bp22 = mp2[1];

            Assert.IsNotNull(bp22);
            MimeUtil.SetAttachmentContent(bp22, "bye World");
            Assert.AreEqual("bye World", MimeUtil.GetAttachmentContent(bp22));
            Attachment bp23 = mp2[1];

            Assert.AreEqual(bp22, bp23);

            MimeUtil.writeToFile(mp2, mimeFile + "_1.mjm", null);
            AttachmentCollection mp3  = MimeUtil.GetMultiPart(mimeFile + "_1.mjm");
            Attachment           bp31 = mp3[1];

            Assert.AreEqual("bye World", MimeUtil.GetAttachmentContent(bp31));
        }
Esempio n. 10
0
        public virtual void testWriteToFile()
        {
            testBuildMimePackageDocJMF();

            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");

            MimeUtil.writeToFile(mp, sm_dirTestDataTemp + "testMimePackageDoc2.mjm", null);
            FileInfo f1 = new FileInfo(sm_dirTestDataTemp + "testMimePackageDoc2.mjm");
            FileInfo f2 = new FileInfo(sm_dirTestDataTemp + "testMimePackageDoc.mjm");

            Assert.IsTrue(f1.Exists);
            Assert.AreEqual(f1.Length, f2.Length, 100);
            AttachmentCollection mp2 = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc2.mjm");

            Assert.IsNotNull(mp2);
            Assert.AreEqual(mp.Count, mp2.Count);
        }
Esempio n. 11
0
        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());
        }
Esempio n. 12
0
        public virtual void testGetJDFDoc()
        {
            testBuildMimePackageDocJMF();
            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");
            Attachment           bp = MimeUtil.GetPartByCID(mp, "JDF.jdf");

            Assert.IsNotNull(bp);
            Attachment bp2 = MimeUtil.GetPartByCID(mp, "CID:JDF.jdf");

            Assert.AreEqual(bp, bp2);
            Attachment bp3 = MimeUtil.GetPartByCID(mp, "<cid:JDF.jdf>");

            Assert.AreEqual(bp, bp3);
            Assert.AreEqual("JDF.jdf", bp.Name);
            JDFDoc d = MimeUtil.getJDFDoc(bp);

            Assert.IsNotNull(d);
            JDFNode n = d.getJDFRoot();

            Assert.IsNotNull(n);
        }
Esempio n. 13
0
        public virtual void testUpdateXMLMultipart()
        {
            AttachmentCollection multipart = null;
            JDFDoc jDoc = new JDFDoc("JMF");

            MimeUtil.updateXMLMultipart(multipart, jDoc, null);
            string mimeFile = sm_dirTestDataTemp + "testUpdateXML";

            MimeUtil.writeToFile(multipart, mimeFile + "0.mjm", null);
            AttachmentCollection multiparsed = MimeUtil.GetMultiPart(mimeFile + "0.mjm");
            Attachment           bp          = multiparsed[0];

            Assert.IsTrue(bp.ContentId.Length > 5, "cid >cid_");

            JDFDoc jDoc1 = new JDFDoc("JDF");

            jDoc1.setOriginalFileName("jdf1.jdf");

            MimeUtil.updateXMLMultipart(multipart, jDoc1, null);

            MimeUtil.writeToFile(multipart, mimeFile + "1.mjm", null);
            multiparsed = MimeUtil.GetMultiPart(mimeFile + "1.mjm");
            bp          = multiparsed[0];
            Assert.IsTrue(bp.ContentId.Length > 5, "cid >cid_");

            JDFDoc jDoc2 = new JDFDoc("JDF");

            jDoc2.setOriginalFileName("jdf1.jdf");
            jDoc2.getJDFRoot().setDescriptiveName("updated jdf");
            MimeUtil.updateXMLMultipart(multipart, jDoc2, "jdf1.jdf");
            MimeUtil.writeToFile(multipart, mimeFile + "2.mjm", null);

            AttachmentCollection multipart3 = MimeUtil.GetMultiPart(mimeFile + "2.mjm");

            jDoc2.getJDFRoot().setDescriptiveName("3rd jdf");
            MimeUtil.updateXMLMultipart(multipart3, jDoc2, "jdf2.jdf");
            MimeUtil.writeToFile(multipart3, mimeFile + "3.mjm", null);
        }
Esempio n. 14
0
        public virtual void testBuildMimePackage()
        {
            JDFDoc d1 = new JDFDoc("JMF");

            d1.setOriginalFileName("JMF.jmf");
            JDFDoc d2 = new JDFDoc("JDF");

            d2.setOriginalFileName("JDF.jdf");
            ArrayList vXMLDocs = new ArrayList();

            vXMLDocs.Add(d1);
            vXMLDocs.Add(d2);

            AttachmentCollection m    = MimeUtil.buildMimePackage(vXMLDocs);
            FileInfo             file = MimeUtil.writeToFile(m, sm_dirTestDataTemp + "test.mjm", null);

            AttachmentCollection aBp = MimeUtil.GetMultiPart(file.FullName);

            Assert.AreEqual(2, aBp.Count);

            Assert.AreEqual("JMF.jmf", aBp[0].Name);
            Assert.AreEqual("JDF.jdf", aBp[1].Name);
        }
Esempio n. 15
0
        public virtual void testWriteToFileMimeDetails()
        {
            testBuildMimePackageDocJMF();

            MIMEDetails md = new MIMEDetails();

            md.modifyBoundarySemicolon = true;
            AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc.mjm");

            MimeUtil.writeToFile(mp, sm_dirTestDataTemp + "testMimePackageDoc2.mjm", md);
            FileInfo f2 = new FileInfo(sm_dirTestDataTemp + "testMimePackageDoc2.mjm");
            FileInfo f1 = new FileInfo(sm_dirTestDataTemp + "testMimePackageDoc.mjm");

            Assert.IsTrue(f2.Exists);
            Assert.AreEqual(f1.Length, f2.Length, 100);
            AttachmentCollection mp2 = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "testMimePackageDoc2.mjm");

            Assert.IsNotNull(mp2);
            Assert.AreEqual(mp.Count, mp2.Count);
            MemoryStream sw = new MemoryStream();

            IOUtils.CopyStream(new FileStream(f2.FullName, FileMode.Open), sw);
            Assert.AreEqual(-1, sw.ToString().IndexOf("related;"));
        }
Esempio n. 16
0
        /// <summary>
        /// Get an array of urlparts, regardless of whether this was mime or not if the stream is mime/multipart also extract that
        /// </summary>
        /// <param name="connection">Web request/response</param>
        /// <returns>The array of body parts input stream </returns>
        ///
        public static UrlPart[] GetURLParts(HttpWebRequest connection)
        {
            if (connection == null)
            {
                return(null);
            }

            string contentType;

            try
            {
                contentType = connection.GetResponse().Headers.Get("Content-Type");
            }
            catch (ArgumentNullException)
            {
                contentType = null;
            }

            string urlContentType = contentType;

            if (!MimeUtil.MULTIPART_RELATED.ToLower().Equals(urlContentType.ToLower()))
            {
                UrlPart p;
                try
                {
                    p = new UrlPart(connection);
                }
                catch (IOException)
                {
                    return(null);
                }
                return(new UrlPart[] { p });
            }

            AttachmentCollection attachments;

            try
            {
                attachments = MimeUtil.GetMultiPart(connection.GetResponse().GetResponseStream());
            }
            catch (IOException)
            {
                return(null);
            }

            if (attachments == null)
            {
                return(null);
            }
            UrlPart[] parts = new UrlPart[attachments.Count];

            int i = 0;

            foreach (Attachment attatchment in attachments)
            {
                try
                {
                    ContentType ct = attatchment.ContentType;
                    parts[i] = new UrlPart(attatchment);
                }
                catch (HttpException)
                {
                    parts[i] = null;
                }
                catch (IOException)
                {
                    parts[i] = null;
                }
                ++i;
            }
            return(parts);
        }