Beispiel #1
0
        public static DateTime GetRandomDateTime(this DateTime to, TaskPeriod period)
        {
            switch (period)
            {
            case TaskPeriod.Day:
                return(GetRandomDate(to.GetDayStartDate(), to));

            case TaskPeriod.Week:
                return(GetRandomDate(to.GetWeekStartDate(), to));

            case TaskPeriod.Month:
                return(GetRandomDate(to.GetMonthStartDate(), to));

            case TaskPeriod.Quarter:
                return(GetRandomDate(to.GetQuarterStartDate(), to));

            case TaskPeriod.Year:
                return(GetRandomDate(to.GetYearStartDate(), to));

            case TaskPeriod.All:
                return(GetRandomDate(to.AddYears(-100), to));

            default:
                throw new ArgumentException(nameof(period));
            }
        }
        private IEnumerable <WorkTask> GetTestTasks(int count, TaskPeriod period)
        {
            var dt = DateTime.Now;

            return(Enumerable.Range(0, count).Select(i => new WorkTask {
                Id = Guid.NewGuid(), Name = $"Task{i}", Created = dt.GetRandomDateTime(period)
            }));
        }
Beispiel #3
0
        /// <summary>
        /// 设置需配置的任务周期对象。
        /// </summary>
        /// <param name="taskPeriod">任务周期。</param>
        /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
        public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
        {
            this.m_TaskPeriod = taskPeriod as CurvePointTaskPeriod;

            for (int intIndex = 0; intIndex < this.Items.Count; intIndex++)
            {
                CurvePointItem _CurvePointItem = this.Items[intIndex] as CurvePointItem;
                if (_CurvePointItem.CurvePoint == this.m_TaskPeriod.CurvePoint)
                {
                    this.SelectedIndex = intIndex;
                }
            }
        }
