Пример #1
0
 public WlbEditScheduledTask(WlbScheduledTask Task)
 {
     InitializeComponent();
     _task = Task;
     PopulateControls();
     InitializeControls();
 }
Пример #2
0
        public WlbScheduledTask GetNextExecutingTask()
        {
            WlbScheduledTask firstTask = null;

            int currentTimeSortKey = GetSortKey(WlbScheduledTask.ConvertToWlbTaskDayOfWeek(DateTime.Now.DayOfWeek), DateTime.Now);

            foreach (int key in this.VirtualTaskList.Keys)
            {
                //only consider Enabled tasks
                if (this.VirtualTaskList[key].Enabled)
                {
                    if (null == firstTask)
                    {
                        firstTask = this.VirtualTaskList[key];
                    }

                    if (key > currentTimeSortKey)
                    {
                        return(this.VirtualTaskList[key]);
                    }
                }
            }
            //we are still here, so we have not found the next task.  this means that we
            // need to account for week wrapping.  This shoudl be the first task of the Virtual
            // Task List
            return(firstTask);
        }
Пример #3
0
 public WlbEditScheduledTask(int NewTaskId, WlbScheduledTask.WlbTaskActionType ActionType)
 {
     InitializeComponent();
     _task = new WlbScheduledTask(NewTaskId.ToString());
     _task.ActionType = ActionType;
     PopulateControls();
 }
Пример #4
0
 /// <summary>
 /// Accepts a client's local time DayOfWeek and ExecuteTime of a scheduled task
 /// and returns the DaysOfWeek and ExecuteTime adjusted to UTC time
 /// </summary>
 /// <param name="LocalDaysOfWeek">Task's DaysOfWeek value in local time</param>
 /// <param name="LocalExecuteTime">Task's ExecuteTime in local time</param>
 /// <param name="UtcDaysOfWeek">(Output) Task's DaysOfWeek value adjusted to UTC</param>
 /// <param name="UtcExecuteTime">(Output) Task's ExecuteTime value adjusted to UTC</param>
 public static void GetUTCTaskTimes(WlbScheduledTask.WlbTaskDaysOfWeek LocalDaysOfWeek, DateTime LocalExecuteTime,
                                    out WlbScheduledTask.WlbTaskDaysOfWeek UtcDaysOfWeek, out DateTime UtcExecuteTime)
 {
     UtcDaysOfWeek  = LocalDaysOfWeek;
     UtcExecuteTime = LocalExecuteTime.AddMinutes(LocalOffsetMinutes());
     if (DateTime.Compare(LocalExecuteTime.Date, UtcExecuteTime.Date) < 0)
     {
         UtcDaysOfWeek = WlbScheduledTask.NextDay(LocalDaysOfWeek);
     }
     else if (DateTime.Compare(LocalExecuteTime.Date, UtcExecuteTime.Date) > 0)
     {
         UtcDaysOfWeek = WlbScheduledTask.PreviousDay(LocalDaysOfWeek);
     }
 }
Пример #5
0
        public static WlbPoolPerformanceMode GetTaskOptMode(WlbScheduledTask task)
        {
            WlbPoolPerformanceMode mode = WlbPoolPerformanceMode.MaximizePerformance;

            if (task.TaskParameters["OptMode"] == "0")
            {
                mode = WlbPoolPerformanceMode.MaximizePerformance;
            }
            else
            {
                mode = WlbPoolPerformanceMode.MaximizeDensity;
            }
            return(mode);
        }
Пример #6
0
        /// <summary>
        /// Accepts UTC DayOfWeek and ExecuteTime of a scheduled task
        /// and returns the DaysOfWeek and ExecuteTime adjusted to client's local time
        /// </summary>
        /// <param name="UtcDaysOfWeek">Task's DaysOfWeek value in UTC</param>
        /// <param name="UtcExecuteTime">Task's ExecuteTime in UTC</param>
        /// <param name="LocalDaysOfWeek">(Output) Task's DaysOfWeek value adjusted to local time</param>
        /// <param name="LocalExecuteTime">(Output) Task's ExecuteTime value adjusted to local time</param>
        public static void GetLocalTaskTimes(WlbScheduledTask.WlbTaskDaysOfWeek UtcDaysOfWeek, DateTime UtcExecuteTime,
                                             out WlbScheduledTask.WlbTaskDaysOfWeek LocalDaysOfWeek, out DateTime LocalExecuteTime)
        {
            LocalDaysOfWeek  = UtcDaysOfWeek;
            LocalExecuteTime = UtcExecuteTime.AddMinutes(LocalOffsetMinutes() * -1);

            if (UtcDaysOfWeek != WlbTaskDaysOfWeek.None &&
                UtcDaysOfWeek != WlbTaskDaysOfWeek.All &&
                UtcDaysOfWeek != WlbTaskDaysOfWeek.Weekdays &&
                UtcDaysOfWeek != WlbTaskDaysOfWeek.Weekends)
            {
                if (DateTime.Compare(UtcExecuteTime.Date, LocalExecuteTime.Date) < 0)
                {
                    LocalDaysOfWeek = WlbScheduledTask.NextDay(UtcDaysOfWeek);
                }
                else if (DateTime.Compare(UtcExecuteTime.Date, LocalExecuteTime.Date) > 0)
                {
                    LocalDaysOfWeek = WlbScheduledTask.PreviousDay(UtcDaysOfWeek);
                }
            }
        }
