From dc150f1363728cf0def54ee319730fdfcba85e6d Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Wed, 24 May 2017 15:33:09 +0300 Subject: [PATCH] Add files --- TaskRunner/Program.cs | 40 +++++++++++++++++++++++++++++++++--- TaskRunner/ServerAPI.cs | 27 ++++++++++++++++++++++++ TaskRunner/TaskManager.cs | 36 ++++++++++++++++++++++++++++++++ TaskRunner/TaskRunner.csproj | 4 ++++ 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 TaskRunner/ServerAPI.cs create mode 100644 TaskRunner/TaskManager.cs diff --git a/TaskRunner/Program.cs b/TaskRunner/Program.cs index 3a0d6c8..7aefd74 100644 --- a/TaskRunner/Program.cs +++ b/TaskRunner/Program.cs @@ -1,12 +1,46 @@ using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using CommandLine; +using CommandLine.Text; namespace TaskRunner { - class Program + public class Options { - static void Main(string[] args) + [Option("server", HelpText="Task source server", Required = true)] + public string server { get; set; } + + [HelpOption] + public string GetUsage() { - Console.WriteLine("Hello World!"); + return HelpText.AutoBuild(this, (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current)); + } + } + public class Program + { + public static void Main(string[] args) + { + MainAsync(args).Wait(); + } + + static async Task MainAsync(string[] args) + { + var options = new Options(); + if (Parser.Default.ParseArguments(args, options)) + { + Console.WriteLine($"Waiting for tasks from server: {options.server}"); + var server = new ServerApi(new Uri(options.server)); + var task = await server.GetTask(); + Console.WriteLine(task); + var taskManager = new TaskManager(); + await taskManager.RunFfmpeg(); + } else { + Console.WriteLine(options.GetUsage()); + } + } } } diff --git a/TaskRunner/ServerAPI.cs b/TaskRunner/ServerAPI.cs new file mode 100644 index 0000000..1084d42 --- /dev/null +++ b/TaskRunner/ServerAPI.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Net.Http; + + +namespace TaskRunner +{ + public class ServerApi + { + public Uri serverUri; + private readonly HttpClient client = new HttpClient(); + + public ServerApi(Uri serverUri) + { + this.serverUri = serverUri; + client.BaseAddress = serverUri; + } + + public async Task GetTask() + { + var resp = await client.GetStringAsync("get"); + return resp; + } + } +} diff --git a/TaskRunner/TaskManager.cs b/TaskRunner/TaskManager.cs new file mode 100644 index 0000000..a855ff5 --- /dev/null +++ b/TaskRunner/TaskManager.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; + +namespace TaskRunner +{ + public class TaskManager + { + public Task RunFfmpeg() + { + var task = new TaskCompletionSource(); + var process = new Process + { + StartInfo = + { + FileName = "ping", + Arguments = "google.com -t", + RedirectStandardOutput = true, + UseShellExecute = false + }, + EnableRaisingEvents = true + }; + process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data); + process.Start(); + process.BeginOutputReadLine(); + process.Exited += (sender, args) => + { + task.SetResult(true); + process.Dispose(); + }; + return task.Task; + } + } +} diff --git a/TaskRunner/TaskRunner.csproj b/TaskRunner/TaskRunner.csproj index ce1697a..ef6462a 100644 --- a/TaskRunner/TaskRunner.csproj +++ b/TaskRunner/TaskRunner.csproj @@ -5,4 +5,8 @@ netcoreapp2.0 + + + +