Ejemplo n.º 1
0
 public TimeDoTask(int timeInterval, TimeNowDoEventHandler func)
 {
     this.tasktype      = enum_taskType.interval;
     this._timeInterval = timeInterval;
     _timer             = new Timer(_timeInterval)
     {
         AutoReset = true
     };
     _timer.Elapsed += pTimer_Elapsed;
     _dodunc         = func;
 }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="timedo">需求做的时间,格式HHmmss</param>
 /// <param name="func"></param>
 /// <param name="tasktype"></param>
 public TimeDoTask(string timedo, TimeNowDoEventHandler func, enum_taskType tasktype)
 {
     this.tasktype      = tasktype;
     _dodunc            = func;
     this._timeInterval = 10;
     _timer             = new Timer(_timeInterval)
     {
         AutoReset = true
     };
     _timer.Elapsed += pTimer_Elapsed;
     _timeEvery      = timedo;
     setNextDoTaskTime();
 }
Ejemplo n.º 3
0
        public virtual IList <TimeDoTask> initTasklist(string taskConfigFile)
        {
            if (string.IsNullOrEmpty(taskConfigFile))
            {
                return(null);
            }
            var    rootdir     = System.AppDomain.CurrentDomain.BaseDirectory;
            string xmlfilename = System.IO.Path.Combine(rootdir, taskConfigFile);

            if (!File.Exists(xmlfilename))
            {
                return(null);
            }

            List <TimeDoTask> alltask = new List <TimeDoTask>();

            FrmLib.Log.commLoger.runLoger.Debug(string.Format("now createTaskList"));

            Type[] nodeTaskHandles = FrmLib.Extend.tools_static.GetTypesFromAssemblysByType(typeof(ICronTask));


            XmlDocument tmpxmldoc = Static_xmltools.GetXmlDocument(xmlfilename);
            XmlNodeList alllist   = null;
            string      xpathstr  = "/configuration/CronTask";

            alllist = Static_xmltools.SelectXmlNodes(tmpxmldoc, xpathstr);
            FrmLib.Log.commLoger.runLoger.Debug(string.Format("createTaskList count:{0}", alllist.Count));
            TimeDoTask            tdt    = null;
            TimeNowDoEventHandler myfunc = null;

            foreach (XmlNode onenode in alllist)
            {
                int    tasktype     = int.Parse(Static_xmltools.GetXmlAttr(onenode, "taskType"));
                string paramvalue   = Static_xmltools.GetXmlAttr(onenode, "paramValue");
                string procesorName = Static_xmltools.GetXmlAttr(onenode, "procesorName");
                try
                {
                    var nodeTaskHandle = FrmLib.Extend.tools_static.getTypeHaveMethodByName(nodeTaskHandles, procesorName);
                    if (nodeTaskHandle == null)
                    {
                        continue;
                    }
                    myfunc = (TimeNowDoEventHandler)Delegate.CreateDelegate(typeof(TimeNowDoEventHandler), nodeTaskHandle, procesorName);
                    if (tasktype == (int)enum_taskType.interval)
                    {
                        tdt = new TimeDoTask(int.Parse(paramvalue), myfunc);
                    }
                    else
                    {
                        tdt = new TimeDoTask(paramvalue, myfunc, (enum_taskType)tasktype);
                    }
                    alltask.Add(tdt);
                }
                catch (Exception exp)
                {
                    FrmLib.Log.commLoger.runLoger.Error("create task error, info:" + onenode.InnerText);
                    return(null);
                }
            }
            return(alltask);
        }