Пример #7
0
        public WlbScheduledTask Clone()
        {
            WlbScheduledTask newTask = new WlbScheduledTask(this.TaskId.ToString());

            newTask.ActionType      = this.ActionType;
            newTask.DaysOfWeek      = this.DaysOfWeek;
            newTask.DeleteTask      = this.DeleteTask;
            newTask.Description     = this.Description;
            newTask.DisableTime     = this.DisableTime;
            newTask.Enabled         = this.Enabled;
            newTask.EnableDate      = this.EnableDate;
            newTask.ExecuteTime     = this.ExecuteTime;
            newTask.LastRunDate     = this.LastRunDate;
            newTask.LastRunResult   = this.LastRunResult;
            newTask.LastTouched     = this.LastTouched;
            newTask.LastTouchedBy   = this.LastTouchedBy;
            newTask.Name            = this.Name;
            newTask.Owner           = this.Owner;
            newTask.TaskParameters  = this.TaskParameters;
            newTask.TriggerInterval = this.TriggerInterval;

            return(newTask);
        }
Пример #8
0
        public WlbScheduledTask GetLastExecutingTask()
        {
            int[] taskKeys = new int[this.VirtualTaskList.Keys.Count];
            this.VirtualTaskList.Keys.CopyTo(taskKeys, 0);
            WlbScheduledTask lastTask = this.VirtualTaskList[taskKeys[taskKeys.Length - 1]];

            int currentTimeSortKey = GetSortKey(WlbScheduledTask.ConvertToWlbTaskDayOfWeek(DateTime.Now.DayOfWeek), DateTime.Now);

            for (int i = taskKeys.Length - 1; i >= 0; i--)
            {
                //Only consider Enabled tasks
                if (this.VirtualTaskList[taskKeys[i]].Enabled)
                {
                    if (taskKeys[i] < currentTimeSortKey)
                    {
                        return(this.VirtualTaskList[taskKeys[i]]);
                    }
                }
            }
            //we are still here, so we have not found the previous task.  this means that we
            // need to account for week wrapping.  This should be the last task of the Virtual
            // Task List
            return(lastTask);
        }
Пример #9
0
        private static WlbPoolPerformanceMode GetTaskOptMode(WlbScheduledTask task)
        {
            WlbPoolPerformanceMode mode = WlbPoolPerformanceMode.MaximizePerformance;

            if (task.TaskParameters["OptMode"] == "0")
            {
                mode = WlbPoolPerformanceMode.MaximizePerformance;
            }
            else
            {
                mode = WlbPoolPerformanceMode.MaximizeDensity;
            }
            return mode;
        }
Пример #10
0
        private static string GetTaskDayOfWeek(WlbScheduledTask.WlbTaskDaysOfWeek taskDaysOfWeek,
            WlbScheduledTask.WlbTaskDaysOfWeek taskDaysofWeekSortedList)
        {
            string returnStr = "";
            returnStr += WlbScheduledTask.DaysOfWeekL10N(taskDaysOfWeek);

            //count the bits set in days of week.
            //this workaround had to be made to determine whether the original task was set for
            //weekends/weekdays/alldays
            uint bitCount = Bitcount((int)taskDaysofWeekSortedList);
            if (bitCount == 2)
            {
                returnStr += " (" + Messages.ResourceManager.GetString("WLB_DAY_WEEKENDS") + ")";
            }
            else if (bitCount == 5)
            {
                returnStr += " (" + Messages.ResourceManager.GetString("WLB_DAY_WEEKDAYS") + ")";
            }
            else if (bitCount == 7)
            {
                returnStr += " (" + Messages.ResourceManager.GetString("WLB_DAY_ALL") + ")";
            }

            return returnStr;
        }
