Beispiel #1
0
        /// <summary>
        /// 在ToolsManager中新建一个参数
        /// </summary>
        /// <param name="packName">包名</param>
        /// <param name="name">注册函数名字</param>
        public void registerFunc(string packName, string name)
        {
            //ToolsManager.
            ITools it  = dllList[packName];
            var    fun = it.js.AddFunction(name);

            fun.Execute += (func, args) =>
            {
                var stringArgument = args.Arguments.FirstOrDefault(p => p.IsString);
                if (stringArgument != null)
                {
                    MethodInfo m_func = it.type.GetMethod("func_" + name, new Type[] { typeof(string) });
                    string     result = (string)m_func.Invoke(it.obj, new object[] { stringArgument.StringValue });
                    args.SetReturnValue(CfrV8Value.CreateString(result));
                }
            };
        }
Beispiel #2
0
        public bool runTools(string name)
        {
            if (dllList.ContainsKey(name))
            {
                return(false);
            }
            //挂载dll
            Assembly asm = Assembly.LoadFrom("tools\\" + name + "\\" + "ui.dll");
            //读取类型
            Type t = asm.GetType(name + ".Main");
            //创建对象信息
            object o = Activator.CreateInstance(t);

            Bootstrap.RegisterAssemblyResources(asm, null, name + ".greycloud.com");
            ITools it = new ITools(name, asm, t, ToolsManager.AddObject(name), o);

            dllList.Add(name, it);
            //配置
            Type del1 = t.GetNestedType("d_registerFunc");

            if (del1 != null)
            {
                try {
                    Delegate d = Delegate.CreateDelegate(del1, this.GetType().GetMethod("registerFunc"));
                    t.GetField("registerFunc").SetValue(o, d);
                }
                catch (ArgumentException e)
                {
                    Debug.WriteLine(e.ParamName);
                }
            }
            //执行Load
            MethodInfo m_Load = t.GetMethod("Load", new Type[] { typeof(int) });
            bool       result = (bool)m_Load.Invoke(o, new object[] { 0 });

            return(result);
        }