public void ScheduleGroup(object groupTuppleObjectObject)
        {
            Tuple <GroupDetails, TaskCollection, Timer> GroupTuppleObject = (Tuple <GroupDetails, TaskCollection, Timer>)groupTuppleObjectObject;

            try {
                GroupDetails   GroupDetailsObject   = GroupTuppleObject.Item1;
                TaskCollection TaskCollectionObject = GroupTuppleObject.Item2;
                Timer          GroupTimerObject     = GroupTuppleObject.Item3;
                DateTime       GroupScheduleTime    = DateTime.MinValue;
                TimeSpan       ScheduledIn          = new TimeSpan();
                switch (GroupDetailsObject.ScheduleOccurrence)
                {
                case "weekly":
                    GroupScheduleTime = GroupDetailsObject.ScheduleTime;
                    GroupScheduleTime = GroupScheduleTime.AddDays(Math.Abs(GroupDetailsObject.ScheduleDay - (int)DateTime.Now.DayOfWeek));
                    ScheduledIn       = GroupScheduleTime.Subtract(DateTime.Now);
                    GroupTimerObject.Change(Convert.ToInt32(ScheduledIn.TotalMilliseconds), Timeout.Infinite);
                    break;

                case "daily":
                    GroupScheduleTime = GroupDetailsObject.ScheduleTime;
                    if (DateTime.Now > GroupScheduleTime)
                    {
                        GroupScheduleTime = GroupScheduleTime.AddDays(1);
                    }
                    ScheduledIn = GroupScheduleTime.Subtract(DateTime.Now);
                    GroupTimerObject.Change(Convert.ToInt32(ScheduledIn.TotalMilliseconds), Timeout.Infinite);
                    break;

                case "interval":
                    GroupScheduleTime = DateTime.Now.AddMinutes(GroupDetailsObject.ScheduleInterval);
                    ScheduledIn       = GroupScheduleTime.Subtract(DateTime.Now);
                    GroupTimerObject.Change(Convert.ToInt32(ScheduledIn.TotalMilliseconds), Timeout.Infinite);
                    break;

                default:
                    Log.Write("ScheduleService() Error :: Invalid ScheduleOccurrence Given - " + GroupDetailsObject.ScheduleOccurrence + " In - " + GroupDetailsObject.Name);
                    break;
                }
                Log.Write("ScheduleGroup() -> Scheduled Group - " + TaskCollectionObject.Name + " Tasks - " + TaskCollectionObject.TaskList.Count.ToString() + " In - " + ScheduledIn.ToString());
            } catch (Exception ex) {
                Log.Write("ScheduleGroup() Error -> " + ex.Message);
            }
        }
Exemplo n.º 2
0
 public void Initialize(ref GroupDetails groupDetailsObject) {
     GroupDetailsObject = groupDetailsObject;
     IDString = "ID : " + GroupDetailsObject.ID.ToString();
     PathString = "Path : " + PathFormatter.FormatPath(GroupDetailsObject.Path);
     ServiceInfoString = "";
     switch (GroupDetailsObject.ScheduleOccurrence) {
         case "weekly":
             ServiceInfoString += "Occurrence : Weekly   Day : " + DaysList[GroupDetailsObject.ScheduleDay] + "   Time : " + GroupDetailsObject.ScheduleTime.ToShortTimeString();
             break;
         case "daily":
             ServiceInfoString += "Occurrence : Daily   Time : " + GroupDetailsObject.ScheduleTime.ToShortTimeString();
             break;
         case "interval":
             ServiceInfoString += "Occurrence : Interval   Interval : " + GroupDetailsObject.ScheduleInterval + " min";
             break;
     }
     Selected = false;
     Hover = false;
     Initialized = false;
 }
Exemplo n.º 3
0
 public void LoadGroupData() {
     GroupDetailsObject = GroupTuppleObject.Item1;
     DeleteGroup.Visible = true;
     this.Text = "Group : " + GroupDetailsObject.Name;
     NameTextBox.Text = GroupDetailsObject.Name;
     PathTextBox.Text = GroupDetailsObject.Path;
     GroupFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(GroupDetailsObject.Path);
     GroupFileDialog.FileName = System.IO.Path.GetFileName(GroupDetailsObject.Path);
     if (GroupDetailsObject.Enabled) EnabledComboBox.SelectedIndex = 0;
     else EnabledComboBox.SelectedIndex = 1;
     switch (GroupDetailsObject.ScheduleOccurrence) {
         case "weekly":
             OccurrenceComboBox.SelectedIndex = 0;
             break;
         case "daily":
             OccurrenceComboBox.SelectedIndex = 1;
             break;
         case "interval":
             OccurrenceComboBox.SelectedIndex = 2;
             break;
     }
     DayComboBox.SelectedIndex = GroupDetailsObject.ScheduleDay - 1;
     HourTextBox.Text = GroupDetailsObject.ScheduleTime.Hour.ToString();
     MinuteTextBox.Text = GroupDetailsObject.ScheduleTime.Minute.ToString().PadLeft(2, '0');
     IntervalTextBox.Text = GroupDetailsObject.ScheduleInterval.ToString();
     CreateSaveGroupButton.Text = "Save Group";
     CancelCloseButton.Text = "Close";
     IntervalComboBox.SelectedIndex = 0;
     GroupID = GroupDetailsObject.ID;
     GroupIDLabel.Text = "ID : " + GroupID.ToString();
     TasksLoadedCount = 0;
     TaskCollectionObject = GroupTuppleObject.Item2;
     NumberOfTasks = TaskCollectionObject.TaskList.Count;
     TotalTasksLabel.Text = "Total Tasks : " + NumberOfTasks.ToString();
     foreach (Task TaskObject in TaskCollectionObject.TaskList)
         ThreadPool.QueueUserWorkItem(new WaitCallback(PopulateTasks), TaskObject);
 }
