Add files

This commit is contained in:
Arti Zirk 2017-05-24 15:33:09 +03:00
parent 0f659cd5e0
commit dc150f1363
4 changed files with 104 additions and 3 deletions

View File

@ -1,12 +1,46 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using CommandLine;
using CommandLine.Text;
namespace TaskRunner 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());
}
} }
} }
} }

27
TaskRunner/ServerAPI.cs Normal file
View File

@ -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<string> GetTask()
{
var resp = await client.GetStringAsync("get");
return resp;
}
}
}

36
TaskRunner/TaskManager.cs Normal file
View File

@ -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<bool>();
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;
}
}
}

View File

@ -5,4 +5,8 @@
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="1.9.71" />
</ItemGroup>
</Project> </Project>