public Base64EncodedByteArrayInstance ConcatenatePdfDocuments(string html, object pdfsToAppend) { IEnumerable <Base64EncodedByteArrayInstance> pdfsToAppendInstances = null; if (pdfsToAppend != null && pdfsToAppend != Undefined.Value && pdfsToAppend != Null.Value && pdfsToAppend is ArrayInstance) { pdfsToAppendInstances = (pdfsToAppend as ArrayInstance).ElementValues.OfType <Base64EncodedByteArrayInstance>(); } IList <byte[]> pdfsToAppendData = null; if (pdfsToAppendInstances != null) { pdfsToAppendData = pdfsToAppendInstances.Select(p => p.Data) .ToList(); } var result = HtmlConverterHelper.MergeFiles(html, pdfsToAppendData, this.WinnovativeHtmlToPdfConverterLicenseKey); var byteResult = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, result) { MimeType = "application/pdf" }; return(byteResult); }
public object Bundle(string bundleDefinitionXml, string fileName, object update, object minify) { if (String.IsNullOrEmpty(fileName)) { fileName = "bundle.txt"; } var bUpdate = JurassicHelper.GetTypedArgumentValue(Engine, update, true); var bMinify = JurassicHelper.GetTypedArgumentValue(Engine, minify, false); var doc = new XmlDocument(); doc.LoadXml(bundleDefinitionXml); var bundleText = GenerateBundleFromBundleDefinition(fileName, doc, bUpdate, bMinify); var bytes = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, Encoding.UTF8.GetBytes(bundleText)) { FileName = fileName, MimeType = StringHelper.GetMimeTypeFromFileName(fileName), }; var result = Engine.Object.Construct(); result.SetPropertyValue("lastModified", JurassicHelper.ToDateInstance(Engine, FileModifiedDates.Values.Max(v => v.Item1)), false); result.SetPropertyValue("data", bytes, false); return(result); }
public Base64EncodedByteArrayInstance Html2Pdf(string html, object pdfAttachments) { IEnumerable <PdfAttachmentInstance> pdfAttachmentInstances = null; if (pdfAttachments != null && pdfAttachments != Undefined.Value && pdfAttachments != Null.Value && pdfAttachments is ArrayInstance) { pdfAttachmentInstances = (pdfAttachments as ArrayInstance).ElementValues.OfType <PdfAttachmentInstance>(); } IList <PdfAttachment> attachments = null; if (pdfAttachmentInstances != null) { attachments = pdfAttachmentInstances.Select(p => new PdfAttachment { FileName = p.FileName, FileDisplayName = p.FileDisplayName, Description = p.Description, Data = p.Data != null ? p.Data.Data : null, }) .ToList(); } var result = HtmlConverterHelper.ConvertHtmlToPdf(new List <string> { html }, attachments, this.WinnovativeHtmlToPdfConverterLicenseKey); var byteResult = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, result) { MimeType = "application/pdf" }; return(byteResult); }
public Base64EncodedByteArrayInstance GZip(object obj, object fileName, object mimeType) { byte[] data; if (obj is Base64EncodedByteArrayInstance) { var b = obj as Base64EncodedByteArrayInstance; if (fileName == Undefined.Value || fileName == Null.Value || fileName == null) { fileName = b.FileName; } if (mimeType == Undefined.Value || mimeType == Null.Value || mimeType == null) { mimeType = b.MimeType; } data = b.Data; } else { data = Encoding.UTF8.GetBytes(TypeConverter.ToString(obj)); } Base64EncodedByteArrayInstance result; using (var inStream = new MemoryStream(data)) { using (var outStream = new MemoryStream()) { using (var compress = new GZipStream(outStream, CompressionMode.Compress)) { // Copy the source file into the compression stream. byte[] buffer = new byte[4096]; int numRead; while ((numRead = inStream.Read(buffer, 0, buffer.Length)) != 0) { compress.Write(buffer, 0, numRead); } } result = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, outStream.ToArray()); if (fileName != Undefined.Value && fileName != Null.Value && fileName != null) { result.FileName = TypeConverter.ToString(fileName); } if (mimeType != Undefined.Value && mimeType != Null.Value && mimeType != null) { result.MimeType = TypeConverter.ToString(mimeType); } } } return(result); }
public string GetString(Base64EncodedByteArrayInstance bytes) { if (bytes == null) { return(null); } var result = m_encoding.GetString(bytes.Data); return(result); }
public void AddFile(string fileName, Base64EncodedByteArrayInstance fileData) { var entry = new ZipEntry(fileName) { DateTime = DateTime.Now, Size = fileData.Data.LongLength }; m_zipOutputStream.PutNextEntry(entry); m_zipOutputStream.Write(fileData.Data, 0, fileData.Data.Length); m_zipOutputStream.CloseEntry(); }
public Base64EncodedByteArrayInstance GetBytes(object fileName) { var data = m_excelPackage.GetAsByteArray(); var result = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, data) { MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }; if (fileName != null && fileName != Undefined.Value) { result.FileName = TypeConverter.ToString(fileName); } return(result); }
public object SerializeObject(object objectToSerialize) { if (objectToSerialize == Null.Value || objectToSerialize == Undefined.Value || objectToSerialize == null) { return(Null.Value); } var serializer = new BinaryFormatter(); Base64EncodedByteArrayInstance result; using (var stream = new MemoryStream()) { serializer.Serialize(stream, objectToSerialize); result = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, stream.ToArray()); } return(result); }
public Base64EncodedByteArrayInstance Finish() { m_zipOutputStream.Finish(); m_zipOutputStream.Flush(); m_memoryStream.Seek(0, SeekOrigin.Begin); byte[] result = new byte[m_memoryStream.Length]; m_memoryStream.ReadWholeArray(result); m_memoryStream.Dispose(); m_memoryStream = null; m_zipOutputStream = null; var byteResult = new Base64EncodedByteArrayInstance(this.Engine.Object.InstancePrototype, result) { FileName = this.FileName, MimeType = StringHelper.GetMimeTypeFromFileName(this.FileName) }; return(byteResult); }
protected object GetResultFromResponse(HttpWebResponse response, AjaxDataType dataType) { object resultObject = null; if (response.StatusCode == HttpStatusCode.OK) { using (var stream = response.GetResponseStream()) { var resultData = stream.ToByteArray(); var result = Encoding.UTF8.GetString(resultData); var success = false; //If there is no contents, return undefined. if (resultData.Length == 0) { resultObject = Undefined.Value; success = true; } if (dataType == AjaxDataType.Unknown || dataType == AjaxDataType.Json) { //Attempt to convert the result into Json if (!success) { try { resultObject = JSONObject.Parse(Engine, result, null); success = true; } catch { /* Do Nothing. */ } } } if (dataType == AjaxDataType.Unknown || dataType == AjaxDataType.Xml) { if (!success) { //Attempt to convert the result into Xml try { XDocument doc; using (var xmlStream = new MemoryStream(resultData)) { using (var xmlReader = new XmlTextReader(xmlStream)) { doc = XDocument.Load(xmlReader); } } var jsonDocument = JsonConvert.SerializeXmlNode(doc.Root.GetXmlNode()); resultObject = JSONObject.Parse(Engine, jsonDocument, null); success = true; } catch { /* Do Nothing. */ } } } if (dataType == AjaxDataType.Unknown || dataType == AjaxDataType.Raw) { if (!success) { //If we couldn't convert as json or xml, use it as a byte array. resultObject = new Base64EncodedByteArrayInstance(Engine.Object.InstancePrototype, resultData); } } } } else { resultObject = String.Format("Error attempting to retrieve {2}: {0} {1}", response.StatusCode, response.StatusDescription, response.ResponseUri); } return(resultObject); }