public static void InvokeTaskComand(IOptions opts, TaskLib.Task task) { //foreach(TaskLib.Task task in tasks) { Console.WriteLine($"start executing task({task.Name}) command({opts.CmdCommandText})"); string command = opts.CmdCommandText.Replace(CmdArgs.TaskNameReplacer, $"{task.Name}"); Process process = new Process(); process.StartInfo = new ProcessStartInfo("cmd", @"/c " + command); process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.Start(); void streamShow(System.IO.StreamReader streamReader) { if (streamReader.ReadToEnd() is string streamData && !string.IsNullOrEmpty(streamData)) { Console.WriteLine(streamData); } } streamShow(process.StandardOutput); streamShow(process.StandardError); } }
public void InvokeTaskComand(TaskLib.Task task) { try { string command = _Opts.GetTaskCmdCommand(task); //System.Threading.Tasks.Task.Factory.StartNew(() => Console.WriteLine($"{DateTime.Now} Start executing task:'{task.Name}' command:'{command}'")); Log.InfoAsync($"Start executing task:'{task.Name}' command:'{command}'"); //_Opts.CmdCommandText.Replace(CmdArgs.TaskNameReplacer, $"{task.Name}"); Process process = new Process(); process.StartInfo = new ProcessStartInfo("cmd", @"/c " + command); process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.Start(); void streamShow(System.IO.StreamReader streamReader) { if (streamReader.ReadToEnd() is string streamData && !string.IsNullOrEmpty(streamData)) { Log.InfoAsync(streamData); } } streamShow(process.StandardOutput); streamShow(process.StandardError); } catch (Exception ex) { Log.ErrorAsync(ex.GetMessages()); } }
public void RemoveTask(int taskId) { TaskLib.Task task = _Tasks.FirstOrDefault(t => t.TaskId == taskId); Log.InfoAsync($"remove task({task})."); _Tasks.Remove(task); task.Dispose(); }
public override void Process() { base.Process(); TaskLib.Task task = new TaskLib.Task() { Name = _Opts.TaskName, CreatedDT = DateTime.Now, RemindPeriod = _Opts.PeriodObj, TargetDT = _Opts.DateTimeObj }; WatchTasks(task); }
public bool AddTaskToWatch(TaskLib.Task task) { _Tasks.Add(task); if (task.IsComplited == true) { return(false); } Log.InfoAsync($"Start observe {task}"); task.OnTaskTime += (s, e) => InvokeTaskComand((TaskLib.Task)s); task.StartObserve(); return(true); }
public string GetTaskCmdCommand(TaskLib.Task task) => CmdCommandText.Replace(CmdArgs.TaskNameReplacer, $"{task.Name}");
void OnUpdateMessage(TaskLib.Task task) { RemoveTask(task.TaskId); AddTasksToWatch(task); }