Exemple #1
0
        /// <summary>
        /// 加载默认插件服务
        /// </summary>
        /// <param name="pluginDLLDir">插件服务绝对路径文件夹</param>
        public List <JobsTrigger> DefaultRunningQZServer(string pluginDLLDir, out string error)
        {
            error = "";
            try
            {
                var assemblies = new DirectoryInfo(pluginDLLDir)
                                 .GetFiles("*.dll")
                                 .Select(r => Assembly.LoadFrom(r.FullName)).ToArray();
                foreach (var ass in assemblies)
                {
                    #region 具体加载配个PluginDLL

                    Type[] allType = ass.GetTypes();  //获取程序集中的所有类型列表
                    Dictionary <string, Type> dic = new Dictionary <string, Type>();
                    foreach (Type temp in allType)
                    {
                        if (temp.GetInterface("ICronConfig") != null)
                        {
                            dic.Add("CronConfig", temp);
                        }
                        if (temp.GetInterface("IJobsConfig") != null)
                        {
                            dic.Add("JobsConfig", temp);
                        }

                        if (temp.GetInterface("IJobLibray") != null)
                        {
                            dic.Add("JobLibray", temp);
                        }
                    }
                    var        jobsConfig = Activator.CreateInstance(dic["JobsConfig"]);
                    IJobLibray jobLibrary = (IJobLibray)Activator.CreateInstance(dic["JobLibray"]);
                    Type       t          = jobsConfig.GetType();

                    string tempError = "";
                    foreach (var c in jobLibrary.GetJobList())
                    {
                        AddQuartzServer(c.JobDetail, c.Trigger, out tempError);
                        error += tempError;
                        UpdateJobsTriggerList(c.JobDetail.Key);
                    }

                    #endregion
                }

                return(jobTriggerServerList);
            }
            catch (Exception ex)
            {
                scheduler.Shutdown();
                jobTriggerServerList.Clear();
                error += ex.ToString();
            }
            return(new List <JobsTrigger>());
        }
Exemple #2
0
        /// <summary>
        /// 加载指定插件dll 并自定运行
        /// </summary>
        /// <param name="path">指定插件dll绝对地址</param>
        /// <param name="error">错误信息</param>
        /// <returns>返回加载结果</returns>
        public bool AddQZServerDLL(string path, out string error)
        {
            error = "";
            bool result = true;

            try
            {
                #region 具体加载配个PluginDLL
                Assembly ass = Assembly.LoadFile(path);

                Type[] allType = ass.GetTypes();  //获取程序集中的所有类型列表
                Dictionary <string, Type> dic = new Dictionary <string, Type>();
                foreach (Type temp in allType)
                {
                    if (temp.GetInterface("ICronConfig") != null)
                    {
                        dic.Add("CronConfig", temp);
                    }
                    if (temp.GetInterface("IJobsConfig") != null)
                    {
                        dic.Add("JobsConfig", temp);
                    }

                    if (temp.GetInterface("IJobLibray") != null)
                    {
                        dic.Add("JobLibray", temp);
                    }
                }
                var        jobsConfig = Activator.CreateInstance(dic["JobsConfig"]);
                IJobLibray jobLibrary = (IJobLibray)Activator.CreateInstance(dic["JobLibray"]);
                Type       t          = jobsConfig.GetType();

                string tempError = "";
                foreach (var c in jobLibrary.GetJobList())
                {
                    AddQuartzServer(c.JobDetail, c.Trigger, out tempError);
                    error += tempError;
                    UpdateJobsTriggerList(c.JobDetail.Key);
                }

                #endregion
            }
            catch (Exception ex)
            {
                result = false;
                error += ex.ToString();
            }

            return(result);
        }