示例#1
0
        /// <summary>
        /// 任务的拆分
        /// </summary>
        /// <param name="cron_task"></param>
        private void cron_task_parse(string cron_task)
        {
            string[] cron_parse = cron_task.Split(' ');

            if (cron_parse.Length < 6)
            {
                this.list_log(cron_task + " -- 无法解析");
                return;
            }

            //分 时 日 月 周 命令 解析
            cronTask c = new cronTask();

            c.mins   = cron_parse[0].Trim();
            c.hours  = cron_parse[1].Trim();
            c.days   = cron_parse[2].Trim();
            c.months = cron_parse[3].Trim();
            c.weeks  = cron_parse[4].Trim();

            List <string> cron_command = new List <string>();

            for (int i = 5; i < cron_parse.Length; i++)
            {
                string args_t = cron_parse[i].Trim();
                cron_command.Add(args_t);
            }
            c.command = string.Join(" ", cron_command);

            //if (File.Exists(command_s))
            //{
            //    c.command = command_s;

            //    List<string> cron_args = new List<string>();
            //    for (int i = 6; i < cron_parse.Length; i++)
            //    {
            //        string args_t = cron_parse[i].Trim();
            //        cron_args.Add(args_t);
            //    }
            //    c.args = string.Join(" ", cron_args);
            //    c.type = "file";
            //}
            //else
            //{

            //    List<string> cron_command = new List<string>();
            //    for (int i = 5; i < cron_parse.Length; i++)
            //    {
            //        string args_t = cron_parse[i].Trim();
            //        cron_command.Add(args_t);
            //    }
            //    c.command = string.Join(" ", cron_command);
            //    c.type = "cmd";
            //}

            this.log(c.command);
            cronTasks.Add(c);
        }
示例#2
0
        private bool checkTaskIsRun(cronTask c)
        {
            //分 时 日 月 周
            if (c.mins.Trim() == "*" && c.hours.Trim() == "*" &&
                c.days.Trim() == "*" && c.months.Trim() == "*" &&
                c.weeks.Trim() == "*")
            {
                //【开启|关闭】秒监控
                int sec2 = Convert.ToInt32(DateTime.Now.Second);
                if (this.checkBoxMin.Checked)
                {
                    return(true);
                }
                else
                {
                    if (sec2 == 0)
                    {
                        return(true);
                    }
                    return(false);
                }
            }

            //周
            int week = Convert.ToInt32(DateTime.Now.DayOfWeek);

            if (!checkTimeIsOk(c.weeks, week, "week"))
            {
                return(false);
            }

            //月
            int month = Convert.ToInt32(DateTime.Now.Month);

            //Console.WriteLine(month.ToString());
            if (!checkTimeIsOk(c.months, month, "month"))
            {
                return(false);
            }

            //天
            int day = Convert.ToInt32(DateTime.Now.Day);

            //Console.WriteLine(day.ToString());
            if (!checkTimeIsOk(c.days, day, "day"))
            {
                return(false);
            }

            //小时
            int hour = Convert.ToInt32(DateTime.Now.Hour);

            //Console.WriteLine(hour.ToString());
            if (!checkTimeIsOk(c.hours, hour, "hour"))
            {
                return(false);
            }

            //分钟
            int min = Convert.ToInt32(DateTime.Now.Minute);

            //Console.WriteLine(min.ToString());
            if (!checkTimeIsOk(c.mins, min, "min"))
            {
                return(false);
            }

            //【开启|关闭】秒监控
            int sec = Convert.ToInt32(DateTime.Now.Second);

            //this.log(this.checkBoxMin.Checked.ToString() + ":" + sec.ToString());
            if (this.checkBoxMin.Checked)
            {
                //this.log("开启秒控制");
                return(true);
            }
            else
            {
                //this.log("关闭秒控制");
                if (sec == 0)
                {
                    return(true);
                }
                return(false);
            }
        }