diff --git a/src/cli/Commands/Builder.cs b/src/cli/Commands/Builder.cs deleted file mode 100644 index 319ddc73..00000000 --- a/src/cli/Commands/Builder.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.IO; -using Yavsc.Server.Models.IT; -using Yavsc.Server.Models.IT.SourceCode; - -public class Builder -{ - readonly string _gitRepository; - private readonly Project _projectInfo; - - public Builder() - { - - } - - - public void Clone() - { - var di = new DirectoryInfo(_gitRepository); - if (!di.Exists) di.Create(); - - var clone = new GitClone(_gitRepository); - clone.Launch(_projectInfo); - } - -} diff --git a/src/cli/Commands/Streamer.cs b/src/cli/Commands/Streamer.cs index 5a7b4136..75eddca6 100644 --- a/src/cli/Commands/Streamer.cs +++ b/src/cli/Commands/Streamer.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Net.WebSockets; -using System.Security.Policy; using System.Threading; using System.Threading.Tasks; using System.Web; @@ -9,102 +8,10 @@ using cli.Model; using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Yavsc.Abstract; namespace cli { - - public class Streamer: ICommander { - private readonly ClientWebSocket _client; - private readonly ILogger _logger; - private readonly ConnectionSettings _cxSettings; - private readonly UserConnectionSettings _userCxSettings; - private CommandOption _fileOption; - private CommandArgument _flowIdArg; - private CancellationTokenSource _tokenSource; - - public Streamer(ILoggerFactory loggerFactory, - IOptions cxSettings, - IOptions userCxSettings - ) - { - _logger = loggerFactory.CreateLogger(); - _cxSettings = cxSettings.Value; - _userCxSettings = userCxSettings.Value; - _client = new ClientWebSocket(); - _client.Options.SetRequestHeader("Authorization", $"Bearer {_userCxSettings.AccessToken}"); - } - - public CommandLineApplication Integrate(CommandLineApplication rootApp) - { - CommandLineApplication streamCmd = rootApp.Command("stream", - (target) => - { - target.FullName = "Stream to server"; - target.Description = "Stream arbitrary binary data to your server channel"; - _fileOption = target.Option("-f | --file", "use given file as input stream", CommandOptionType.SingleValue); - _flowIdArg = target.Argument("flowId", "Remote Id for this channel", false); - target.HelpOption("-? | -h | --help"); - }); - streamCmd.OnExecute(async() => await DoExecute()); - return streamCmd; - } - - private async Task DoExecute() - { - - if (_fileOption.HasValue()){ - var fi = new FileInfo(_fileOption.Value()); - if (!fi.Exists) { - _logger.LogError("Input file doesn´t exist."); - return -2; - } - using (var stream = fi.OpenRead()) - { - _logger.LogInformation("DoExecute from given file"); - await DoStream(stream); - } - return 0; - } - else - { - using(var stream = Console.OpenStandardInput()) - { - _logger.LogInformation("DoExecute from standard input"); - await DoStream(stream); - } - return 0; - } - } - async Task DoStream (Stream stream) - { - - _tokenSource = new CancellationTokenSource(); - var url = _cxSettings.StreamingUrl+"/"+_flowIdArg.Value; - - _logger.LogInformation("Connecting to "+url); - await _client.ConnectAsync(new Uri(url), _tokenSource.Token); - _logger.LogInformation("Connected"); - const int bufLen = Yavsc.Constants.WebSocketsMaxBufLen; - byte [] buffer = new byte[bufLen]; - const int offset=0; - int read; - bool lastFrame; - - WebSocketMessageType pckType = WebSocketMessageType.Binary; - do - { - read = await stream.ReadAsync(buffer, offset, bufLen); - lastFrame = read < Yavsc.Constants.WebSocketsMaxBufLen; - ArraySegment segment = new ArraySegment(buffer, offset, read); - await _client.SendAsync(segment, pckType, lastFrame, _tokenSource.Token); - _logger.LogInformation($"sent {segment.Count} "); - } while (!lastFrame); - _logger.LogInformation($"Closing socket"); - await _client.CloseAsync(WebSocketCloseStatus.NormalClosure, "EOF", _tokenSource.Token); - } - } - public class NStreamer: ICommander { + public class Streamer: ICommander { private readonly ClientWebSocket _client; private readonly ILogger _logger; private readonly ConnectionSettings _cxSettings; @@ -113,7 +20,7 @@ namespace cli { private CommandArgument _destArg; private CancellationTokenSource _tokenSource; - public NStreamer(ILoggerFactory loggerFactory, + public Streamer(ILoggerFactory loggerFactory, IOptions cxSettings, IOptions userCxSettings ) diff --git a/src/cli/Program.cs b/src/cli/Program.cs index 1d34f595..7eee4080 100644 --- a/src/cli/Program.cs +++ b/src/cli/Program.cs @@ -118,11 +118,10 @@ namespace cli new SendMailCommandProvider().Integrate(cliapp); new GenerateJsonSchema().Integrate(cliapp); - (new AuthCommander(loggerFactory)).Integrate(cliapp); - (new CiBuildCommand()).Integrate(cliapp); - (new GenerationCommander()).Integrate(cliapp); - (new Streamer(loggerFactory, cxSettings, usercxSettings )).Integrate(cliapp); - new NStreamer(loggerFactory, cxSettings, usercxSettings ).Integrate(cliapp); + new AuthCommander(loggerFactory).Integrate(cliapp); + new CiBuildCommand().Integrate(cliapp); + new GenerationCommander().Integrate(cliapp); + new Streamer(loggerFactory, cxSettings, usercxSettings ).Integrate(cliapp); if (args.Length == 0) {