/// <summary>
        /// 反射调用方法
        /// </summary>
        /// <param name="cfi"></param>
        /// <param name="methodName"></param>
        private static void InvokeAssemblyMethod(Mission cfi, string methodName)
        {
            System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFile(cfi.DllLocation);

            lock (ass)
            {
                Type type = ass.GetType(cfi.ClassName);//必须使用名称空间+类名称
                System.Reflection.MethodInfo method = type.GetMethod(methodName);//方法的名称
                Object obj = ass.CreateInstance(cfi.ClassName);//必须使用名称空间+类名称
                string s = (string)method.Invoke(obj, null); //实例方法的调用
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mi"></param>         
 private static void ThreadDoLaunch(Mission mi)
 {
     while (_ServiceRunningStatus)
     {
         try
         {
             //mi.MissionOwnerStatus = Thread.CurrentThread.ThreadState;
             InvokeAssemblyMethod(mi, mi.LaunchMethod);
             _logger.Info(string.Format("Strong Dispatch服务:调用任务{0}的方法{1}.{2}成功!下次任务在{3}毫秒后再次启动!", mi.MissionName,
                         mi.ClassName, mi.LaunchMethod, mi.LaunchInterval));
             Thread.Sleep(mi.LaunchInterval);
         }
         catch (Exception err)
         {
             mi.MissionStatus = eMissionStatus.ErrorHalt;
             //mi.MissionOwnerStatus = Thread.CurrentThread.ThreadState;
             _logger.Error(err);
             _logger.Info(string.Format("Strong Dispatch服务:调用任务{0}的方法{1}.{2}失败!下次任务在{3}毫秒后再次启动!", mi.MissionName,
                     mi.ClassName, mi.LaunchMethod, mi.ErrorTryInterval));
             Thread.Sleep(mi.ErrorTryInterval);
         }
     }
 }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strConfFileName"></param>
        /// <returns></returns>
        public static List<Mission> LoadConf(string strConfFileName)
        {
            if (_list != null)
            {
                return _list;
            }
            _list = new List<Mission>();
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(strConfFileName);
                XmlNode rt = XMLHelper.FindXmlNode(doc, "conf", true);
                string runningStatus = XMLHelper.GetXmlNodeAttributes(rt, "runingstatus", true);
                XmlNode runningNode = XMLHelper.FindXmlNode(rt, runningStatus, true);

                //守护线程 --守护线程功能取消
                //守护线程错误重启时间间隔
                //int errormonitorinterval = XMLHelper.GetXmlNodeAttributesToInt(runningNode, "errormonitorinterval", true);
                //Mission daemon = new Mission(eTaskType.Daemon, "Daemon", "", "", "", "", errormonitorinterval * 1000, 0, eMissionStatus.Running);
                //_list.Add(daemon);

                XmlNodeList missionNode = runningNode.ChildNodes;
                foreach (XmlNode node in missionNode)
                {
                    string missionName = XMLHelper.GetXmlNodeAttributes(node, "name", true);
                    //判定是否有重名应用,重名应用选取
                    if (!_list.Exists((c) => { return c.MissionName == missionName; }))
                    {
                        Mission mi = new Mission(node, missionName);
                        _list.Add(mi);
                    }
                }
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
            return _list;
        }