Пример #11
0
 private static string GetTaskDayOfWeek(WlbScheduledTask.WlbTaskDaysOfWeek taskDaysOfWeek)
 {
     return WlbScheduledTask.DaysOfWeekL10N(taskDaysOfWeek);
 }
Пример #12
0
 public void NonNumericItemIDInCtor()
 {
     WlbScheduledTask task = new WlbScheduledTask("not a number");
     Assert.AreEqual(0, task.TaskId, "Non-numeric task ID");
 }
Пример #13
0
 public void Setup()
 {
     task = new WlbScheduledTask("73");
 }
 private string GetLocalizedDayOfWeek(WlbScheduledTask.WlbTaskDaysOfWeek daysOfWeek)
 {
     return WlbScheduledTask.DaysOfWeekL10N(daysOfWeek);
 }
Пример #15
0
        public WlbScheduledTask Clone()
        {
            WlbScheduledTask newTask = new WlbScheduledTask(this.TaskId.ToString());
            newTask.ActionType = this.ActionType;
            newTask.DaysOfWeek = this.DaysOfWeek;
            newTask.DeleteTask = this.DeleteTask;
            newTask.Description = this.Description;
            newTask.DisableTime = this.DisableTime;
            newTask.Enabled = this.Enabled;
            newTask.EnableDate = this.EnableDate;
            newTask.ExecuteTime = this.ExecuteTime;
            newTask.LastRunDate = this.LastRunDate;
            newTask.LastRunResult = this.LastRunResult;
            newTask.LastTouched = this.LastTouched;
            newTask.LastTouchedBy = this.LastTouchedBy;
            newTask.Name = this.Name;
            newTask.Owner = this.Owner;
            newTask.TaskParameters = this.TaskParameters;
            newTask.TriggerInterval = this.TriggerInterval;

            return newTask;
        }
Пример #16
0
 public WlbScheduledTask.WlbTaskDaysOfWeek FindSelectedDay(WlbScheduledTask.WlbTaskDaysOfWeek daysOfWeek)
 {
     uint bitCount = WlbOptModeScheduler.Bitcount((int)daysOfWeek);
     if (bitCount == 2)
     {
         return WlbScheduledTask.WlbTaskDaysOfWeek.Weekends;
     }
     else if (bitCount == 5)
     {
         return WlbScheduledTask.WlbTaskDaysOfWeek.Weekdays;
     }
     else if (bitCount == 7)
     {
         return WlbScheduledTask.WlbTaskDaysOfWeek.All;
     }
     return daysOfWeek;
 }
Пример #17
0
 private void EditTask(WlbScheduledTask task)
 {
     WlbScheduledTask editTask = task.Clone();
     WlbEditScheduledTask taskEditor = new WlbEditScheduledTask(editTask);
     DialogResult dr = taskEditor.ShowDialog();
     if (DialogResult.OK == dr)
     {
         WlbScheduledTask checkTask = CheckForDuplicateTask(editTask);
         if (null != checkTask)
         {
             using (var dlg = new ThreeButtonDialog(
                new ThreeButtonDialog.Details(
                    SystemIcons.Warning,
                    Messages.WLB_TASK_SCHEDULE_CONFLICT_BLURB,
                    Messages.WLB_TASK_SCHEDULE_CONFLICT_TITLE)))
             {
                 dlg.ShowDialog(this);
             }
             SelectTask(checkTask.TaskId);
         }
         else
         {
             editTask.LastTouchedBy = _pool.Connection.Username;
             editTask.LastTouched = DateTime.UtcNow;
             _scheduledTasks.TaskList[editTask.TaskId.ToString()] = editTask;
             PopulateListView();
             _hasChanged = true;
         }
     }
 }
Пример #18
0
        private WlbScheduledTasks BuildSampleTasksWithTimes()
        {
            WlbScheduledTasks tasks = new WlbScheduledTasks();

            Dictionary<string, string > taskParameters = new Dictionary<string, string>()
                                                             {
                                                                 { "OptMode", "1"} // Performance mode
                                                             };

            WlbScheduledTask taskA = new WlbScheduledTask("1")
                                         { 
                                             DaysOfWeek = WlbScheduledTask.WlbTaskDaysOfWeek.Friday,
                                             TaskParameters = taskParameters
                                         };
            WlbScheduledTask taskB = new WlbScheduledTask("2")
                                         {
                                             DaysOfWeek = WlbScheduledTask.WlbTaskDaysOfWeek.Monday,
                                             TaskParameters = taskParameters
                                         };

            //Weekend tasks adds 2 to the virtual task list, one for each day
            WlbScheduledTask taskC = new WlbScheduledTask("3")
                                         {
                                             DaysOfWeek = WlbScheduledTask.WlbTaskDaysOfWeek.Weekends,
                                             TaskParameters = taskParameters
                                         };
            Dictionary<string, WlbScheduledTask> taskCollection = new Dictionary<string, WlbScheduledTask>()
                                                                      {
                                                                          {"schedTask_1", taskA},
                                                                          {"schedTask_2", taskB},
                                                                          {"schedTask_3", taskC}
                                                                      };

            Assert.AreEqual(3, taskCollection.Count, "Setting up task collection");
            tasks.TaskList = taskCollection;
            return tasks;
        }
