示例#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
文件: UrlUtil.cs 项目: cip4/JDFLibNet
        /// <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);
        }