Beispiel #4
0
        //public IEnumerable<WorkTask> GetTasks(Guid userId)
        //{
        //    var now = DateTime.Now;
        //    var ret = context.Tasks
        //        .Include(e => e.Project)
        //        .Include(e => e.TaskHistoryItems)
        //        .Where(t => t.Created.HasValue && t.UserId == userId &&
        //        t.Created.Value.Month.Equals(now.Month) &&
        //        t.Created.Value.Year.Equals(now.Year));

        //    return ret;
        //}

        public IEnumerable <WorkTask> GetTasks(Guid userId, TaskPeriod period)
        {
            DateTime to = DateTime.Now;
            DateTime from;

            switch (period)
            {
            case TaskPeriod.Day:
                from = to.GetDayStartDate();
                break;

            case TaskPeriod.Week:
                from = to.GetWeekStartDate();
                break;

            case TaskPeriod.Month:
                from = to.GetMonthStartDate();
                break;

            case TaskPeriod.Quarter:
                from = to.GetQuarterStartDate();
                break;

            case TaskPeriod.Year:
                from = to.GetYearStartDate();
                break;

            case TaskPeriod.All:
                from = to.AddYears(-100);
                break;

            default:
                throw new ArgumentException(nameof(period));
            }

            var ret = context.GetTasks()
                      .Include(e => e.Project)
                      .Include(e => e.TaskHistoryItems)
                      .Where(t => t.UserId == userId &&
                             t.Created.HasValue && t.Created >= from && t.Created <= to);

            return(ret);
        }
        /// <summary>
        /// 设置需配置的任务周期对象。
        /// </summary>
        /// <param name="taskPeriod">任务周期。</param>
        /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
        public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
        {
            this.m_TaskPeriod = taskPeriod as PredecessorTaskPeriod;

            foreach (TaskConfig _TaskConfig in currentTaskConfig.Group.TaskConfigs)
            {
                if (_TaskConfig.Equals(currentTaskConfig) == false)
                {
                    this.cmbTask.Items.Add(_TaskConfig);

                    if (this.m_TaskPeriod.PredecessorTask != null && this.m_TaskPeriod.PredecessorTask.Equals(_TaskConfig))
                    {
                        this.cmbTask.SelectedIndex = this.cmbTask.Items.Count - 1;
                    }
                }
            }

            if (this.cmbTask.SelectedIndex == -1 && this.cmbTask.Items.Count > 0)
            {
                this.cmbTask.SelectedIndex = 0;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 设置需配置的任务周期对象。
        /// </summary>
        /// <param name="taskPeriod">任务周期。</param>
        /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
        public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
        {
            this.m_TaskPeriod = taskPeriod as DayTaskPeriod;

            this.tlpPeriod = new System.Windows.Forms.TableLayoutPanel();
            this.labDay    = new System.Windows.Forms.Label();
            this.numHour   = new System.Windows.Forms.NumericUpDown();
            this.labHour   = new System.Windows.Forms.Label();
            this.numMinute = new System.Windows.Forms.NumericUpDown();
            this.labMinute = new System.Windows.Forms.Label();

            this.tlpPeriod.ColumnCount = 6;
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpPeriod.Controls.Add(this.labDay, 0, 0);
            this.tlpPeriod.Controls.Add(this.numHour, 1, 0);
            this.tlpPeriod.Controls.Add(this.labHour, 2, 0);
            this.tlpPeriod.Controls.Add(this.numMinute, 3, 0);
            this.tlpPeriod.Controls.Add(this.labMinute, 4, 0);
            this.tlpPeriod.Dock     = System.Windows.Forms.DockStyle.Top;
            this.tlpPeriod.Location = new System.Drawing.Point(0, 0);
            this.tlpPeriod.RowCount = 1;
            this.tlpPeriod.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpPeriod.Size     = new System.Drawing.Size(554, 25);
            this.tlpPeriod.TabIndex = 0;

            this.labDay.AutoSize  = true;
            this.labDay.Dock      = System.Windows.Forms.DockStyle.Fill;
            this.labDay.Location  = new System.Drawing.Point(3, 0);
            this.labDay.Size      = new System.Drawing.Size(29, 25);
            this.labDay.TabIndex  = 0;
            this.labDay.Text      = "每天";
            this.labDay.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

            this.numHour.Dock     = System.Windows.Forms.DockStyle.Fill;
            this.numHour.Location = new System.Drawing.Point(38, 3);
            this.numHour.Maximum  = new decimal(new int[] { 23, 0, 0, 0 });
            this.numHour.Size     = new System.Drawing.Size(50, 21);
            this.numHour.TabIndex = 1;

            this.labHour.AutoSize  = true;
            this.labHour.Dock      = System.Windows.Forms.DockStyle.Fill;
            this.labHour.Location  = new System.Drawing.Point(94, 0);
            this.labHour.Size      = new System.Drawing.Size(17, 25);
            this.labHour.TabIndex  = 2;
            this.labHour.Text      = "时";
            this.labHour.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

            this.numMinute.Dock     = System.Windows.Forms.DockStyle.Fill;
            this.numMinute.Location = new System.Drawing.Point(117, 3);
            this.numMinute.Maximum  = new decimal(new int[] { 59, 0, 0, 0 });
            this.numMinute.Size     = new System.Drawing.Size(50, 21);
            this.numMinute.TabIndex = 3;

            this.labMinute.AutoSize  = true;
            this.labMinute.Dock      = System.Windows.Forms.DockStyle.Fill;
            this.labMinute.Location  = new System.Drawing.Point(173, 0);
            this.labMinute.Size      = new System.Drawing.Size(65, 25);
            this.labMinute.TabIndex  = 4;
            this.labMinute.Text      = "分开始执行";
            this.labMinute.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

            this.Controls.Add(this.tlpPeriod);

            this.numHour.Value   = this.m_TaskPeriod.TimeNum / 10000;
            this.numMinute.Value = (this.m_TaskPeriod.TimeNum / 100) % 100;
        }
Beispiel #7
0
 /// <summary>
 /// 设置需配置的任务周期对象。
 /// </summary>
 /// <param name="taskPeriod">任务周期。</param>
 /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
 public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
 {
     this.m_TaskPeriod          = taskPeriod as IntervalTaskPeriod;
     this.numIntervalTime.Value = this.m_TaskPeriod.IntervalTime;
 }
 public FixedTaskTimer(DateTime taskDate, TaskPeriod period)
     : this()
 {
     this.TaskPeriod = period;
     this.TaskDate = taskDate;
 }
Beispiel #9
0
 /// <summary>
 /// 设置需配置的任务周期对象。
 /// </summary>
 /// <param name="taskPeriod">任务周期。</param>
 /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
 public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
 {
     this.m_TaskPeriod = taskPeriod as Minute30TaskPeriod;
 }
Beispiel #10
0
 /// <summary>
 /// 设置需配置的任务周期对象。
 /// </summary>
 /// <param name="taskPeriod">任务周期。</param>
 /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
 public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
 {
     this.m_TaskPeriod = taskPeriod as Hour1TaskPeriod;
 }
Beispiel #11
0
 /// <summary>
 /// 设置需配置的任务周期对象。
 /// </summary>
 /// <param name="taskPeriod">任务周期。</param>
 /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
 public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
 {
     this.m_TaskPeriod = taskPeriod as ContinuousTaskPeriod;
 }
        public void GetTasks_VariousPeriod_ReturnsCorrectTask(string taskName, DateTime dt, TaskPeriod period)
        {
            var userId = Guid.NewGuid();
            var data   = new List <WorkTask>
            {
                new WorkTask {
                    Name = taskName, UserId = userId, Created = dt
                },
            };

            var set = FakeDbSet(data);
            var ctx = Substitute.For <ApplicationDbContext>(new DbContextOptions <ApplicationDbContext>());

            ctx.GetTasks().Returns(set);

            var repo  = new TaskRepository(ctx);
            var tasks = repo.GetTasks(userId, period).ToArray();

            Assert.Equal(tasks.Length, 1);
            Assert.Equal(tasks[0].Name, taskName);
        }
Beispiel #13
0
        /// <summary>
        /// 设置需配置的任务周期对象。
        /// </summary>
        /// <param name="taskPeriod">任务周期。</param>
        /// <param name="currentTaskConfig">设置周期时所配置的任务配置对象。</param>
        public void SetTaskPeriod(TaskPeriod taskPeriod, TaskConfig currentTaskConfig)
        {
            this.m_TaskPeriod = taskPeriod as MonthTaskPeriod;

            this.tlpPeriod = new System.Windows.Forms.TableLayoutPanel();
            this.labMonth  = new System.Windows.Forms.Label();
            this.cmbDay    = new ComboBox();
            this.labDay    = new Label();
            this.numHour   = new System.Windows.Forms.NumericUpDown();
            this.labHour   = new System.Windows.Forms.Label();
            this.numMinute = new System.Windows.Forms.NumericUpDown();
            this.labMinute = new System.Windows.Forms.Label();

            this.tlpPeriod.ColumnCount = 8;
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.tlpPeriod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpPeriod.Controls.Add(this.labMonth, 0, 0);
            this.tlpPeriod.Controls.Add(this.cmbDay, 1, 0);
            this.tlpPeriod.Controls.Add(this.labDay, 2, 0);
            this.tlpPeriod.Controls.Add(this.numHour, 3, 0);
            this.tlpPeriod.Controls.Add(this.labHour, 4, 0);
            this.tlpPeriod.Controls.Add(this.numMinute, 5, 0);
            this.tlpPeriod.Controls.Add(this.labMinute, 6, 0);
            this.tlpPeriod.Dock     = System.Windows.Forms.DockStyle.Top;
            this.tlpPeriod.RowCount = 1;
            this.tlpPeriod.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpPeriod.Size = new System.Drawing.Size(554, 25);

            this.labMonth.AutoSize  = true;
            this.labMonth.Dock      = System.Windows.Forms.DockStyle.Fill;
            this.labMonth.Size      = new System.Drawing.Size(29, 25);
            this.labMonth.Text      = "每月";
            this.labMonth.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

            this.cmbDay.Dock          = DockStyle.Fill;
            this.cmbDay.Size          = new System.Drawing.Size(50, 21);
            this.cmbDay.DropDownStyle = ComboBoxStyle.DropDownList;
            for (int intIndex = 1; intIndex <= 31; intIndex++)
            {
                this.cmbDay.Items.Add(intIndex);
                if ((this.m_TaskPeriod.DateTimeNum / 10000) == intIndex)
                {
                    this.cmbDay.SelectedIndex = this.cmbDay.Items.Count - 1;
                }
            }
            if (this.cmbDay.SelectedIndex == -1)
            {
                this.cmbDay.SelectedIndex = 0;
            }

            this.labDay.AutoSize  = true;
            this.labDay.Dock      = System.Windows.Forms.DockStyle.Fill;
            this.labDay.Text      = "日";
            this.labDay.Size      = new System.Drawing.Size(17, 25);
            this.labDay.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

            this.numHour.Dock    = System.Windows.Forms.DockStyle.Fill;
            this.numHour.Maximum = new decimal(new int[] { 23, 0, 0, 0 });
            this.numHour.Size    = new System.Drawing.Size(50, 21);

            this.labHour.AutoSize  = true;
            this.labHour.Dock      = System.Windows.Forms.DockStyle.Fill;
            this.labHour.Text      = "时";
            this.labHour.Size      = new System.Drawing.Size(17, 25);
            this.labHour.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

            this.numMinute.Dock    = System.Windows.Forms.DockStyle.Fill;
            this.numMinute.Maximum = new decimal(new int[] { 59, 0, 0, 0 });
            this.numMinute.Size    = new System.Drawing.Size(50, 21);

            this.labMinute.AutoSize  = true;
            this.labMinute.Dock      = System.Windows.Forms.DockStyle.Fill;
            this.labMinute.Text      = "分开始执行";
            this.labMinute.Size      = new System.Drawing.Size(65, 25);
            this.labMinute.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

            this.Controls.Add(this.tlpPeriod);

            this.numHour.Value   = (this.m_TaskPeriod.DateTimeNum / 100) % 100;
            this.numMinute.Value = this.m_TaskPeriod.DateTimeNum % 100;
        }