Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
            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);
            }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }