Пример #1
0
        /// <summary>
        /// 根据指定的上下文执行hostjs
        /// </summary>
        /// <param name="js"></param>
        /// <param name="context"></param>
        /// <param name="outobjname"></param>
        /// <returns></returns>
        public object RunJs(string js, HostLogicContext context, string outobjname)
        {
            try
            {
                Dictionary <string, object> dic = new Dictionary <string, object>();
                foreach (var item in context.AllHostJsObject)
                {
                    dic.Add(item.Name, item);
                }

                context.CurrentJsEngine.Evaluate(js, dic.ToArray());
                var outobj = context.CurrentJsEngine.GetOutObject(outobjname);
                if (outobj == null)
                {
                    outobj = FrameDLRObject.CreateInstance();
                }
                if (outobj is Dictionary <string, object> )
                {
                    return(FrameDLRObject.CreateInstance(outobj, FrameDLRFlags.SensitiveCase));
                }
                else
                {
                    return(outobj);
                }
            }
            finally
            {
                context.CurrentJsEngine.Release();
            }
        }
Пример #2
0
 public HostLogicEngine(WebBaseLogic <WebParameter, GoData> logic)
 {
     _context                = new HostLogicContext();
     _context.RootPath       = GlobalCommon.HostCommon.RootPath;
     _context.RunTimeLibPath = GlobalCommon.HostCommon.RootPath + "/" + HostJsConstants.COMPILED_ROOT_PATH;
     _context.CommonLibPath  = GlobalCommon.HostCommon.RootPath;
     _logic = logic;
     InitContext(_context, logic);
 }
Пример #3
0
        /// <summary>
        /// 运行格式化js,将js封装成function运行,可以使用return语句,用于HostLogic使用
        /// </summary>
        /// <param name="js"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public object DebugRunFormatJs(string js, HostLogicContext context)
        {
            var formatjs = @"function ___r___(){
    " + js + @"
}; 
var _____out______ = ___r___();";

            return(DebugRunJs(formatjs, context, "_____out______"));
        }
Пример #4
0
 public static void InitContext(HostLogicContext context, WebBaseLogic <WebParameter, GoData> logic)
 {
     context.AddHostJsObject(new JsDocument(context.CurrentJsEngine, context.RootPath, context.CommonLibPath, context.RunTimeLibPath));
     context.AddHostJsObject(new ConsoleObject());
     context.AddHostJsObject(new ServerObject(logic));
     context.AddHostJsObject(new ClientObject(logic));
     context.AddHostJsObject(new SessionObject(logic));
     context.AddHostJsObject(new LoginInfoObject(logic));
     context.AddHostJsObject(new CookieObject(logic));
     context.AddHostJsObject(new ConfigObject(logic));
     context.AddHostJsObject(new DBObject(logic));
     context.AddHostJsObject(new InputObject(logic));
     context.AddHostJsObject(new LogicObject(logic));
     context.AddHostJsObject(new ComFuncObject());
     context.AddHostJsObject(new FrameCacheObject(logic));
     context.AddHostJsObject(new LockObject(logic));
 }
Пример #5
0
 public HostLogicEngine(HostLogicContext context, WebBaseLogic <WebParameter, GoData> logic)
 {
     _context = context;
     _logic   = logic;
     InitContext(_context, logic);
 }
Пример #6
0
 /// <summary>
 /// debug方式运行js,默认返回参数名称为out
 /// </summary>
 /// <param name="js"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public object DebugRunJs(string js, HostLogicContext context)
 {
     return(DebugRunJs(js, context, "out"));
 }