Exemple #1
0
        public int CallFunction(FunctionEnums.Functions ApiName, params object[] args)
        {
            JObject json = new JObject
            {
                new JProperty("ApiName", JsonConvert.SerializeObject(ApiName)),
                new JProperty("Args", JsonConvert.SerializeObject(args))
            };

            if ((ApiName != FunctionEnums.Functions.Disable && ApiName != FunctionEnums.Functions.Exit &&
                 ApiName != FunctionEnums.Functions.Enable && ApiName != FunctionEnums.Functions.StartUp) &&
                Loading)
            {
                LogHelper.WriteLog(LogLevel.Warning, "OPQBot框架", "插件逻辑处理", "插件模块处理中...", "x 不处理");
                return(-1);
            }
            //遍历插件列表,遇到标记消息阻断则跳出
            foreach (var item in Plugins)
            {
                Dll dll = item.dll;
                //先看此插件是否已禁用
                if (item.Enable is false)
                {
                    continue;
                }
                if (Save.TestPluginsList.Any(x => x == item.appinfo.Name))
                {
                    Debug.WriteLine($"{item.appinfo.Name} 插件测试中,忽略消息投递");
                    continue;
                }
                try
                {
                    int result = dll.CallFunction(ApiName, args);
                    //调用函数, 返回 1 表示消息阻塞, 跳出后续
                    if (result == 1)
                    {
                        return(Plugins.IndexOf(item) + 1);
                    }
                }
                catch (Exception e)
                {
                    LogHelper.WriteLog(LogLevel.Error, "函数执行异常", $"插件 {item.appinfo.Name} {ApiName} 函数发生错误,错误信息:{e.Message} {e.StackTrace}");
                    Thread thread = new Thread(() =>
                    {
                        var b = ErrorHelper.ShowErrorDialog($"错误模块:{item.appinfo.Name}\n{ApiName} 函数发生错误,错误信息:\n{e.Message} {e.StackTrace}");
                        switch (b)
                        {
                        case ErrorHelper.TaskDialogResult.ReloadApp:
                            ReLoad();
                            break;

                        case ErrorHelper.TaskDialogResult.Exit:
                            NotifyIconHelper.HideNotifyIcon();
                            Environment.Exit(0);
                            break;
                        }
                        //报错误但仍继续执行
                    });
                    thread.Start();
                }
            }
            return(0);
        }