public static Attachment ToAttachment(NSJSValue value) { if (value == null) { return(null); } if (value is NSJSString) { string path = ((NSJSString)value).Value; if (!File.Exists(path)) { return(null); } return(new Attachment(path)); } if (value is NSJSObject) { NSJSObject o = (NSJSObject)value; string fileName = o.Get("FileName").As <string>(); string mediaType = o.Get("MediaType").As <string>(); string blobName = o.Get("Name").As <string>(); Stream contentStream = NSJSStream.Get(o.Get("ContentStream") as NSJSObject); if (contentStream != null && !string.IsNullOrEmpty(blobName)) { return(new Attachment(contentStream, blobName, mediaType)); } if (!File.Exists(fileName)) { return(null); } return(new Attachment(fileName, mediaType)); } return(null); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, HttpPostedFile file) { if (machine == null) { return(null); } if (file == null) { return(NSJSValue.Null(machine)); } NSJSObject objective = NSJSObject.New(machine); objective.Set("ContentLength", file.ContentLength); objective.Set("ContentType", file.ContentType); objective.Set("FileName", file.FileName); objective.Set("InputStream", NSJSValue.NullMerge(machine, NSJSStream.New(machine, file.InputStream))); return(objective); }
private static HttpClientResponse object2response(NSJSObject response) { if (response == null) { return(null); } HttpClientResponse o = new HttpClientResponse(); NSJSBoolean boolean = response.Get("ManualWriteToStream") as NSJSBoolean; if (boolean != null) { o.ManualWriteToStream = boolean.Value; } NSJSObject objectt = response.Get("ContentStream") as NSJSObject; if (objectt != null) { o.ContentStream = NSJSStream.Get(objectt); } return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, NSJSObject context, HTTPRequest request) { if (machine == null || context == null || request == null) { return(null); } NSJSObject objective = NSJSObject.New(machine); objective.Set("HttpMethod", request.HttpMethod); objective.Set("IsLocal", request.IsLocal); objective.Set("KeepAlive", request.KeepAlive); objective.Set("ContentType", request.ContentType); objective.Set("CurrentContext", context); objective.Set("Files", ObjectAuxiliary.ToObject(machine, request.Files)); objective.Set("InputStream", NSJSValue.NullMerge(machine, NSJSStream.New(machine, request.InputStream))); objective.Set("Cookies", ArrayAuxiliary.ToArray(machine, request.Cookies)); objective.Set("RequestTraceIdentifier", request.RequestTraceIdentifier.ToString()); // "D" objective.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, request.RemoteEndPoint)); objective.Set("ContentEncoding", NSJSEncoding.New(machine, request.ContentEncoding ?? NSJSEncoding.DefaultEncoding)); objective.Set("Form", ObjectAuxiliary.ToObject(machine, request.Form)); objective.Set("QueryString", ObjectAuxiliary.ToObject(machine, request.QueryString)); objective.Set("ContentLength", Convert.ToDouble(request.ContentLength)); objective.Set("AcceptTypes", ArrayAuxiliary.ToArray(machine, request.AcceptTypes)); objective.Set("Path", request.Path); objective.Set("RawUrl", request.RawUrl); objective.Set("ServiceName", request.ServiceName); objective.Set("Url", request.Url?.ToString()); objective.Set("UrlReferrer", request.UrlReferrer?.ToString()); objective.Set("UserAgent", request.UserAgent); objective.Set("UserHostAddress", request.UserHostAddress); objective.Set("UserHostName", request.UserHostName); objective.Set("ProtocolVersion", request.ProtocolVersion.ToString()); objective.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, request.LocalEndPoint)); objective.Set("UserLanguages", ArrayAuxiliary.ToArray(machine, request.UserLanguages)); return(objective); }