Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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());
            }
        }
Ejemplo n.º 3
0
 public void RemoveTask(int taskId)
 {
     TaskLib.Task task = _Tasks.FirstOrDefault(t => t.TaskId == taskId);
     Log.InfoAsync($"remove task({task}).");
     _Tasks.Remove(task);
     task.Dispose();
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public string GetTaskCmdCommand(TaskLib.Task task) =>
 CmdCommandText.Replace(CmdArgs.TaskNameReplacer, $"{task.Name}");
Ejemplo n.º 7
0
 void OnUpdateMessage(TaskLib.Task task)
 {
     RemoveTask(task.TaskId);
     AddTasksToWatch(task);
 }