Beispiel #1
0
        /// <summary>
        /// 执行。
        /// </summary>
        /// <param name="config">配置。</param>
        public void Execute(ScheduledTaskConfiguration config)
        {
            this.Config = config;
            ThreadStart start = new ThreadStart(this.ScheduleCallback);

            this.ScheduleThread = new Thread(start);
            this.ScheduleThread.Start();
        }
Beispiel #2
0
        /// <summary>
        /// 分析配置节的 XML。
        /// </summary>
        /// <param name="section">一个 XmlNode,它包含配置文件中的配置信息。提供对配置节 XML 内容的直接访问。</param>
        /// <returns>配置对象。</returns>
        public static List <ScheduledTaskConfiguration> Parse(XmlNode section)
        {
            List <ScheduledTaskConfiguration> configurations = new List <ScheduledTaskConfiguration>();

            foreach (XmlNode node in section.ChildNodes)
            {
                if (node.Name == "scheduledTask")
                {
                    ScheduledTaskConfiguration configuration = new ScheduledTaskConfiguration();
                    foreach (XmlAttribute attribute in node.Attributes)
                    {
                        string name = attribute.Name;
                        if (name == null)
                        {
                            continue;
                        }
                        name = string.IsInterned(name);
                        if (name == "ScheduledTaskType")
                        {
                            configuration.ScheduledTaskType = attribute.Value;
                            continue;
                        }
                        if (name == "ThreadSleepSecond")
                        {
                            configuration.ThreadSleepSecond = Convert.ToInt32(attribute.Value, 10);
                        }
                    }
                    foreach (XmlNode node2 in node.ChildNodes)
                    {
                        if (node2.Name == "execute")
                        {
                            foreach (XmlAttribute attribute2 in node2.Attributes)
                            {
                                if (attribute2.Name == "type")
                                {
                                    configuration.Executes.Add(attribute2.Value);
                                    break;
                                }
                            }
                            continue;
                        }
                    }
                    configurations.Add(configuration);
                }
            }
            return(configurations);
        }
Beispiel #3
0
        /// <summary>
        /// 写执行日志文件。
        /// </summary>
        /// <param name="config">配置信息。</param>
        public static void WriteLog(ScheduledTaskConfiguration config)
        {
            if ((config != null) && LogSetting.ScheduledTaskLogEnabled)
            {
                try
                {
                    string str = string.Format("Task\t\t\t\t= {0}\r\nTime              = {1}", config.ScheduledTaskType, FormatConvertor.DateTimeToTimeString(DateTime.Now, true));
                    // LogHelper.Write(LogSetting.ScheduleTaskLogFilePath(DateTime.Today, config), str);

                    log.Info(str);
                }
                catch (Exception exception)
                {
                    ExceptionHandler.HandleException(exception);
                }
            }
        }