public async Task DoWork(MessageDefinitions message) { // Long running process; await Task.Delay(4000); var tobeCompiledPath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, @"..\..\ToBeCompiled"); var projectPath = $"{tobeCompiledPath}\\{message.Recipient.AssemblyName}"; Process process = new Process() { StartInfo = new ProcessStartInfo("cmd") { WorkingDirectory = projectPath, RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true } }; process.Start(); // only if the command preceding the symbol is successful process.StandardInput.WriteLine("dotnet build"); process.StandardInput.Flush(); string output = process.StandardOutput.ReadToEnd(); process.WaitForExit(); process.Dispose(); Console.WriteLine(output); var context = new OperationResultContext { ClientId = ClientId, Command = Commands.Build, CompletedDate = DateTime.Now, State = OperationResultState.Success, ResultInfo = output }; await PostStatus(context); }
public async Task Listen() { var token = CancellationToken.None; var buffer = new ArraySegment <byte>(new byte[_settings.MaxDataSize]); // Below will wait for a request message. var received = await _webSocket.ReceiveAsync(buffer, token); switch (received.MessageType) { case WebSocketMessageType.Text: MessageDefinitions command = GetMessage(buffer, token); Console.WriteLine( "Server pushed Command(s): " + string.Join(",", command.Commands) + "\t" + "to: " + command.Recipient.AssemblyName); if (!string.IsNullOrEmpty(command.Recipient.AssemblyName)) { await DoWork(command); } break; } }