Exemplo n.º 1
0
        public string RunTemplate(string template, string data, ref XHTMLMerge.SVCache svCache)
        {
            var application = new JSApplication();
            var session     = new JSSession();

            return(RunTemplate(template, data, ref application, ref session, ref svCache));
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context, JSApplication application, JSSession session)
        {
            XHTMLMerge.SVCache svCache = null;

            var path = GetPath(context.Request);

            var arguments = Core.Tool.Construct("Object", application.Engine.Scope);

            arguments.Set("request", CreateRequest(context, path, application.Engine.Scope));

            var response = Core.Tool.Construct("Object", application.Engine.Scope);

            response.Set("contentType", new Core.Javascript.String("text/html"));
            response.Set("statusCode", new Core.Javascript.Number(200));
            arguments.Set("response", response);

            var responseString = RunTemplate(application.Settings.Entry, arguments, ref application, ref session, ref svCache);

            try {
                context.Response.ContentType = response.Get <Core.Javascript.String>("contentType").Value;
                context.Response.StatusCode  = (int)response.Get <Core.Javascript.Number>("statusCode").Value;
            }catch (Exception) {
                // TODO: log error
            }

            context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            context.Response.AppendHeader("Access-Control-Allow-Headers", "X-Requested-With");

            var buffer = Encoding.UTF8.GetBytes(responseString);
            var output = context.Response.OutputStream;

            output.Write(buffer, 0, buffer.Length);
            output.Close();
        }
Exemplo n.º 3
0
        public static Constant include(Constant _this, Constant[] arguments, Scope scope)
        {
            var name = Core.Tool.GetArgument <Core.Javascript.String>(arguments, 0, "XDoc.include");

            var context = HttpContext.Current;

            XHTMLMerge.AppCache appCache = null;
            XHTMLMerge.SVCache  svCache  = null;

            if (context != null && context.Application != null)
            {
                appCache = (XHTMLMerge.AppCache)context.Application["AppCache"];
            }
            if (appCache == null)
            {
                appCache = new XHTMLMerge.AppCache();
            }

            if (context != null && context.Session != null)
            {
                svCache = (XHTMLMerge.SVCache)context.Session["SVCache"];
            }
            if (svCache == null)
            {
                svCache = new XHTMLMerge.SVCache();
            }

            var parameters = new Hashtable();

            if (arguments.Length > 1)
            {
                var param = (Core.Javascript.Object)arguments[1];
                foreach (var key in param.GetKeys())
                {
                    parameters.Add(key, param.Get(key).ToString());
                }
            }

            var application = Tool.GetFromScope <JSApplication>(scope, "__application__");

            if (application == null)
            {
                throw new InternalError("No application");
            }
            var result = application.XDocService.RunTemplate(context, name.Value, parameters, ref appCache, ref svCache);

            if (context != null && context.Application != null)
            {
                context.Application["AppCache"] = appCache;
            }
            if (context != null && context.Session != null)
            {
                context.Session["SVCache"] = svCache;
            }

            return(new Core.Javascript.String(result));
        }
Exemplo n.º 4
0
        public string RunTemplate(string template, Core.Javascript.Object arguments, ref JSApplication application)
        {
            if (application == null)
            {
                application = new JSApplication();
            }

            var session = new JSSession();
            var svCache = new XHTMLMerge.SVCache();

            return(RunTemplate(template, arguments, ref application, ref session, ref svCache));
        }
