示例#1
0
        public override void Process(HttpRequest request, HttpResponse response, HttpApplication application)
        {
            object processor = null;

            if (routeMap.TryGetValue(request.Path, out processor))
            {
                if (processor is string)
                {
                    processor = new LoadedScript(processor.ToString());
                    routeMap[request.Path] = processor;
                }
                if (processor is NiL.JS.Core.BaseTypes.Function)
                {
                    (processor as NiL.JS.Core.BaseTypes.Function).Invoke(new NiL.JS.Core.BaseTypes.Array(new object[] { request, response, application }));
                    return;
                }
                else if (processor is LoadedScript)
                {
                    var sc = (processor as LoadedScript).Script;
                    sc.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                    sc.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                    sc.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                    sc.Invoke();
                    return;
                }
            }

            if (defaultScript == null)
            {
                try
                {
                    defaultScript = new LoadedScript(defaultPath);
                }
                catch
                {
                    response.BinaryWrite(System.Text.Encoding.Default.GetBytes(new Http.ErrorPage(Http.ResponseCode.SERVICE_UNAVAILABLE, "Service unavailable.").ToString()));
                    response.StatusCode = (int)Http.ResponseCode.SERVICE_UNAVAILABLE;
                }
            }
            lock (defaultScript)
            {
                var script = defaultScript.Script;
                script.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                script.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                script.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                script.Invoke();
            }
        }
示例#2
0
        private static JSObject loadTemplate(Context context, JSObject args)
        {
            string templateName = args.GetField("0").ToString();
            var    sect         = (WebConfigurationManager.GetSection("templates") as Html.TemplateElementCollection)[templateName];

            templateName = sect.Path ?? templateName;
            templateName = validatePath(templateName);
            string templateText = "";
            var    file         = new FileStream(templateName, FileMode.Open, FileAccess.Read);

            templateText = new StreamReader(file).ReadToEnd();
            file.Close();
            var template = NiL.WBE.Html.HtmlPage.Parse(templateText);

            return(TypeProxy.Proxy(template));
        }