public override void ResponseReceived(byte[] parameter) { if (parameter == null || parameter.Length == 0) { return; } switch ((ConsoleCommunication)parameter[0]) { case ConsoleCommunication.ResponseNewLine: var line = Encoding.UTF8.GetString(parameter, 1, parameter.Length - 1); CurrentOutput.AppendLine(line); ConsoleLineReceived?.Invoke(this, line); break; case ConsoleCommunication.ResponseConsoleOpen: IsEnabled = true; Started?.Invoke(this, EventArgs.Empty); break; case ConsoleCommunication.ResponseConsoleClosed: IsEnabled = false; Stopped?.Invoke(this, EventArgs.Empty); break; default: throw new ArgumentOutOfRangeException(); } }
public override async void ResponseReceived(byte[] parameter) { if (parameter == null || parameter.Length == 0) { LogService.Error((string)Application.Current.Resources["ConsoleErrorEmptyResponse"]); return; } switch ((ConsoleCommunication)parameter[0]) { case ConsoleCommunication.ResponseNewLine: await Application.Current.Dispatcher.BeginInvoke( new Action( () => ConsoleLineReceived?.Invoke(this, Encoding.UTF8.GetString(parameter, 1, parameter.Length - 1)))); break; case ConsoleCommunication.ResponseConsoleOpen: LogService.Receive((string)Application.Current.Resources["ConsoleStarted"]); await Application.Current.Dispatcher.BeginInvoke(new Action(() => { IsEnabled = true; Started?.Invoke(this, EventArgs.Empty); })); break; case ConsoleCommunication.ResponseConsoleClosed: LogService.Receive((string)Application.Current.Resources["ConsoleClosed"]); await Application.Current.Dispatcher.BeginInvoke(new Action(() => { IsEnabled = false; Stopped?.Invoke(this, EventArgs.Empty); })); break; default: throw new ArgumentOutOfRangeException(); } }