예제 #1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            var addSeconds = 0;

            if (_isOn)
            {
                // Update UI
                lblState.Text      = "OFF";
                lblState.ForeColor = Color.Red;
                btnStart.Text      = "Start Schedule";

                // Reset the scheduler
                _taskScheduler.Enabled = false;
                _taskScheduler.TriggerItems.Clear();
            }
            else
            {
                // Update UI
                lblState.Text      = "ON";
                lblState.ForeColor = Color.Green;
                btnStart.Text      = "Stop Schedule";

                // Clear the data before wrintg the elements in it
                _storage.Clear();

                for (var i = ScheduleList.Items.Count - 1; i >= 0; i--)
                {
                    var date = Convert.ToDateTime(ScheduleList.Items[i].ToString().Split('|')[0]);

                    if (date.CompareTo(DateTime.Now) <= 0)
                    {
                        addSeconds += 11;
                        var item = (AttackScheduler)ScheduleList.Items[i];

                        date      = DateTime.Now.AddSeconds(addSeconds);
                        item.Date = date;

                        ScheduleList.Items.RemoveAt(i);
                        ScheduleList.Items.Add(item);
                    }

                    _storage.WriteLine(RegisterItem((AttackScheduler)ScheduleList.Items[i]));
                }

                //_tickTimer.AddEvent(new SingleEvent(((AttackScheduler)ScheduleList.Items[0]).Date));
                var triggerItem = CreateTriggerItems(((AttackScheduler)ScheduleList.Items[0]).Date);
                _taskScheduler.AddTrigger(triggerItem); // Add the trigger to List

                // start the timer
                _taskScheduler.Enabled = true;
            }

            _isOn ^= true;
        }
예제 #2
0
        public ManagementSpecs()
        {
            _taskScheduler = new TaskScheduler();
            var triggerItem = new TriggerItem();

            triggerItem.Tag         = "Test";
            triggerItem.StartDate   = new DateTime(2018, 3, 28);
            triggerItem.EndDate     = new DateTime(2018, 3, 30);
            triggerItem.TriggerTime = new DateTime(2018, 3, 29, 9, 30, 0);
            triggerItem.OnTrigger  += new OnTriggerEventHandler(triggerItem_OnTrigger);
            triggerItem.Enabled     = true;
            _taskScheduler.AddTrigger(triggerItem);
        }