Example #1
0
        public ActionResult TaskInfo(int?sysNo)
        {
            var model = new ParaSyTask();

            model.Config = new Model.SyTaskConfig();
            //获取实现了ITask的任务类型名称
            var typeList = TaskManager.Instance.GetType()
                           .Assembly.GetExportedTypes()
                           .Where(x => x.GetInterface("ITask") != null)
                           .ToList();
            var types = new Dictionary <Type, string>();

            foreach (var t in typeList)
            {
                var p = t.GetCustomAttributes(typeof(DescriptionAttribute), false);
                var s = p.Any() ? ((DescriptionAttribute)(p[0])).Description : "无描述";
                types.Add(t, s);
            }
            ViewBag.Types = types;
            if (sysNo != null)
            {
                var task = Hyt.BLL.Sys.SyTaskBo.Instance.GetTask(sysNo ?? 0);
                if (task.CreateTime == default(DateTime))
                {
                    task.CreateTime = DateTime.Now;
                }
                model.Config = task;
                switch (task.Timetype)
                {
                case (int)TaskTimeType.Interval:
                    if (!string.IsNullOrEmpty(task.TimeQuantum))
                    {
                        var timeQuantum = task.TimeQuantum.Split(',');
                        model.StartTimeQuantum = new TimeSpan(long.Parse(timeQuantum[0]));
                        model.EndTimeQuantum   = new TimeSpan(long.Parse(timeQuantum[1]));
                    }
                    model.IntervalTime = Int64.Parse(task.ExecuteTime) / (10000000);
                    break;

                case (int)TaskTimeType.Day:
                    model.DayExecuteTime = new TimeSpan(long.Parse(task.ExecuteTime));
                    break;

                case (int)TaskTimeType.Week:
                    model.DayOfWeekExecuteTime = new TimeSpan(long.Parse(task.ExecuteTime));
                    break;

                case (int)TaskTimeType.Month:
                    var time = new TimeSpan(long.Parse(task.ExecuteTime));
                    model.MonthHmsExecuteTime   = new TimeSpan(time.Hours, time.Minutes, time.Seconds);
                    model.MonthOfDayExecuteTime = time.Days;
                    break;
                }
            }
            else
            {
                model.EndTimeQuantum = new TimeSpan(23, 59, 59);
            }
            return(View(model));
        }
Example #2
0
        public JsonResult AddTaskInfo(ParaSyTask model)
        {
            var result = new Model.Result
            {
                Message = "任务添加成功",
                Status  = true
            };

            try
            {
                //时间转换为刻度数
                switch (model.Config.Timetype)
                {
                case (int)TaskTimeType.Interval:
                    //是否设置了间隔任务的时间段
                    if (model.StartTimeQuantum != default(TimeSpan) && model.EndTimeQuantum != default(TimeSpan))
                    {
                        model.Config.TimeQuantum = model.StartTimeQuantum.Ticks + "," +
                                                   model.EndTimeQuantum.Ticks;
                    }
                    model.Config.ExecuteTime = (10000000 * model.IntervalTime).ToString();
                    break;

                case (int)TaskTimeType.Day:
                    model.Config.ExecuteTime = model.DayExecuteTime.Ticks.ToString();
                    break;

                case (int)TaskTimeType.Week:
                    model.Config.ExecuteTime = model.DayOfWeekExecuteTime.Ticks.ToString();
                    break;

                case (int)TaskTimeType.Month:
                    model.Config.ExecuteTime =
                        model.MonthHmsExecuteTime.Add(new TimeSpan(model.MonthOfDayExecuteTime, 0, 0, 0))
                        .Ticks.ToString();
                    break;
                }

                model.Config.LastExecuteTime = model.Config.LastExecuteTime == System.DateTime.MinValue ? (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue : model.Config.LastExecuteTime;
                //添加
                if (model.Config.SysNo == 0)
                {
                    model.Config.CreateTime = DateTime.Now;
                    model.Config.Status     = 1;
                    model.Config.StartTime  = model.Config.StartTime == System.DateTime.MinValue ? (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue : model.Config.StartTime;
                    model.Config.EndTime    = model.Config.EndTime == System.DateTime.MinValue ? (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue : model.Config.EndTime;
                    Hyt.BLL.Sys.SyTaskBo.Instance.Add(model.Config);
                }
                //更新
                else
                {
                    result.Message = "任务更新成功";
                    Hyt.BLL.Sys.SyTaskBo.Instance.UpdateTask(model.Config);
                }
                TaskManager.Instance.Reload();
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = false;
                //TODO:记录错误
            }
            return(Json(result));
        }