private static void SetCookie(IntPtr info) { ObjectAuxiliary.Call(info, (HTTPResponse response, NSJSFunctionCallbackInfo arguments, NSJSValue solt0) => { bool success = false; Cookie cookie = ObjectAuxiliary.ToCookie(solt0); if (cookie != null) { success = response.SetCookie(cookie); } arguments.SetReturnValue(success); }); }
private static void Start(IntPtr info) { ObjectAuxiliary.Call <WebSocketListener>(info, (server, arguments) => { try { server.Start(); } catch (Exception exception) { Throwable.Exception(arguments.VirtualMachine, exception); } }); }
private static void Open(IntPtr info) { ObjectAuxiliary.Call <WebSocket>(info, (websocket, arguments) => { try { websocket.Open(); } catch (Exception exception) { Throwable.Exception(arguments.VirtualMachine, exception); } }); }
private static void InternalSend(IntPtr info, bool synchronization) { ObjectAuxiliary.Call <MailClient>(info, (smtp, arguments) => { do { NSJSVirtualMachine machine = arguments.VirtualMachine; if (arguments.Length <= 0) { Throwable.ArgumentException(machine); break; } MailMessage message = null; try { message = ObjectAuxiliary.ToMailMessage(arguments[0]); } catch (Exception exception) { Throwable.Exception(machine, exception); break; } if (message == null) { Throwable.ArgumentNullException(machine); break; } if (synchronization) { arguments.SetReturnValue(smtp.Send(message)); } else { NSJSFunction function = arguments.Length > 1 ? arguments[1] as NSJSFunction : null; Action <Exception> callbackt = null; if (function != null) { callbackt = (exception) => machine.Join((sender, state) => function.Call(new[] { Throwable.FormatMessage(exception) })); function.CrossThreading = true; } arguments.SetReturnValue(smtp.SendAsync(message, callbackt)); } } while (false); }); }
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 void RollbackOrCommit(IntPtr info, bool commiting) { ObjectAuxiliary.Call <IDbTransaction>(info, (transaction, arguments) => { try { if (commiting) { transaction.Commit(); } else { transaction.Rollback(); } } catch (Exception exception) { Throwable.Exception(arguments.VirtualMachine, exception); } }); }
private static void Send(IntPtr info) { ObjectAuxiliary.Call <WebSocket>(info, (websocket, arguments) => { bool success = false; byte[] buffer = arguments.Length > 0 ? (arguments[0] as NSJSUInt8Array)?.Buffer : null; if (buffer != null) { success = websocket.Send(buffer); } else { string message = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null; if (message != null) { success = websocket.Send(message); } } arguments.SetReturnValue(success); }); }
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, 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 void Headers(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response, arguments) => arguments.SetReturnValue(ObjectAuxiliary. ToObject(arguments.VirtualMachine, response.Headers)), (response, arguments, objecttive) => ObjectAuxiliary.Fill(objecttive, response.Headers)); }
private static void Available(IntPtr info) { ObjectAuxiliary.Call <WebSocket>(info, (websocket, arguments) => arguments.SetReturnValue(websocket.Available)); }
private static void NoDelay(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <WebSocket>(info, (websocket) => websocket.NoDelay, (websocket, value) => websocket.NoDelay = value); }
private static void InternalExecute(NSJSFunctionCallbackInfo arguments, bool nonquery) { InternalExecute(arguments, (gateway, adapter, text) => { DataTable dataTable = null; IDbCommand command = null; try { IDbTransaction transaction = null; NSJSArray parameters = null; NSJSInt32 cmdtype = null; for (int solt = 1, count = arguments.Length; solt < count && (transaction == null || cmdtype == null || parameters == null); solt++) { NSJSValue current = arguments[solt]; if (transaction == null) { transaction = DatabaseTransaction.GetTransaction(current as NSJSObject); } if (cmdtype == null) { cmdtype = current as NSJSInt32; } if (parameters == null) { parameters = current as NSJSArray; } } command = ObjectAuxiliary.ToDbCommand(adapter, text, parameters); int commandType = ValueAuxiliary.ToInt32(cmdtype); switch (commandType) { case 1: command.CommandType = CommandType.StoredProcedure; break; case 2: command.CommandType = CommandType.TableDirect; break; default: command.CommandType = CommandType.Text; break; } command.Transaction = transaction; if (nonquery) { arguments.SetReturnValue(gateway.ExecuteNonQuery(command)); } else { dataTable = gateway.Select(command); arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, dataTable)); } } catch (Exception e) { Throwable.Exception(arguments.VirtualMachine, e); } if (dataTable != null) { dataTable.Dispose(); } if (command != null) { command.Dispose(); } }); }
private static void SendChunked(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response) => response.SendChunked, (response, value) => response.SendChunked = value); }
private static void RedirectLocation(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response) => response.RedirectLocation, (response, value) => response.RedirectLocation = value); }
private static void StatusDescription(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response) => response.StatusDescription, (response, value) => response.StatusDescription = value); }
private static void ProtocolVersion(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response) => response.ProtocolVersion?.ToString(), (response, value) => response.ProtocolVersion?.ToString()); }
public static bool Close(NSJSObject response) { return(ObjectAuxiliary.RemoveInKeyValueCollection(response)); }
private static void ConnectAsync(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); bool success = false; do { if (arguments.Length <= 0) { Throwable.ObjectDisposedException(arguments.VirtualMachine); break; } SocketContext context = GetSocketContext(arguments.This); if (context == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); break; } SOCKET socket = context.Socket; if (socket == null || SocketExtension.CleanedUp(socket)) { Throwable.ObjectDisposedException(arguments.VirtualMachine); break; } EndPoint remoteEP = ObjectAuxiliary.ToEndPoint(arguments[0]); int cbsolt = 1; if (remoteEP == null) { IPAddress address = ObjectAuxiliary.ToAddress(arguments[0]); if (address == null) { break; } int port = arguments.Length > 1 ? ((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault() : 0; remoteEP = new IPEndPoint(address, port); cbsolt++; } if (remoteEP == null) { break; } NSJSFunction callback = arguments.Length > cbsolt ? arguments[cbsolt] as NSJSFunction : null; try { SocketAsyncEventArgs e = context.ConnectedAsync; if (e != null) { break; } else { e = new SocketAsyncEventArgs(); e.Completed += ProcessConnected; e.UserToken = context; context.ConnectedAsync = e; } e.RemoteEndPoint = remoteEP; if (callback != null) { callback.CrossThreading = true; context.ConnectedAsyncCallback = callback; } if (!socket.ConnectAsync(e)) { ProcessConnected(socket, e); } success = true; } catch (Exception e) { Throwable.Exception(arguments.VirtualMachine, e); } } while (false); arguments.SetReturnValue(success); }
private static void StatusCode(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response) => response.StatusCode, (response, value) => response.StatusCode = value); }
private static void Cookies(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response, arguments) => arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, response.Cookies)), (response, arguments, value) => ArrayAuxiliary.Fill(value, response.Cookies)); }
private static void ContentType(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response) => response.ContentType, (response, value) => response.ContentType = value); }
private static void Redirect(IntPtr info) { ObjectAuxiliary.Call <HTTPResponse>(info, (response, arguments, value) => response.Redirect(value)); }
private static void Close(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); arguments.SetReturnValue(ObjectAuxiliary.RemoveInKeyValueCollection(arguments.This)); }
private static void Asynchronous(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPContext>(info, (context) => context.Asynchronous, (context, value) => context.Asynchronous = value); }
private static void KeepAlive(IntPtr info) { ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response) => response.KeepAlive, (response, value) => response.KeepAlive = value); }
private static void Stop(IntPtr info) { ObjectAuxiliary.Call <WebSocketListener>(info, (server, arguments) => server.Stop()); }
private static void GetBindPort(IntPtr info) { ObjectAuxiliary.Call <WebSocketListener>(info, (server, arguments) => arguments.SetReturnValue(server.GetBindPort())); }
public static void Close(NSJSFunctionCallbackInfo arguments) { arguments.SetReturnValue(ObjectAuxiliary.RemoveInKeyValueCollection(arguments.This)); }
private static void Write(IntPtr info) { ObjectAuxiliary.Call <HTTPResponse>(info, (response, arguments, value) => arguments.SetReturnValue(response.Write(value))); }