Exemple #1
0
 protected void btnResult_Click(object sender, EventArgs e)
 {
     if (CustomFunctionService.Delete(p => p.FAccountId == CurrentUser.Id))
     {
         Alert.Show("已全部清空定义常用功能,请重新定义。", MessageBoxIcon.Information);
     }
 }
Exemple #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            bool isSucceed = false;

            try
            {
                foreach (var pnode in leftMenuTree.Nodes)
                {
                    foreach (var node in pnode.Nodes)
                    {
                        if (node.Checked)
                        {
                            int id = Convert.ToInt32(node.NodeID);

                            var customerFun = CustomFunctionService.Where(p => p.FMenuId == id).FirstOrDefault();

                            if (customerFun == null)
                            {
                                var fun = new base_custom_function
                                {
                                    FAccountId = CurrentUser.Id,
                                    FMenuId    = Convert.ToInt32(node.NodeID)
                                };

                                CustomFunctionService.AddEntity(fun);
                            }
                            ;
                        }
                    }
                }

                CustomFunctionService.SaveChanges();

                isSucceed = true;
            }
            catch (Exception)
            {
                isSucceed = false;
            }
            finally
            {
                if (isSucceed)
                {
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.Show("提交失败!", MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        /// 在接收到外部命令后,调用下一层进行解析配置文件,并且使它对该文件进行处理;
        ///
        ///  这个方法并不是再 Start 中调用的,而是再网页返回数据后调后调用的;TODO
        /// </summary>
        private void Start()
        {
            // 这里只是模拟接受到命令;

            if (dataString != null)
            {
                DataParsing.Parsing(DataType.Json, dataString, true);
            }

            // 向组件注册一些 ExternalFunctions类中的通用处理函数,这样做是为了扩展一些组件内部通用的功能;

            // 注意:组件默认是执行一次函数后,就销毁该函数,true为始终不销毁;

            CustomFunctionService.AddScriptDisposeFunction <ExternalFunctions, JsonData>(true);

            // 当获取数据后,回调该方法,该方法由客户端实现;

            ComStart();
        }
Exemple #4
0
        /// <summary>
        ///  保存场景中所有 ObjectAssetsBase 类型的 GameObject,并动态收集和注册该方法;
        /// </summary>
        public static bool Scene(string sceneName)
        {
            ScriptAssetsBase script = ScriptAssetsManager.Instance.GetScriptByName(sceneName);

            if (script == null)
            {
                return(false);
            }

            // 清空上一次可以销毁的函数,以释放其内存;

            CustomFunctionService.ClearNeedDestroyFunction();

            Type type = script.GetType();

            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                                 BindingFlags.Static | BindingFlags.DeclaredOnly;


            foreach (var methodInfo in type.GetMethods(flags))
            {
            }


            foreach (var methodInfo in type.GetMethods(flags))
            {
                // 方法的返回值类型不为 Void ,或者该方法是泛型方法,则跳过;

                if (methodInfo.Name == "SceneAwake" ||

                    methodInfo.IsGenericMethod || methodInfo.ContainsGenericParameters)
                {
                    continue;
                }

                // 根据参数类型,获取相应的方法;

                ParameterInfo[] parameters = methodInfo.GetParameters();

                if (methodInfo.ReturnParameter.ToString() == "Boolean" &&

                    parameters.Length == 1 && parameters[0].ParameterType == typeof(JsonData))
                {
                    CustomFunctionService.AddDisposeFunction((Func <JsonData, bool>)

                                                             Delegate.CreateDelegate(typeof(Func <JsonData, bool>), script, methodInfo));

                    continue;
                }

                if (methodInfo.ReturnParameter.ToString() != "Void")
                {
                    continue;
                }

                // 创建一个委托,里使用反射和委托的静态创建方法将 T 中符合要求的方法添加进函数库;

                switch (parameters.Length)
                {
                case 0:

                    CustomFunctionService.AddEventAction((Action)
                                                         Delegate.CreateDelegate(typeof(Action), script, methodInfo));

                    CustomFunctionService.AddDisposeFunction <JsonData>((Action)

                                                                        Delegate.CreateDelegate(typeof(Action), script, methodInfo));

                    break;

                case 1:

                    if (parameters[0].ParameterType != typeof(string))
                    {
                        break;
                    }

                    CustomFunctionService.AddEventAction((Action <string>)
                                                         Delegate.CreateDelegate(typeof(Action <string>), script, methodInfo));

                    break;
                }
            }

            // 调用客户端重写的函数,执行该脚本;

            script.SceneAwake();

            return(true);
        }