public async Task SendMessageAsync(OperationResultContext context)
 {
     var token = CancellationToken.None;
     var type = WebSocketMessageType.Text;
     var message = context.CreateJson().ToUtf8Bytes();
     var buffer = new ArraySegment<byte>(message);
     await _webSocket.SendAsync(buffer, type, true, token);
 }
 private async Task PostStatus(OperationResultContext resultContext)
 {
     HttpRequestMessage request = new HttpRequestMessage();
     HttpMethod httpMethod = HttpMethod.Get;
     UriBuilder requestUri = new UriBuilder(_settings.ApiBaseHostAddress);
     requestUri.Path = "api/Task/Completed";
     request.Method = HttpMethod.Post;
     request.RequestUri = requestUri.Uri;
     request.Content = new StringContent(JsonConvert.SerializeObject(resultContext), Encoding.UTF8, "application/json");
     using (var client = new HttpClient())
     {
         await client.SendAsync(request, CancellationToken.None);
     }
 }
        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);
        }