Exemplo n.º 1
0
        private void Prox_Ejec()
        {
            string         nombreApp = (Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).Replace("Config.exe", "");
            ScheduledTasks Tareas    = new ScheduledTasks();

            TaskScheduler.Task tarea = Tareas.OpenTask(nombreApp);
            if (chkInicioW.Checked && tarea != null)
            {
                string proxima = tarea.NextRunTime.ToString();
                label18.Visible  = true;
                label18.Text     = ("Proxima ejecucion: " + proxima);
                chkEdit.Visible  = true;
                TimePicker.Value = Convert.ToDateTime(proxima);
                tarea.Close();

                Dehab();
            }
            else
            {
                label18.Visible    = false;
                label18.Text       = "";
                chkEdit.Visible    = false;
                chkInicioW.Checked = false;
            }
            chkEdit.Checked = false;
            Tareas.Dispose();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add task to system
 /// </summary>
 /// <param name="task">Task to add</param>
 public override void AddTask(Task task)
 {
     base.AddTask(task);
     queue.Enqueue(task);
 }
Exemplo n.º 3
0
        private bool IniciarWindows()
        {
            string         nombreApp = (Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).Replace("Config.exe", "");
            ScheduledTasks Tareas    = new ScheduledTasks();

            string[] Existen = Tareas.GetTaskNames();
            short    hora    = Convert.ToInt16(TimePicker.Text.Substring(0, 2));
            short    min     = Convert.ToInt16(TimePicker.Text.Substring(3, 2));
            string   pass    = null;

            if (chkInicioW.Checked == true)
            {
                try
                {
                    //Referencia https://www.codeproject.com/Articles/2407/A-New-Task-Scheduler-Class-Library-for-NET

                    if (!Existen.Contains(nombreApp + ".job"))
                    {
                        TaskScheduler.Task tarea = Tareas.CreateTask(nombreApp);
                        tarea.ApplicationName = txtRutaRead.Text;
                        tarea.Comment         = "Tarea para ejecutar el ReadFiles diariamente";
                        tarea.SetAccountInformation(Environment.UserName, pass);
                        tarea.Creator  = Environment.UserName;
                        tarea.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
                        tarea.Triggers.Add(new DailyTrigger(hora, min));
                        tarea.Flags = TaskFlags.RunOnlyIfLoggedOn;
                        tarea.Save();
                        tarea.Close();
                    }
                    else if (chkEdit.Checked)
                    {
                        TaskScheduler.Task tarea = Tareas.OpenTask(nombreApp);
                        tarea.Triggers.RemoveAt(0);
                        tarea.Triggers.Add(new DailyTrigger(hora, min));
                        tarea.Save();
                        tarea.Close();
                    }
                    Tareas.Dispose();
                    Prox_Ejec();
                    txtPassWind.Text = "";
                    return(true);
                }
                catch (Exception e)
                {
                    Tareas.DeleteTask(nombreApp);
                    Tareas.Dispose();
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Prox_Ejec();
                    return(false);
                }
            }
            else
            {
                try
                {
                    Tareas.DeleteTask(nombreApp);
                    Tareas.Dispose();
                    Prox_Ejec();
                    return(true);
                }
                catch (Exception e)
                {
                    Prox_Ejec();
                    return(false);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Reset task enumeration. See <see cref="IEnumerator.Reset()"/> for more information.
 /// </summary>
 public void Reset()
 {
     curIndex = -1;
     curTask = null;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Moves to the next task. See <see cref="IEnumerator.MoveNext()"/> for more information.
 /// </summary>
 /// <returns>true if next task found, false if no more TaskNames.</returns>
 public bool MoveNext()
 {
     bool ok = ++curIndex < nameTask.Length;
     if (ok) curTask = outer.OpenTask(nameTask[curIndex]);
     return ok;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Complete task
 /// </summary>
 /// <param name="task">Task to complete</param>
 protected virtual void CompleteTask(Task task)
 {
     task.EndTime = time;
     TasksLeaved.Add(task);
     if (TaskCompleted != null) TaskCompleted(task, time);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Add task to system
 /// </summary>
 /// <param name="task">Task to add</param>
 public virtual void AddTask(Task task)
 {
     task.StartTime = time;
     TasksEntered.Add(task);
 }
Exemplo n.º 8
0
        private void buttonProceed_Click(object sender, EventArgs e)
        {
            // Clear all previous results
            listBox.Items.Clear();
            foreach (Series series in chart.Series)
                series.Points.Clear();

            List<DataPoint> points0 = new List<DataPoint>();
            List<DataPoint> points1 = new List<DataPoint>();

            // Start scheduler with different incoming task intensities
            for (int incomingInterval = (int)numericUpDownMaxIncomingInterval.Value; incomingInterval >= 1; incomingInterval--)
            {
                // Choose scheduler algorithm
                Scheduler scheduler;
                if (comboBox.SelectedItem == null) return;
                string algorithm = (string)comboBox.SelectedItem.ToString();
                if (algorithm == "FIFO") scheduler = new SchedulerFIFO();
                else if (algorithm == "RR") scheduler = new SchedulerRR();
                else if (algorithm == "LLQ") scheduler = new SchedulerLLQ();
                else return;

                // Regard only completed task or all tasks that entered
                List<Task> taskList = checkBoxRegardCompleted.Checked ? scheduler.TasksLeaved : scheduler.TasksEntered;

                // Add event to list box
                if (checkBoxMakeEventList.Checked && incomingInterval == (int)numericUpDownIntervalVariation.Value)
                    scheduler.TaskCompleted += new Scheduler.TaskCompletedEventHandler(delegate(Task task, int time)
                        {
                            listBox.Items.Add(time.ToString() + ":\tTask completed");
                        });

                // FORCE SCHEDULING
                Random random = new Random(DateTime.Now.Millisecond);
                int next = random.Next(1, incomingInterval);
                for (scheduler.Time = 0; scheduler.Time < numericUpDownTotalTime.Value; scheduler.Time++)
                    if (--next == 0)
                    {
                        Task task = new Task(random.Next(1, (int)numericUpDownMaxTaskWeight.Value), (int)numericUpDownPriorityCount.Value, (int)numericUpDownPriorityClasses.Value);
                        task.EndTime = (int)numericUpDownTotalTime.Value;
                        scheduler.AddTask(task);
                        next = random.Next(1, incomingInterval);
                        // Add event to list box
                        if (checkBoxMakeEventList.Checked && incomingInterval == (int)numericUpDownIntervalVariation.Value)
                            listBox.Items.Add(scheduler.Time.ToString() + "\tTask entered");
                    }

                // Add points to chart
                double intensity = (double)taskList.Count / (double)numericUpDownTotalTime.Value;
                points0.Add(new DataPoint(intensity, scheduler.IdleTime));
                points1.Add(new DataPoint(intensity, taskList.Average(new Func<Task, double>(delegate(Task task)
                    {
                        return task.IdleTime;
                    }))));

                // Draw variation
                if (incomingInterval == (int)numericUpDownIntervalVariation.Value)
                {
                    int MaxTaskIdle = taskList.Max<Task>(new Func<Task, int>(delegate(Task task)
                        {
                            return task.IdleTime;
                        }));
                    chart.ChartAreas[1].AxisX.Maximum = MaxTaskIdle + (int)numericUpDownVariationStep.Value - MaxTaskIdle % (int)numericUpDownVariationStep.Value;
                    for (int idle = 0; idle <= MaxTaskIdle; idle += (int)numericUpDownVariationStep.Value)
                        chart.Series[2].Points.AddXY(idle + (int)numericUpDownVariationStep.Value / 2, taskList.Count(new Func<Task, bool>(delegate(Task task)
                            {
                                return task.IdleTime >= idle && task.IdleTime < idle + (int)numericUpDownVariationStep.Value;
                            })));
                }
            }

            points0.Sort(new Comparison<DataPoint>(delegate(DataPoint p1, DataPoint p2)
                 {
                     return p1.XValue >= p2.XValue ? 1 : -1;
                 }));
            points1.Sort(new Comparison<DataPoint>(delegate(DataPoint p1, DataPoint p2)
            {
                return p1.XValue >= p2.XValue ? 1 : -1;
            }));
            foreach (DataPoint point in points0)
                chart.Series[0].Points.AddXY(point.XValue, point.YValues[0]);
            foreach (DataPoint point in points1)
                chart.Series[1].Points.AddXY(point.XValue, point.YValues[0]);
        }