Example #1
0
        public String V8Build(String view, object modal)
        {
            String result = String.Empty;

            using (var engine = new V8ScriptEngine())
            {
                engine.Execute(Juicer);

                engine.Script.view = "hi , id: ${ID}";
                //	engine.Script.modal = modal;
                //var modal_script = "modal = " + JsonConvert.SerializeObject(modal);

                var modal_script = JsonConvert.SerializeObject(modal);

                //engine.Execute(modal_script);
                //string tpl = "${subTpl}";
                //result = engine.Invoke("juicer", engine.Script.view, engine.Script.modal);
                //	var result1 = engine.Invoke("juicer", engine.Script.view);
                result = engine.Invoke("juicer", engine.Script.view, modal_script);
                string tpl = "Hi, {@include subTpl, subData}, End.";

                string data = "{\"subTpl\":\"I\'m sub content, ${name}\",\"subData\":{\"name\": \"juicer\"}}";

                //engine.Execute(data);
                var result1 = engine.Invoke("juicer", tpl, data);
            }

            return(result.ToString());
        }
        /// <summary>
        /// 加载模块
        /// </summary>
        /// <param name="v8"></param>
        /// <param name="module"></param>
        internal static object LoadModule(this V8ScriptEngine v8, ModuleInfo module)
        {
            var ass = Assembly.LoadFile(Path.Combine(module.ExecutePath, module.Assembly));

            if (ass == null)
            {
                throw new Exception("the path is not found,'" + module.Assembly + "'.");
            }
            var type = ass.GetType(module.Type);

            if (type == null)
            {
                throw new Exception("the type is not found,'" + module.Type + "'.");
            }
            var refType = string.Format("_ref_module_type_{0}", type.Name);

            v8.AddHostType(refType, type);
            var funcName = string.Format("_init_module_func_{0}", module.Name);
            var script   = new StringBuilder("function ");

            script.Append(funcName + "() {\r\n");
            script.AppendFormat("var {0} = new {1}();\r\n", module.Name, refType);
            if (module.ProxyScript?.Length > 0)
            {
                script.Append(module.ProxyScript);
            }
            script.AppendFormat("\r\nreturn {0};", module.Name);
            script.Append("\r\n}");
            v8.Execute(script.ToString());
            return(v8.Invoke(funcName));
        }
Example #3
0
        public int Main()
        {
            try
            {
                var result = engine.Invoke("main");
                Debug.WriteLine(result);
                if (result is int retCode)
                {
                    return(retCode);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception exception)
            {
                SLogger <ScriptRT> .Warn(exception);

                return(-1);
            }
        }
Example #4
0
        public String V8Build(String view, object modal)
        {
            String result = String.Empty;

            using (var engine = new V8ScriptEngine())
            {
                engine.Execute(Juicer);

                engine.Script.view = view;

                var modal_script = "modal = " + JsonConvert.SerializeObject(modal);

                engine.Execute(modal_script);

                result = engine.Invoke("juicer", engine.Script.view, engine.Script.modal);
            }

            return(result.ToString());
        }
 public Task <object> InvokeAsync(string methodName, params object[] args)
 {
     return(Task.Run(async() =>
     {
         object result = null;
         try
         {
             result = engine.Invoke(methodName, args);
             return await result.ToTask();
         }
         catch (ArgumentException)
         {
             return await Task.FromResult(result);
         }
         catch (ScriptEngineException e)
         {
             throw new InvalidOperationException(e.Message, e);
         }
     }));
 }
Example #6
0
        public String V8Build(String view, object modal)
        {
            String result = String.Empty;

            using (var engine = new V8ScriptEngine())
            {
                engine.Execute(Juicer);

                engine.Script.view = view;

                var modal_script = "modal = " + JsonConvert.SerializeObject(modal);

                engine.Execute(modal_script);

                result = engine.Invoke("juicer", engine.Script.view, engine.Script.modal);
            }

            return result.ToString();
        }