/// <summary> /// Make the execution code. /// </summary> /// <param name="pContext">The context.</param> /// <returns> /// Empty if succed, an error message in case of failure. /// </returns> protected override string DoExecute(INetworkPoint pContext) { Server lServer = pContext as Server; if (lServer.Clients.ContainsKey(this.ClientView)) { var lPreviousClient = lServer.Clients.FirstOrDefault(pClient => pClient.Value.Id == this.ClientId); if (lPreviousClient.Value != null) { //lPreviousClient.Value.Status = Status.Declared; ClientView lRemoved; lServer.Clients.TryRemove(lPreviousClient.Key, out lRemoved); lServer.Clients[this.ClientView].Id = this.ClientId; lServer.Clients[this.ClientView].Status = Status.Declared; lServer.NotifyClientDeclared(this.ClientView, lPreviousClient.Value); } else { lServer.Clients[this.ClientView].Id = this.ClientId; lServer.Clients[this.ClientView].Status = Status.Declared; lServer.NotifyClientDeclared(this.ClientView, null); } } return(""); }
public void ConstructorCall_WithParameters_ShouldCreateSocket() { var socketFactory = ArrangeSocketFactory(); var networkTunnelFactory = ArrangeNetworkTunnelFactory(); var networkAddress = ArrangeNetworkAddress(IPAddress.Any, 20); _sut = CreateNetworkPoint(networkAddress, networkTunnelFactory, socketFactory, _recorder); Mock.Assert(() => socketFactory.Invoke(Arg.IsAny <AddressFamily>(), Arg.IsAny <SocketType>(), Arg.IsAny <ProtocolType>()), Occurs.Exactly(1)); }
public NodeGateway( INetworkPoint networkPoint, Func <INetworkTunnel, ISession> sessionFactory, IRecorder recorder) { _networkPoint = networkPoint; _sessionFactory = sessionFactory; _networkPoint.Accepted += AcceptedHandler; _recorder = recorder; }
public void ConstructorCall_WithParameters_ShouldBindSocket() { var socketMock = Mock.Create <ISocket>(); var socketFactory = ArrangeSocketFactory(socketMock); var networkTunnelFactory = ArrangeNetworkTunnelFactory(); var networkAddress = ArrangeNetworkAddress(IPAddress.Any, 20); _sut = CreateNetworkPoint(networkAddress, networkTunnelFactory, socketFactory, _recorder); Mock.Assert(() => socketMock.Bind(Arg.IsAny <IPAddress>(), Arg.AnyInt), Occurs.Exactly(1)); }
private void OnReceivedDataCommand(INetworkConnection connection, INetworkPoint networkPoint, IDataCommand dataCommand) { if (dataCommand is HeartbeatDataCommandRequest) { NetworkConnection.UpdateStatus(NetworkConnectionStatus.Connected, networkPoint); Heartbeat(false); } else if (dataCommand is HeartbeatDataCommandResponse) { NetworkConnection.UpdateStatus(NetworkConnectionStatus.Connected, networkPoint); } }
public async Task AcceptAsync_Throws_ShouldBeCaught() { var socketMock = Mock.Create <ISocket>(); Mock.Arrange(() => socketMock.AcceptAsync()).IgnoreArguments().Throws(new Exception("exception")); Mock.Arrange(() => socketMock.Close()).IgnoreArguments().Throws(new Exception("exception")); var socketFactory = ArrangeSocketFactory(socketMock, false); var networkTunnelFactory = ArrangeNetworkTunnelFactory(); var networkAddress = ArrangeNetworkAddress(IPAddress.Any, 20); _sut = CreateNetworkPoint(networkAddress, networkTunnelFactory, socketFactory, _recorder); Mock.Assert(() => _recorder.RecordError(Arg.AnyString, Arg.AnyString), Occurs.Exactly(1)); }
/// <summary> /// Executes this instance. /// </summary> /// <param name="pContext">The context.</param> public void Execute(INetworkPoint pContext) { try { this.Executing?.Invoke(this, null); string lErrorMessage = this.DoExecute(pContext); if (string.IsNullOrWhiteSpace(lErrorMessage) == false) { this.Failed?.Invoke(this, lErrorMessage); } else { this.Succeed?.Invoke(this, null); } } catch (Exception lException) { this.Failed?.Invoke(this, lException.ToString()); } }
/// <summary> /// Make the execution code. /// </summary> /// <param name="pContext">The context.</param> /// <returns>Empty if succed, an error message in case of failure.</returns> protected abstract string DoExecute(INetworkPoint pContext);
/// <summary> /// Make the execution code. /// </summary> /// <param name="pContext">The context.</param> /// <returns> /// Empty if succed, an error message in case of failure. /// </returns> protected override string DoExecute(INetworkPoint pContext) { return(""); }
/// <summary> /// Called when a command is sent on the server. /// </summary> /// <param name="pSender">The sender.</param> /// <param name="pCommand">The command.</param> private void OnCommandSent(INetworkPoint pSender, ANetworkCommand pCommand) { Console.WriteLine(@"Command sent " + pCommand.GetType().Name); this.mTimer.Start(); }