Пример #1
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));
        }
Пример #2
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
     }
 }
Пример #3
0
        public virtual void testResolveRelativeUrls()
        {
            // Build MIME package
            string path   = sm_dirTestData + "MISPrepress-ICS-Complex.jdf";
            JDFDoc jdfDoc = new JDFParser().parseFile(path);

            Assert.IsNotNull(jdfDoc, "Could not parse JDF: " + path);
            AttachmentCollection multipart = MimeUtil.buildMimePackage(null, jdfDoc, true);

            Assert.IsNotNull(multipart, "Could not build multipart");
            // Verify contents
            Assert.AreEqual(3, multipart.Count);
            JDFDoc jdfDoc2 = MimeUtil.getJDFDoc(multipart[0]);

            Assert.IsNotNull(jdfDoc2);
            JDFNode jdf = jdfDoc2.getJDFRoot();

            Assert.IsNotNull(jdf);
            VElement fileSpecs = jdf.getChildrenByTagName(ElementName.FILESPEC, null, new JDFAttributeMap(AttributeName.URL, "*"), false, false, 0);

            Assert.AreEqual(3, fileSpecs.Count);
            for (IEnumerator i = fileSpecs.GetEnumerator(); i.MoveNext();)
            {
                JDFFileSpec fileSpec = (JDFFileSpec)i.Current;
                string      cid      = fileSpec.getURL();
                Assert.IsTrue(cid.StartsWith("cid:"));
                Assert.IsNotNull(MimeUtil.GetPartByCID(multipart, cid));
            }
        }
Пример #4
0
        /// <summary>
        /// Get a readable inputstream from the CID url
        /// </summary>
        /// <param name="url">The url to get a stream for </param>
        /// <param name="multipart">The multipart mime to which the cid refers</param>
        /// <returns>The readable input stream that this filespec refers to, or null if broken or non-existent</returns>
        ///
        public static Stream GetCidURLStream(string url, AttachmentCollection multipart)
        {
            if (url == null || url.Equals(JDFConstants.EMPTYSTRING))
            {
                return(null);
            }
            System.Net.Mail.Attachment bp = MimeUtil.GetPartByCID(multipart, url);
            if (bp == null)
            {
                return(null);
            }

            try
            {
                return(bp.ContentStream);
            }
            catch (System.IO.IOException)
            {
                /* */
            }
            catch (System.Web.HttpException)
            {
                /* */
            }
            return(null); // snafu exit
        }
Пример #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);
        }
Пример #6
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);
        }
Пример #7
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);
        }