Hi everyone,
I've a client/server application that will interface with a backup program (Cobian).
On the server I have a listbox where are written name and IP address of the client connected to it.
Double-clicking on the client present in the listbox I get a window where I can select the days and time in which I want the backups are made.
Days and time are are saved in a text file with this syntax: MON TUE ;11
Question :
Through a task scheduler I need to start the program Cobian only on the days and time taken from the text file.
Can you help me?
[Edit]
Let me explain, in this moment I have this code:
using System;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32.TaskScheduler;
string[] Paths = Directory.GetFiles(Environment.CurrentDirectory, "*.ini");
foreach (string path in Paths)
{
StreamReader sr = new StreamReader(path);
string[] name_pc = sr.ReadLine().Split(':');
string[] ip = sr.ReadLine().Split(':');
string[] temp = sr.ReadLine().Split(';');
string[] hour = temp[temp.Length-1].Split(':');
string[] days= temp[0].Substring(0, temp[0].Length - 1).Split(' ');
}
TaskService ts = new TaskService();
TaskDefinition td = ts.NewTask();
td.Triggers.Add(new WeeklyTrigger(DaysOfTheWeek.AllDays, 2));
I would like to have something that would give me the possibility to insert in place of DaysOfTheWeek.AllDays something like days[0].ToString().
Do you understand?
[/Edit]
At the end I chose this way:
string[] Paths = Directory.GetFiles(Environment.CurrentDirectory, "*.ini");
foreach (string path in Paths)
{
StreamReader sr = new StreamReader(path);
string[] nome_pc = sr.ReadLine().Split(':');
string[] ip = sr.ReadLine().Split(':');
string[] temp = sr.ReadLine().Split(';');
string[] ore = temp[temp.Length - 1].Split(':');
string[] giorni = temp[0].Substring(0, temp[0].Length - 1).Split(' ');
string[] days = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
TaskScheduler.TriggerItem triggerItem = new TaskScheduler.TriggerItem();
triggerItem.Tag = nome_pc[1].ToString() + ";" + ip[1].ToString();
triggerItem.StartDate = DateTime.Today;
triggerItem.EndDate = DateTime.Today.AddYears(80);
triggerItem.TriggerTime = Convert.ToDateTime(ore[0].ToString() + ":00:00");
for (byte day = 0; day < 7; day++)
{
if (Array.IndexOf(giorni, days[day]) != -1)
{
triggerItem.TriggerSettings.Weekly.DaysOfWeek[day] = true;
}
}
triggerItem.Enabled = true;
_taskScheduler.AddTrigger(triggerItem);
_taskScheduler.Enabled = true;
Send_To(ip[1].ToString(), "ESEGUI");
sr.Dispose();
sr.Close();
My code is based on this
TaskScheduler[
^]