Пример #19
0
 /// <summary>
 /// Accepts a client's local time DayOfWeek and ExecuteTime of a scheduled task 
 /// and returns the DaysOfWeek and ExecuteTime adjusted to UTC time
 /// </summary>
 /// <param name="LocalDaysOfWeek">Task's DaysOfWeek value in local time</param>
 /// <param name="LocalExecuteTime">Task's ExecuteTime in local time</param>
 /// <param name="UtcDaysOfWeek">(Output) Task's DaysOfWeek value adjusted to UTC</param>
 /// <param name="UtcExecuteTime">(Output) Task's ExecuteTime value adjusted to UTC</param>
 public static void GetUTCTaskTimes(WlbScheduledTask.WlbTaskDaysOfWeek LocalDaysOfWeek, DateTime LocalExecuteTime, 
     out WlbScheduledTask.WlbTaskDaysOfWeek UtcDaysOfWeek, out DateTime UtcExecuteTime)
 {
     UtcDaysOfWeek = LocalDaysOfWeek;
     UtcExecuteTime = LocalExecuteTime.AddMinutes(LocalOffsetMinutes());
     if (DateTime.Compare(LocalExecuteTime.Date, UtcExecuteTime.Date) < 0)
     {
         UtcDaysOfWeek = WlbScheduledTask.NextDay(LocalDaysOfWeek);
     }
     else if (DateTime.Compare(LocalExecuteTime.Date, UtcExecuteTime.Date) > 0)
     {
         UtcDaysOfWeek = WlbScheduledTask.PreviousDay(LocalDaysOfWeek);
     }
 }
Пример #20
0
 /// <summary>
 /// Accepts UTC DayOfWeek and ExecuteTime of a scheduled task 
 /// and returns the DaysOfWeek and ExecuteTime adjusted to client's local time
 /// </summary>
 /// <param name="UtcDaysOfWeek">Task's DaysOfWeek value in UTC</param>
 /// <param name="UtcExecuteTime">Task's ExecuteTime in UTC</param>
 /// <param name="LocalDaysOfWeek">(Output) Task's DaysOfWeek value adjusted to local time</param>
 /// <param name="LocalExecuteTime">(Output) Task's ExecuteTime value adjusted to local time</param>
 public static void GetLocalTaskTimes(WlbScheduledTask.WlbTaskDaysOfWeek UtcDaysOfWeek, DateTime UtcExecuteTime, 
     out WlbScheduledTask.WlbTaskDaysOfWeek LocalDaysOfWeek, out DateTime LocalExecuteTime)
 {
     LocalDaysOfWeek = UtcDaysOfWeek;
     LocalExecuteTime = UtcExecuteTime.AddMinutes(LocalOffsetMinutes() * -1);
     
     if (UtcDaysOfWeek != WlbTaskDaysOfWeek.None &&
         UtcDaysOfWeek != WlbTaskDaysOfWeek.All &&
         UtcDaysOfWeek != WlbTaskDaysOfWeek.Weekdays &&
         UtcDaysOfWeek != WlbTaskDaysOfWeek.Weekends)
     {
         if (DateTime.Compare(UtcExecuteTime.Date, LocalExecuteTime.Date) < 0)
         {
             LocalDaysOfWeek = WlbScheduledTask.NextDay(UtcDaysOfWeek);
         }
         else if (DateTime.Compare(UtcExecuteTime.Date, LocalExecuteTime.Date) > 0)
         {
             LocalDaysOfWeek = WlbScheduledTask.PreviousDay(UtcDaysOfWeek);
         }
     }
 }
