public static NSJSValue ToObject(NSJSVirtualMachine machine, IPHostEntry host) { if (machine == null) { return(null); } if (host == null) { return(NSJSValue.Null(machine)); } NSJSObject entry = NSJSObject.New(machine); entry.Set("HostName", host.HostName); entry.Set("AddressList", ArrayAuxiliary.ToArray(machine, host.AddressList)); string[] aliases = host.Aliases; NSJSArray array = NSJSArray.New(machine, aliases.Length); for (int i = 0; i < aliases.Length; i++) { array[i] = NSJSString.New(machine, aliases[i]); } entry.Set("Aliases", array); return(entry); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, IDictionary <string, string> s) { if (machine == null) { return(null); } NSJSObject obj = NSJSObject.New(machine); if (s != null) { foreach (KeyValuePair <string, string> kv in s) { if (string.IsNullOrEmpty(kv.Key)) { continue; } if (kv.Value == null) { obj.Set(kv.Key, NSJSValue.Null(machine)); } else { obj.Set(kv.Key, kv.Value); } } } return(obj); }
public static NSJSObject New(NSJSVirtualMachine machine, HTTPApplication application) { if (machine == null || application == null) { return(null); } NSJSObject objective = NSJSObject.New(machine); objective.DefineProperty("Name", g_NameProc, g_NameProc); objective.DefineProperty("Root", g_RootProc, g_RootProc); objective.Set("Start", g_StartProc); objective.Set("Stop", g_StopProc); objective.Set("Close", g_CloseProc); objective.Set("Dispose", g_CloseProc); application.Tag = objective; objective.CrossThreading = true; application.Handler = new HttpHandler(objective, application); application.EndProcessRequest += g_EndProcessRequestProc; application.BeginProcessRequest += g_BeginProcessRequestProc; NSJSKeyValueCollection.Set(objective, application); return(objective); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, NameValueCollection s) { if (machine == null) { return(null); } NSJSObject obj = NSJSObject.New(machine); if (s != null) { foreach (string key in s.AllKeys) { if (string.IsNullOrEmpty(key)) { continue; } string value = s.Get(key); string name = key.ToLower(); if (value != null) { obj.Set(name, value); } else { obj.Set(name, NSJSValue.Null(machine)); } } } return(obj); }
public static NSJSObject GetMessageEventData(NSJSVirtualMachine machine, EventArgs e) { if (machine == null || e == null) { return(null); } MessageEventArgs message = e as MessageEventArgs; if (message == null) { return(null); } NSJSObject data = NSJSObject.New(machine); data.Set("IsText", message.IsText); if (message.IsText) { data.Set("RawData", message.Message); } else // BLOB { data.Set("RawData", message.RawData); } return(data); }
public static NSJSObject NewContextObject(NSJSVirtualMachine machine, NSJSObject application, HTTPContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (application == null) { throw new ArgumentNullException("application"); } if (machine == null) { throw new ArgumentNullException("machine"); } NSJSObject objective = NSJSObject.New(machine); // ctx objective.Set("Application", application); objective.Set("Close", m_CloseProc); objective.Set("Dispose", m_CloseProc); objective.Set("Request", HttpRequest.New(machine, objective, context.Request)); objective.Set("Response", HttpResponse.New(machine, objective, context.Response)); objective.DefineProperty("Asynchronous", m_AsynchronousProc, m_AsynchronousProc); NSJSKeyValueCollection.Set(objective, context); return(objective); }
private NSJSObject New(NSJSVirtualMachine machine, RijndaelCryptoServiceProvider provider) { NSJSObject o = NSJSObject.New(machine); o.Set("Encrypt", this.m_EncryptProc); o.Set("Decrypt", this.m_DecryptProc); o.Set("Dispose", this.m_DisposeProc); NSJSKeyValueCollection.Set(o, provider); return(o); }
private static NSJSObject New(NSJSVirtualMachine machine, RC4CSP provider) { NSJSObject o = NSJSObject.New(machine); o.Set("Encrypt", m_EncryptProc); o.Set("Decrypt", m_DecryptProc); o.Set("Dispose", m_DisposeProc); NSJSKeyValueCollection.Set(o, provider); return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, MailClient smtp) { if (machine == null || smtp == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("Send", g_SendProc); o.Set("SendAsync", m_SendAsyncProc); o.Set("Close", g_CloseProc); o.Set("Dispose", g_CloseProc); NSJSKeyValueCollection.Set(o, smtp); return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, IDbTransaction transaction) { if (machine == null || transaction == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("Commit", g_CommitProc); o.Set("Rollback", g_RollbackProc); o.Set("Close", g_CloseProc); o.Set("Dispose", g_CloseProc); NSJSKeyValueCollection.Set(o, transaction); return(o); }
public static NSJSValue ToArray(NSJSVirtualMachine machine, DataTable dataTable) { if (machine == null) { return(null); } DataRowCollection rows = null; int count = dataTable == null ? 0 : (rows = dataTable.Rows).Count; NSJSArray results = NSJSArray.New(machine, count); if (count <= 0) { return(results); } IDictionary <string, int> columns = new Dictionary <string, int>(); foreach (DataColumn column in dataTable.Columns) { columns.Add(column.ColumnName, column.Ordinal); } for (int i = 0; i < count; i++) { NSJSObject item = NSJSObject.New(machine); DataRow row = rows[i]; results[i] = item; foreach (KeyValuePair <string, int> column in columns) { object value = row[column.Value]; item.Set(column.Key, value.As(machine)); } } return(results); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, HttpFileCollection files) { if (machine == null) { return(null); } if (files == null) { return(NSJSValue.Null(machine)); } NSJSObject owner = NSJSObject.New(machine); foreach (string key in files.AllKeys) { if (string.IsNullOrEmpty(key)) { continue; } HttpPostedFile fileinfo = files[key]; if (fileinfo == null) { continue; } owner.Set(key, ToObject(machine, fileinfo)); } return(owner); }
private static void OnBeginProcessRequest(object sender, HttpBeginProcessRequestEventArgs e) { DoProcessRequest(sender, (application, origin, machine) => { NSJSFunction callback = origin.Get("BeginProcessRequest") as NSJSFunction; if (callback != null) { NSJSObject args = NSJSObject.New(machine); args.Set("Cancel", e.Cancel); args.Set("Application", origin); args.Set("CurrentContext", HttpHandler.NewContextObject(machine, origin, e.CurrentContext)); callback.Call(args); e.Cancel = args.Get("Cancel").As <bool>(); } }); }
private static void GetConfigurationView(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); string path = GetFullPath(arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null); if (File.Exists(path)) { NSJSObject configuration = NSJSObject.New(arguments.VirtualMachine); foreach (string section in GetAllSection(path)) { if (string.IsNullOrEmpty(section)) { continue; } NSJSObject sectionObject = NSJSObject.New(arguments.VirtualMachine); foreach (KeyValuePair <string, string> kv in GetAllKeyValue(path, section)) { if (string.IsNullOrEmpty(kv.Key)) { continue; } sectionObject.Set(kv.Key, kv.Value); } configuration.Set(section, sectionObject); } arguments.SetReturnValue(configuration); } }
public static NSJSValue ToObject(NSJSVirtualMachine machine, EncodingInfo encoding) { if (machine == null) { return(null); } if (encoding == null) { return(NSJSValue.Null(machine)); } NSJSObject obj = NSJSObject.New(machine); obj.Set("Name", encoding.Name); obj.Set("DisplayName", encoding.DisplayName); obj.Set("CodePage", encoding.CodePage); return(obj); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, IDbDataParameter parameter) { if (machine == null) { return(null); } if (parameter == null) { return(NSJSValue.Null(machine)); } NSJSObject o = NSJSObject.New(machine); o.Set("Name", parameter.ParameterName); o.Set("IsNullable", parameter.IsNullable); o.Set("DbType", unchecked ((int)parameter.DbType)); return(o); }
public static NSJSValue New(NSJSVirtualMachine machine, MSSQLDatabaseAccessAdapter adapter) { if (machine == null) { return(null); } if (adapter == null) { return(NSJSValue.Null(machine)); } NSJSObject self = NSJSObject.New(machine); self.UserToken = adapter; self.Set("Close", g_CloseProc); self.Set("Dispose", g_CloseProc); return(self); }
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); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, IPAddress address) { if (machine == null) { return(null); } if (address == null) { return(NSJSValue.Null(machine)); } NSJSObject o = NSJSObject.New(machine); if (address.AddressFamily == AddressFamily.InterNetworkV6) { o.Set("ScopeId", address.ScopeId); } o.Set("AddressFamily", (int)address.AddressFamily); o.Set("Address", address.ToString()); o.Set("AddressBytes", address.GetAddressBytes()); return(o); }
private static NSJSObject New(NSJSVirtualMachine machine, WebSocketListener server) { if (machine == null || server == null) { return(null); } NSJSObject objective = NSJSObject.New(machine); objective.Set("Port", server.Port); objective.Set("GetBindPort", g_GetBindPortProc); objective.Set("Stop", g_StopProc); objective.Set("Start", g_StartProc); objective.Set("Close", g_CloseProc); objective.Set("Dispose", g_CloseProc); server.UserToken = objective; objective.CrossThreading = true; server.OnMessage += (websocket, e) => ProcessEvent(objective, websocket, "OnMessage", e); server.OnOpen += (websocket, e) => ProcessEvent(objective, websocket, "OnOpen", e, true); server.OnError += (websocket, e) => ProcessEvent(objective, websocket, "OnError", e); server.OnClose += (websocket, e) => ProcessEvent(objective, websocket, "OnClose", e); NSJSKeyValueCollection.Set(objective, server); return(objective); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, EndPoint endpoint) { if (machine == null) { return(null); } if (endpoint == null) { return(NSJSValue.Null(machine)); } NSJSObject obj = NSJSObject.New(machine); obj.Set("AddressFamily", (int)endpoint.AddressFamily); IPEndPoint ipep = endpoint as IPEndPoint; if (ipep != null) { obj.Set("Address", ToObject(machine, ipep.Address)); obj.Set("Port", ipep.Port); } return(obj); }
public static NSJSValue ToObject(NSJSVirtualMachine machine, KeyValuePair <string, string> kv) { if (machine == null) { return(null); } if (string.IsNullOrEmpty(kv.Key)) { return(null); } NSJSObject obj = NSJSObject.New(machine); obj.Set("Key", kv.Key); if (kv.Value == null) { obj.Set("Value", NSJSValue.Null(machine)); } else { obj.Set("Value", kv.Value); } return(obj); }
public static int Fill(NSJSValue source, NSJSValue destination) { NSJSObject sourceObject = source as NSJSObject; NSJSObject destinationObject = destination as NSJSObject; int count = 0; if (sourceObject == null || destinationObject == null) { return(count); } foreach (string key in sourceObject.GetAllKeys()) { if (string.IsNullOrEmpty(key)) { continue; } count++; NSJSValue value = sourceObject.Get(key); destinationObject.Set(key, value); } return(count); }
public static NSJSObject New(NSJSVirtualMachine machine, DATATableGateway gateway) { if (machine == null || gateway == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("Select", g_SelectProc); o.Set("Close", g_CloseProc); o.Set("Dispose", g_CloseProc); o.Set("ExecuteNonQuery", g_ExecuteNonQueryProc); o.Set("DeriveParameters", g_DeriveParametersProc); o.Set("BeginTransaction", g_BeginTransactionProc); NSJSKeyValueCollection.Set(o, gateway); 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); }
private static NSJSObject New(NSJSVirtualMachine machine, SOCKET socket) { if (machine == null || socket == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("MSS", SocketExtension.MSS); o.Set("PPP", SocketExtension.PPP); o.Set("MTU", SocketExtension.MTU); o.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, socket.LocalEndPoint)); o.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, socket.RemoteEndPoint)); o.Set("Send", m_SendProc); o.Set("Bind", m_BindProc); o.Set("Handle", socket.Handle.ToInt32()); o.Set("Close", m_CloseProc); o.Set("Dispose", m_CloseProc); o.Set("Connect", m_ConnectProc); o.Set("Receive", m_ReceiveProc); o.Set("Accept", m_AcceptProc); o.Set("Connected", m_ConnectedProc); o.Set("ConnectAsync", m_ConnectAsyncProc); o.Set("AcceptAsync", m_AcceptAsyncProc); o.Set("SendAsync", m_SendAsyncProc); o.Set("ReceiveAsync", m_ReceiveAsyncProc); o.Set("SendTo", m_SendToProc); o.Set("SendToAsync", m_SendToAsyncProc); o.Set("ReceiveFrom", m_ReceiveFromProc); o.Set("ReceiveFromAsync", m_ReceiveFromAsyncProc); o.CrossThreading = true; NSJSKeyValueCollection.Set(o, new SocketContext { This = o, Socket = socket, }); return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, BaseStream stream) { if (machine == null || stream == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("CanWrite", stream.CanWrite); o.Set("CanSeek", stream.CanSeek); o.Set("CanRead", stream.CanRead); o.DefineProperty("Length", m_LengthProc, (NSJSFunctionCallback)null); o.DefineProperty("Position", m_PositionProc, m_PositionProc); o.Set("Seek", m_SeekProc); o.Set("CopyTo", m_CopyToProc); o.Set("Read", m_ReadProc); o.Set("Write", m_WriteProc); o.Set("Flush", m_FlushProc); o.Set("ReadBytes", m_ReadBytesProc); o.Set("Close", m_DisposeProc); o.Set("Dispose", m_DisposeProc); NSJSKeyValueCollection.Set(o, stream); return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, WebSocket websocket) { if (machine == null || websocket == null) { return(null); } object usertoken = websocket.UserToken; if (usertoken != null) { return(usertoken as NSJSObject); } NSJSObject objective = NSJSObject.New(machine); objective.Set("Open", m_OpenProc); objective.Set("Close", m_CloseProc); objective.Set("Dispose", m_CloseProc); objective.Set("Send", m_SendProc); objective.Set("Path", websocket.Path); objective.Set("Ttl", websocket.Ttl); objective.Set("Handle", websocket.Handle.ToInt32()); objective.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, websocket.LocalEndPoint)); objective.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, websocket.RemoteEndPoint)); objective.Set("OnMessage", NSJSValue.Null(machine)); objective.Set("OnClose", NSJSValue.Null(machine)); objective.Set("OnError", NSJSValue.Null(machine)); objective.Set("OnOpen", NSJSValue.Null(machine)); websocket.OnMessage += m_OnMessageProc; websocket.OnOpen += m_OnOpenProc; websocket.OnError += m_OnErrorProc; websocket.OnClose += m_OnCloseProc; websocket.UserToken = objective; objective.CrossThreading = true; objective.DefineProperty("NoDelay", m_NoDelayProc, m_NoDelayProc); objective.DefineProperty("Available", m_AvailableProc, (NSJSFunctionCallback)null); NSJSKeyValueCollection.Set(objective, websocket); return(objective); }
protected internal static NSJSValue ToObject(NSJSVirtualMachine machine, object obj) { if (machine == null) { return(null); } if (obj == null) { return(NSJSValue.Null(machine)); } Type owner = obj.GetType(); NSJSObject objective = NSJSObject.New(machine); foreach (MemberInfo mi in InternalCheckKeyMembers(owner).Values) { PropertyInfo pi = mi as PropertyInfo; FieldInfo fi = mi as FieldInfo; object value = null; Type clazz = null; string key = mi.Name; if (pi != null) { clazz = pi.PropertyType; value = pi.GetValue(obj, null); } else { clazz = fi.FieldType; value = fi.GetValue(obj); } NSJSValue result = null; do { if (value == null) { break; } Type element = TypeTool.GetArrayElement(clazz); if (element == null && value is IList) { result = ArrayAuxiliary.ToArray(machine, element, (IList)value); } else if (TypeTool.IsBasicType(clazz) && !TypeTool.IsIPAddress(clazz)) { result = value.As(machine); } else { result = ToObject(machine, value); } } while (false); if (result == null) { result = NSJSValue.Null(machine); } objective.Set(key, result); } NetToObjectCallables callables = InternalCheckNetToObjectCallables(owner); if (callables != null) { if (callables.funcs != null) { foreach (MethodInfo m in callables.funcs) { objective.Set(m.Name, NSJSPinnedCollection.Pinned(Complier(m))); } } if (callables.props != null) { foreach (PropertyInfo p in callables.props) { MethodInfo gm = p.GetGetMethod(); NSJSFunctionCallback get = null; NSJSFunctionCallback set = null; if (gm != null) { get = NSJSPinnedCollection.Pinned(Complier(gm)); } MethodInfo sm = p.GetSetMethod(); if (sm != null) { set = NSJSPinnedCollection.Pinned(Complier(sm)); } if (set != null || get != null) { objective.DefineProperty(p.Name, get, set); } } } objective.Set("Dispose", FDEFAULTDISPOSE); if (!objective.IsDefined("Close")) { objective.Set("Close", FDEFAULTDISPOSE); } NSJSKeyValueCollection.Set(objective, obj); } return(objective); }
public static NSJSObject New(NSJSVirtualMachine machine, NSJSObject context, HTTPResponse response) { if (machine == null || context == null || response == null) { return(null); } NSJSObject objective = NSJSObject.New(machine); objective.Set("CurrentContext", context); objective.DefineProperty("ContentEncoding", g_ContentEncodingProc, g_ContentEncodingProc); objective.DefineProperty("ContentType", g_ContentTypeProc, g_ContentTypeProc); objective.DefineProperty("StatusDescription", g_StatusDescriptionProc, g_StatusDescriptionProc); objective.DefineProperty("StatusCode", g_StatusCodeProc, g_StatusCodeProc); objective.DefineProperty("KeepAlive", g_KeepAliveProc, g_KeepAliveProc); objective.DefineProperty("ProtocolVersion", g_ProtocolVersionProc, g_ProtocolVersionProc); objective.DefineProperty("RedirectLocation", g_RedirectLocationProc, g_RedirectLocationProc); objective.DefineProperty("SendChunked", g_SendChunkedProc, g_SendChunkedProc); objective.DefineProperty("Headers", g_HeadersProc, g_HeadersProc); objective.DefineProperty("Cookies", g_CookiesProc, g_CookiesProc); objective.Set("Redirect", g_RedirectProc); objective.Set("End", g_EndProc); objective.Set("Abort", g_AbortProc); objective.Set("SetCookie", g_SetCookieProc); objective.Set("AppendCookie", g_SetCookieProc); objective.Set("AddHeader", g_AddHeaderProc); objective.Set("AppendHeader", g_AddHeaderProc); objective.Set("Write", g_WriteProc); objective.Set("WriteFile", g_WriteFileProc); objective.Set("BinaryWrite", g_BinaryWriteProc); NSJSKeyValueCollection.Set(objective, response); return(objective); }