public Task OnServerStarted(IDiResolveReleaseOnlyContainer di) { _consoleBasedListener = new Thread(() => { Thread.CurrentThread.IsBackground = true; LogAsReply("listening started"); while (!_shouldQuit) { var rawCmd = _receiveCommand(); LogAsReply("received raw command"); try { var decoded = _codec.Decode <CommandRequest>(rawCmd); LogAsReply($"successfully decoded command requestId={decoded.Id} type={decoded.Type}"); switch (decoded.Type) { case RequestType.StopServer: _shouldQuit = true; break; default: throw new Exception("unsupported RequestType"); } } catch (Exception ex) { LogAsReply($"could not decode command because of {ex}"); } } }); _consoleBasedListener.Start(); Send(CommandReplyUtil.CreateServerStarted()); SendFilterInvocation(new FilterInvocation { InvType = FilterInvocationType.ServerStarted }); return(Task.CompletedTask); }
public void LogAsReply(string txt) { _sendReply( _codec.Encode( CommandReplyUtil.CreateLog(txt))); }