Exemplo n.º 1
0
 private Microsoft.Win32.TaskScheduler.Action GetAction(Schedule schedule)
 {
     if (schedule.ScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.BackupDatabase)
     {
         Microsoft.Win32.TaskScheduler.ExecAction action = new Microsoft.Win32.TaskScheduler.ExecAction();
         ScheduleTypes.BackupDatabase             b      = schedule.ScheduleType as ScheduleTypes.BackupDatabase;
         action.Path             = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "BackupDatabase.exe");
         action.WorkingDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
         action.Arguments        = string.Format("\"BackupPath={0}\" \"BackupName={1}\" \"SetNameType={2}\"", b.SaveTo, b.FileName, (int)b.SetNameType);
         return(action);
     }
     else if (schedule.ScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.ExecuteProgram)
     {
         Microsoft.Win32.TaskScheduler.ExecAction action = new Microsoft.Win32.TaskScheduler.ExecAction();
         ScheduleTypes.ExecuteProgram             e      = schedule.ScheduleType as ScheduleTypes.ExecuteProgram;
         action.Path             = e.FilePath;
         action.WorkingDirectory = System.IO.Path.GetDirectoryName(e.FilePath);
         action.Arguments        = e.Parameter;
         return(action);
     }
     else if (schedule.ScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.ShowMessage)
     {
         Microsoft.Win32.TaskScheduler.ExecAction action = new Microsoft.Win32.TaskScheduler.ExecAction();
         ScheduleTypes.ShowMessage s = schedule.ScheduleType as ScheduleTypes.ShowMessage;
         action.Path             = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "ShowMessage.exe");
         action.WorkingDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
         action.Arguments        = string.Format("\"MessageTitle={0}\" \"MessageBody={1}\"", s.MessageTitle, s.MessageBody);
         return(action);
     }
     throw new Exception();
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine($"*.exe http://google.com - POST to http://google.com");
                Console.WriteLine($"*.exe PARAM add - Add current exe to Task to Scheduler with PARAM");
            }
            try
            {
                if ((args != null) && (args.Length == 2))
                {
                    var action = new Microsoft.Win32.TaskScheduler.ExecAction(Assembly.GetExecutingAssembly().Location);
                    action.Arguments = args[0];
                    var trigger = Microsoft.Win32.TaskScheduler.Trigger.CreateTrigger(Microsoft.Win32.TaskScheduler.TaskTriggerType.Daily);
                    trigger.StartBoundary = DateTime.Now.Date;
                    trigger.Repetition.Duration = TimeSpan.FromMinutes(0);
                    trigger.Repetition.Interval = TimeSpan.FromMinutes(1);
                    Microsoft.Win32.TaskScheduler.TaskService.Instance.AddTask("Process", trigger, action);
                    return;
                }
                if ((args != null) && (args.Length == 1))
                {
                    using (var wc = new WebClient())
                    {
                        var s = wc.DownloadString(args[0]);
                    }
                }
            }
            catch(Exception exc)
            {

            }
        }
Exemplo n.º 3
0
 public void TaskShedulerWrapper_Dev2Action_Construct()
 {
     using ( Microsoft.Win32.TaskScheduler.Action act = new Microsoft.Win32.TaskScheduler.ExecAction("bob","dave","jane"))
     {
         Dev2Action wrapped = new Dev2Action(act);
         wrapped.Id = Guid.NewGuid().ToString();
         Assert.AreEqual(act.ActionType, wrapped.ActionType);
         Assert.AreEqual(act.Id, wrapped.Id);
         Assert.AreEqual(act, wrapped.Instance);
     }
 }
Exemplo n.º 4
0
 public void TaskShedulerWrapper_Dev2Action_Construct()
 {
     using (Microsoft.Win32.TaskScheduler.Action act = new Microsoft.Win32.TaskScheduler.ExecAction("bob", "dave", "jane"))
     {
         Dev2Action wrapped = new Dev2Action(act);
         wrapped.Id = Guid.NewGuid().ToString();
         Assert.AreEqual(act.ActionType, wrapped.ActionType);
         Assert.AreEqual(act.Id, wrapped.Id);
         Assert.AreEqual(act, wrapped.Instance);
     }
 }