Exemplo n.º 5
0
        public static XDocInfo GetXDocInfo()
        {
            var context = HttpContext.Current;

            XHTMLMerge.AppCache appCache = null;
            XHTMLMerge.SVCache  svCache  = null;

            if (context != null)
            {
                if (context.Application != null)
                {
                    appCache = (XHTMLMerge.AppCache)context.Application["AppCache"];
                }
                if (context.Session != null)
                {
                    svCache = (XHTMLMerge.SVCache)context.Session["SVCache"];
                }
            }
            else
            {
                var application = State.Application;
                var session     = State.Session;

                if (application.Get("AppCache") is object af)
                {
                    appCache = (XHTMLMerge.AppCache)af;
                }
                if (session.Get("SVCache") is object sf)
                {
                    svCache = (XHTMLMerge.SVCache)sf;
                }
            }

            if (appCache == null)
            {
                appCache = new XHTMLMerge.AppCache();
            }
            if (svCache == null)
            {
                svCache = new XHTMLMerge.SVCache();
            }

            return(new XDocInfo()
            {
                AppCache = appCache, SVCache = svCache
            });
        }
Exemplo n.º 6
0
        public string RunTemplate(string template, string data, ref JSApplication application, ref JSSession session, ref XHTMLMerge.SVCache svCache)
        {
            try {
                dynamic arguments = new NetJSObject();
                return(RunTemplate(template, arguments, ref application, ref session, ref svCache));
            } catch { }

            return("invalid arguments (must be valid json)");
        }
Exemplo n.º 7
0
        public string RunTemplate(string template, string data, ref JSApplication application, ref JSSession session)
        {
            var svCache = new XHTMLMerge.SVCache();

            return(RunTemplate(template, data, ref application, ref session, ref svCache));
        }
Exemplo n.º 8
0
        // Every template is executed via this function
        public string RunTemplate(string template, Dictionary <string, object> arguments, ref JSApplication application, ref JSSession session, ref XHTMLMerge.SVCache svCache)
        {
            try {
                if (arguments == null)
                {
                    arguments = new Dictionary <string, object>();
                }

                NetJS.API.XDoc.SetXDocInfo(new API.XDoc.XDocInfo()
                {
                    AppCache = null, SVCache = svCache
                });

                // TODO: better way to forward session
                dynamic args = new NetJSObject();
                foreach (var pair in arguments)
                {
                    args[pair.Key] = pair.Value;
                }

                var result = API.Functions.include(template, args);

                return(result.ToString());
            } catch (ScriptEngineException se) {
                return(se.ErrorDetails);
            } catch (Error e) {
                return(e.ToString());
            } catch (Exception e) {
                return("System error - " + e.ToString());
            }
        }
Exemplo n.º 9
0
        public string RunTemplate(string template, string data, ref JSApplication application, ref JSSession session, ref XHTMLMerge.SVCache svCache)
        {
            var arguments = JSON.parse(null, new[] { new Core.Javascript.String(data) }, application.Engine.Scope);

            if (arguments is Core.Javascript.Object a)
            {
                return(RunTemplate(template, a, ref application, ref session, ref svCache));
            }
            return("invalid arguments (must be valid json)");
        }
Exemplo n.º 10
0
        // Every template is executed via this function
        public string RunTemplate(string template, Core.Javascript.Object arguments, ref JSApplication application, ref JSSession session, ref XHTMLMerge.SVCache svCache)
        {
            try {
                if (arguments == null)
                {
                    arguments = Core.Tool.Construct("Object", application.Engine.Scope);
                }

                var scope = new Scope(application.Engine.Scope, null, ScopeType.Session);
                scope.SetVariable("__application__", new Foreign(application));
                scope.SetVariable("__session__", new Foreign(session));
                scope.SetVariable("__svCache__", new Foreign(svCache));

                // TODO: better way to forward session
                var result = External.Functions.include(
                    Static.Undefined,
                    new Constant[] { new Core.Javascript.String(template), arguments },
                    scope
                    );

                if (result is Core.Javascript.String s)
                {
                    return(s.Value);
                }
            } catch (Error e) {
                return(e.Message + "\n" + string.Join("\n", e.StackTrace.Select(loc => Debug.GetFileName(loc.FileId) + " (" + loc.LineNr + ")")));
            } catch (Exception e) {
                return("System error - " + e.ToString());
            }

            return("");
        }