public static NSJSObject New(NSJSVirtualMachine machine, ENCODING encoding) { lock (g_Locker) { if (machine == null || encoding == null) { return(null); } IDictionary <IntPtr, NSJSObject> dVirtualTables; if (!g_EncodingInstanceTable.TryGetValue(encoding.CodePage, out dVirtualTables)) { dVirtualTables = new Dictionary <IntPtr, NSJSObject>(); g_EncodingInstanceTable.Add(encoding.CodePage, dVirtualTables); } NSJSObject o; if (dVirtualTables.TryGetValue(machine.Isolate, out o)) { return(o); } if (!g_UninitializedEncoding) { g_UninitializedEncoding = true; g_GetBytesProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetBytes); g_GetStringProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetString); } o = NSJSObject.New(machine); o.CrossThreading = true; o.Set("GetBytes", g_GetBytesProc); o.Set("GetString", g_GetStringProc); dVirtualTables.Add(machine.Isolate, o); NSJSKeyValueCollection.Set(o, encoding); 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); }
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 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 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); }
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); }
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, 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 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, 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, 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); }
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); }
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); }