Пример #21
0
        /// <summary>
        /// Creates an artificial sort key that is used to sort the presentation of scheduled tasks.
        /// </summary>
        /// <param name="localDaysOfWeek">WlbScheduledTask.DaysOfWeek enumeration of the task denoting on which days it will execute</param>
        /// <param name="localExecuteTime">DateTime execute time of the task denoting on when the task </param>
        /// <returns></returns>
        private static int GetSortKey(WlbScheduledTask.WlbTaskDaysOfWeek localDaysOfWeek, DateTime localExecuteTime)
        {
            int sortKey;
            
            //The day of week is the primary sort item
            switch(localDaysOfWeek)
            {
                //Put ALL tasks at the front of the list
                case WlbScheduledTask.WlbTaskDaysOfWeek.All:
                    {
                        sortKey = 0;
                        break;
                    }
                //Next are WEEKDAY tasks
                case WlbScheduledTask.WlbTaskDaysOfWeek.Weekdays:
                    {
                        sortKey = 200000;
                        break;
                    }
                //Next are WEEKEND tasks
                case WlbScheduledTask.WlbTaskDaysOfWeek.Weekends:
                    {
                        sortKey = 400000;
                        break;
                    }
                //Finally, single-day tasks
                default:
                    {
                        sortKey = (int)localDaysOfWeek * 1000000;
                        break;
                    }
            }

            //Add the execute time of day as a secondary sort item
            //Multiply it by 100 to allow room for disabled tasks
            sortKey += (int)localExecuteTime.TimeOfDay.TotalMinutes * 100;

            return  sortKey;
        }
Пример #22
0
 private WlbScheduledTask CheckForDuplicateTask(WlbScheduledTask newTask)
 {
     WlbScheduledTask checkTask;
     foreach (string key in _scheduledTasks.TaskList.Keys)
     {
         checkTask = _scheduledTasks.TaskList[key];
         if (checkTask.Enabled && !checkTask.DeleteTask)
         {
             if ((checkTask.ActionType == newTask.ActionType) &&
                 ((checkTask.DaysOfWeek & newTask.DaysOfWeek) == checkTask.DaysOfWeek ||
                 (checkTask.DaysOfWeek & newTask.DaysOfWeek) == newTask.DaysOfWeek) &&
                 (string.Compare(HelpersGUI.DateTimeToString(checkTask.ExecuteTime, "t", false), HelpersGUI.DateTimeToString(newTask.ExecuteTime, "t", false)) == 0) &&
                 (checkTask.TaskId != newTask.TaskId))
             {
                 return checkTask; // taskExists = true;
             }
         }
     }
     return null;
 }
Пример #23
0
        public WlbPoolPerformanceMode GetCurrentScheduledPerformanceMode()
        {
            WlbScheduledTask lastTask = GetLastExecutingTask();

            return((WlbPoolPerformanceMode)int.Parse(lastTask.TaskParameters["OptMode"]));
        }
Пример #24
0
 private void DeleteTask(WlbScheduledTask task)
 {
     // if this is a new, unsaved task, simply delete it from the collection
     if (task.TaskId <= 0)
     {
         _scheduledTasks.TaskList.Remove(task.TaskId.ToString());
     }
     // otherwise, leave it in the collection but mark it for deletion
     else
     {
         task.DeleteTask = true;
     }
     PopulateListView();
     _hasChanged = true;
 }
Пример #25
0
 public static DayOfWeek ConvertFromWlbTaskDayOfWeek(WlbScheduledTask.WlbTaskDaysOfWeek wlbDayOfWeek)
 {
     return (DayOfWeek)(Math.Log((int)wlbDayOfWeek, 2));
 }
Пример #26
0
 private void EnableTask(WlbScheduledTask task)
 {
     //If we are trying to enable the task, check to see if it is a duplicate before allowing it
        if (!task.Enabled)
        {
        //We need to pretend the task is enabled to check for duplicates
        WlbScheduledTask enabledTask = task.Clone();
        enabledTask.Enabled = true;
        WlbScheduledTask checkTask = CheckForDuplicateTask(enabledTask);
        //if it's a duplicate task, display warning and return
        if (null != checkTask)
        {
            using (var dlg = new ThreeButtonDialog(
                new ThreeButtonDialog.Details(
                    SystemIcons.Warning,
                    Messages.WLB_TASK_SCHEDULE_CONFLICT_BLURB,
                    Messages.WLB_TASK_SCHEDULE_CONFLICT_TITLE)))
            {
                dlg.ShowDialog(this);
            }
            SelectTask(checkTask.TaskId);
            return;
        }
        }
        task.Enabled = !task.Enabled;
        PopulateListView();
        _hasChanged = true;
 }
Пример #27
0
 private string GetDayString(WlbScheduledTask.WlbTaskDaysOfWeek day)
 {
     return WlbScheduledTask.DaysOfWeekL10N(day);
 }