/// <summary> /// The method Get Signed PDF. /// </summary> /// <param name="data"> /// The byte array[] /// </param> /// <returns> /// The <see cref="byte[]" />. /// </returns> public byte[] GetSignedPDF(byte[] data) { DateTime startTime = _logger.MethodTraceStartTime(); PDFSign pdfSign = Const.pdfSignPool.Rent() as PDFSign; if (Const.certificateInfo == null) { try { CertificateInfo certificateInfo = Const.certificateInfo = new CertificateInfo(); string reason = ConfigurationManager.AppSettings["SIGN_REASON"]; _logger.WriteDebug(String.Format("Reason :{0}", reason)); string location = ConfigurationManager.AppSettings["SIGN_LOCATION"]; _logger.WriteDebug(String.Format("Location :{0}", location)); string password = ConfigurationManager.AppSettings["PASSWORD"]; _logger.WriteDebug(String.Format("Password :{0}", password)); //string certificatePath = HttpContext.Current.Server.MapPath("~")+ConfigurationManager.AppSettings["CERTIFICATE_PATH"]; string certificatePath = ConfigurationManager.AppSettings["CERTIFICATE_PATH"]; _logger.WriteDebug(String.Format("Certificate Path :{0}", certificatePath)); //certificatePath =HttpContext.Current.Server.MapPath("~")+certificatePath; certificatePath = HostingEnvironment.ApplicationPhysicalPath + certificatePath; _logger.WriteDebug(String.Format("Final Certificate Path :{0}", certificatePath)); certificateInfo.Location = location; certificateInfo.Password = password; certificateInfo.Reason = reason; certificateInfo.CertificatePath = certificatePath; if (!String.IsNullOrWhiteSpace(certificateInfo.CertificatePath) || !String.IsNullOrWhiteSpace(certificateInfo.Password)) { certificateInfo.LoadCertificate(); } Const.certificateInfo = certificateInfo; } catch (Exception ex) { Const.certificateInfo = null; _logger.WriteError(ex); throw; } } //return pdfSign.sign(data, Const.certificateInfo.r, signInfo.location); var pdf = pdfSign.sign(data, Const.certificateInfo.Pkcs12Store, Const.certificateInfo.Password, Const.certificateInfo.Reason, Const.certificateInfo.Location, DateTime.Now); Const.pdfSignPool.Return(pdfSign); _logger.MethodTraceEnd(startTime); return(pdf); }
public void TestMethod1() { string path = @"C:\Users\Moinul\Desktop\certificate\SignTemplate_1.pdf"; byte[] bytes = System.IO.File.ReadAllBytes(path); List <PDFSign> PDFSignList = new List <PDFSign>(); PDFSign pdf = new PDFSign(); //byte[] signbytes=new byte[1]; ObjectPool <PDFSign> objectPool = new ObjectPool <PDFSign>(); PDFSign a, a1, a2; a = objectPool.Rent() as PDFSign; //a1 = objectPool.Rent() as PDFSign; //a2 = objectPool.Rent() as PDFSign; //a._executed = true; //a1._executed = true; //a2._executed = true; //Thread t1 = new Thread(() => //{ // Thread.Sleep(10000); // a = objectPool.Rent() as PDFSign; // Thread.Sleep(10000); // a._executed = true; // Thread.Sleep(10000); //}); //Thread t2 = new Thread(() => //{ // Thread.Sleep(10000); // a1 = objectPool.Rent() as PDFSign; // Thread.Sleep(10000); // a1._executed = true; // Thread.Sleep(10000); //}); //t1.Start(); //t2.Start(); //Parallel.For(0, 100, (i, state) => { // //Console.WriteLine(i); if (i == 50) state.Stop(); // a = objectPool.Rent() as PDFSign; // //if (objectPool.IsEmptyPool()) // if(!a._executed) // { // signbytes=a.sign(bytes, "This Document has been certified by National Board of Revenue", "Dhaka, Bangladesh"); // } // else { // signbytes=a.sign(bytes); // } // File.WriteAllBytes(@"C:\Users\Moinul\Desktop\HP\SignTemplate"+i+"_"+DateTime.Now.Minute+"_"+DateTime.Now.Millisecond+".pdf", signbytes); //}); //int largest = arr[0]; //Parallel.ForEach(Partitioner.Create(0, arr.Length), () => arr[0], (range, loop, subtotal)=> //{ // Your stuff //}); //Parall for(int i=0; i <100; i++){ // var a = objectPool.Rent() as PDFSign; // if (objectPool.IsEmptyPool()) // { // signbytes=a.sign(bytes, "This Document has been certified by National Board of Revenue", "Dhaka, Bangladesh"); // } // else { // signbytes=a.sign(bytes); // } // File.WriteAllBytes(@"C:\Users\DELL\Desktop\HP\SignTemplate.pdf", signbytes); //} byte[] signbytes = pdf.sign(bytes, "This Document has been certified by Moinul For Test Purpose", "Dhaka, Bangladesh"); //byte[] signbytes = pdf.mangosign(bytes, "\\Content\\PDF\\"); File.WriteAllBytes(@"C:\Users\Moinul\Desktop\certificate\SignTemplate_sign.pdf", signbytes); }
public byte[] GetSignedPDF(byte[] data, SignInfo signInfo) { PDFSign pdfSign = new PDFSign(); return(pdfSign.sign(data, signInfo.Reason, signInfo.location)); }