Exemplo n.º 4
0
 public GroupButton(ref GroupDetails groupDetailsObject) {
     Initialize(ref groupDetailsObject);
 }
Exemplo n.º 5
0
 private void CreateSaveGroupButtonClick(object sender, EventArgs e) {
     if (ValidateData()) {
         bool PerformSave = true;
         if (System.IO.File.Exists(PathTextBox.Text)) {
             DialogResult OverWriteFile = MessageBox.Show("It seems like the XML Path you provided already exists. Do you want to overwite the existing file? " + vbCrLf + "Path : " + PathTextBox.Text, "XML Already Exists", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
             if (OverWriteFile == DialogResult.No) PerformSave = false;
         }
         if (PerformSave) {
             try {
                 if (GroupExisting) {
                     int IndexOfGroupObject = Program.GroupCollectionObject.GroupWithoutTimerList.IndexOf(GroupTuppleObject);
                     GroupDetailsObject.Name = NameTextBox.Text;
                     GroupDetailsObject.Path = PathTextBox.Text;
                     GroupDetailsObject.Enabled = EnabledComboBox.SelectedIndex == 0;
                     GroupDetailsObject.ScheduleOccurrence = OccurrenceComboBox.SelectedItem.ToString().ToLower();
                     GroupDetailsObject.ScheduleDay = DayComboBox.SelectedIndex + 1;
                     GroupDetailsObject.ScheduleInterval = Convert.ToInt16(IntervalTextBox.Text);
                     GroupDetailsObject.ScheduleTime = DateTime.Parse(HourTextBox.Text + ":" + MinuteTextBox.Text);
                     GroupTuppleObject = new Tuple<GroupDetails, TaskCollection>(GroupDetailsObject, TaskCollectionObject);
                     Program.GroupCollectionObject.GroupWithoutTimerList[IndexOfGroupObject] = GroupTuppleObject;
                     TaskCollectionObject.SaveGroup(PathTextBox.Text);
                     Program.GroupCollectionObject.PerformSaveWithoutTimer(Program.GroupCollectionPath);
                     GroupButtonObject.Initialize(ref GroupDetailsObject);
                     GroupButtonObject.Invalidate();
                 } else {
                     GroupDetailsObject = new GroupDetails(GroupID, NameTextBox.Text, PathTextBox.Text, OccurrenceComboBox.SelectedItem.ToString().ToLower(),
                     DayComboBox.SelectedIndex + 1, Convert.ToInt16(IntervalTextBox.Text), DateTime.Parse(HourTextBox.Text + ":" + MinuteTextBox.Text),
                     EnabledComboBox.SelectedIndex == 0);
                     GroupTuppleObject = new Tuple<GroupDetails, TaskCollection>(GroupDetailsObject, TaskCollectionObject);
                     Program.GroupCollectionObject.GroupWithoutTimerList.Add(new Tuple<GroupDetails, TaskCollection>(GroupDetailsObject, TaskCollectionObject));
                     TaskCollectionObject.SaveGroup(PathTextBox.Text);
                     Program.GroupCollectionObject.PerformSaveWithoutTimer(Program.GroupCollectionPath);
                     Options.LastGroupID++;
                     Options.SaveOptions();
                     Program.MainFormObject.AddGroup(GroupTuppleObject);
                 }
                 GroupSaved = true;
                 Program.MainFormObject.SortGroups(Program.MainFormObject.SortByValue);
                 Close();
             } catch (Exception ex) {
                 MessageBox.Show("An unexpected error occurred while trying to save the group." + vbCrLf + "Exception Message : " + ex.Message, "Error On Group Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         } else MessageBox.Show("Group " + (GroupExisting ? "Saving" : "Creation") + " was canceled by the user.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
     } else MessageBox.Show("It seems like you did not provided valid data. Please verify that all the fields are filled.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }