private IEnumerable <byte> CommandHandler(IEnumerable <byte> received) { SafeExecution.TryCatch(() => CommandHandlerInternal(received), exception => _recorder.DefaultException(this, exception)); return(Enumerable.Empty <byte>()); }
public void DisplayDebugMessage(string message) { if (_isShowDebugMessage) { SafeExecution.TryCatchAsync(() => DisplayDebugMessageInternal(message), exception => _systemInterrupter.InterruptWithMessage(exception.Message)); } }
private void RecordReceivedHandler(string value) { if (Activated) { SafeExecution.TryCatch(() => TrySendText(value), exception => _recorder.DefaultException(this, exception)); } }
private void ConnectedHandler(string address) { SafeExecution.TryCatch(() => { _remoteTraceMonitorСonsistent.SetPrompt(address); _remoteTraceMonitorСonsistent.ClearTextBox(); }, exception => _recorder.DefaultException(this, exception)); }
private async Task OpenInternal() { _isOpened = true; _recorder.RecordInfo(nameof(NetworkPoint), $"NetworkPoint opened {(_sListener.LocalEndPoint).Address}:{(_sListener.LocalEndPoint).Port}"); while (_isOpened) { _sListener.Listen(10); ISocket socket = await _sListener.AcceptAsync(); SafeExecution.TryCatch(() => ConnectionAcceptedHandler(socket), ExceptionHandler); } }
public void TryCatchWithResultAsync_OnException_ShouldCatch() { var wasCatched = false; async Task <bool> TestMethod() { throw new Exception("test exception"); } var task = SafeExecution.TryCatchWithResultAsync(() => TestMethod(), exception => wasCatched = true); Assert.True(wasCatched); Assert.False(task.Result); }
public void TryCatchWithResultAsync_OnException_ShouldReturnDefault() { var wasCatched = false; async Task <int> TestMethod() { throw new Exception("test exception"); } var task = SafeExecution.TryCatchWithResultAsync(() => TestMethod(), exception => wasCatched = true, 6); Assert.True(wasCatched); Assert.Equal(6, task.Result); }
public void TryCatchWithResult_OnSuccess_ShouldReturnResult() { var wasCatched = false; bool TestMethod() { return(true); } var result = SafeExecution.TryCatchWithResult(TestMethod, exception => wasCatched = true); Assert.False(wasCatched); Assert.True(result); }
public void TryCatchWithResultAsync_OnSuccess_ShouldReturnResult() { var wasCatched = false; async Task <bool> TestMethod() { return(true); } var task = SafeExecution.TryCatchWithResultAsync(() => TestMethod(), exception => wasCatched = true); Assert.False(wasCatched); Assert.True(task.Result); }
private bool TryConnectInternal(INetworkAddress networkAddress, out INetworkTunnel networkTunnel) { var socket = _socketFactory.Invoke(networkAddress.IP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); var isFail = false; networkTunnel = default; SafeExecution.TryCatch( () => socket.Connect(networkAddress.IP, networkAddress.Port), e => { SafeExecution.TryCatch(() => socket.Dispose(), e => ExceptionHandler(e)); isFail = true; }); if (!isFail) { networkTunnel = _networkTunnelFactory.Invoke(socket); } return(!isFail); }
private void ReceivedHandler(byte[] receivedBytes) { SafeExecution.TryCatch(() => ReceivedHandlerInternal(receivedBytes), ExceptionHandler); }
public void RegisterCommand(string name, Action handler, string description = "") { SafeExecution.TryCatch(() => _remoteApiMap.RegisterCommand(name, handler, description), exception => _recorder.DefaultException(this, exception)); }
public void Response(IEnumerable <byte> data) { SafeExecution.TryCatch(() => ResponseInternal(data), ExceptionHandler); }
public void Send(IEnumerable <byte> data) { SafeExecution.TryCatch(() => SendInternal(data), ExceptionHandler); }
public void ActivateAndSendCache() { SafeExecution.TryCatch(() => ActivateAndSendCacheInternal(), exception => _recorder.DefaultException(this, exception)); }
public void RegisterCommandWithParameters(string name, Action <IEnumerable <string> > handler, string description = "") { SafeExecution.TryCatch(() => _remoteApiMap.RegisterCommandWithParameters(name, handler, description), exception => _recorder.DefaultException(this, exception)); }
private void Bind(IPAddress ipAddress, int port) { SafeExecution.TryCatch(() => _sListener.Bind(ipAddress, port), ExceptionHandler); }
private void StartProducing() { SafeExecution.TryCatchAsync(() => StartProducingInternal(), exception => _recorder.DefaultException(this, exception)); }
private void Open() { SafeExecution.TryCatchAsync(() => OpenInternal(), ExceptionHandler); }
public void Start() { SafeExecution.TryCatchAsync(() => StartInternal(), exception => _systemInterrupter.InterruptWithMessage(exception.Message)); }
public Task Listen() { return(SafeExecution.TryCatchAsync(() => Task.Run(ListenInternal), ExceptionHandler)); }
public void Send(byte[] data) { RecordSendInfo($"Tunnel.Send {data.Length}"); SafeExecution.TryCatch(() => _socket.Send(data), ExceptionHandler); }
public void SetPrompt(string value) { SafeExecution.TryCatchAsync(() => SetPromptInternal(value), exception => _systemInterrupter.InterruptWithMessage(exception.Message)); }
private void TextReceivedHandler(string value) { SafeExecution.TryCatch(() => _remoteTraceMonitorСonsistent.DisplayNextMessage(value), exception => _recorder.DefaultException(this, exception)); }
public void Start() { SafeExecution.TryCatch(() => _autoLocalConnector.Start(), exception => _recorder.DefaultException(this, exception)); }
private Task <bool> TextEnteredHandler(string value) { return(SafeExecution.TryCatchWithResultAsync(() => _autoLocalConnector.ExecuteCommand(value), exception => _recorder.DefaultException(this, exception)));; }
private void AcceptedHandler(INetworkTunnel tunnel) { SafeExecution.TryCatch(() => AcceptedHandlerInternal(tunnel), ExceptionHandler); }
public (bool, ISession) TryConnect(INetworkAddress networkAddress) { return(SafeExecution.TryCatchWithResult(() => TryConnectInternal(networkAddress), ExceptionHandler)); }
public void RegisterWrongCommandHandler(Action action) { SafeExecution.TryCatch(() => _remoteApiMap.RegisterWrongCommandHandler(action), exception => _recorder.DefaultException(this, exception)); }