Exemplo n.º 1
0
        public void TestInitialise()
        {
            _ClassFactorySnapshot = Factory.TakeSnapshot();

            _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>();
            _WebServer        = new Mock <IWebServer>()
            {
                DefaultValue = DefaultValue.Mock
            }.SetupAllProperties();
            _LogDatabase = new Mock <ILogDatabase>()
            {
                DefaultValue = DefaultValue.Mock
            }.SetupAllProperties();
            _LogSession = new Mock <LogSession>()
            {
                DefaultValue = DefaultValue.Mock
            }.SetupAllProperties();
            _ExceptionCaughtEvent = new EventRecorder <EventArgs <Exception> >();

            _Clock = new ClockMock();
            Factory.Singleton.RegisterInstance <IClock>(_Clock.Object);

            _ConnectionLogger             = Factory.Singleton.Resolve <IConnectionLogger>();
            _ConnectionLogger.WebServer   = _WebServer.Object;
            _ConnectionLogger.LogDatabase = _LogDatabase.Object;
        }
Exemplo n.º 2
0
        public void ConnectionLogger_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            _ConnectionLogger = Factory.Singleton.ResolveNewInstance <IConnectionLogger>();

            TestUtilities.TestProperty(_ConnectionLogger, "LogDatabase", null, _LogDatabase.Object);
            TestUtilities.TestProperty(_ConnectionLogger, "WebServer", null, _WebServer.Object);
        }
Exemplo n.º 3
0
 public WebSocketClient(
     IClientListener clientListener,
     string address,
     IConnectionLogger clientLogger = null)
 {
     _clientListener = clientListener;
     _clientAddress  = address; // the server address the connection will be connecting to.
     _clientLogger   = clientLogger;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Создание внешнего серевера на основе TCP-соединения
        /// </summary>
        /// <param name="client">TCP-соединение</param>
        public Connection(TcpClient client, IConnectionLogger gameLogger, bool usePing = false)
            : base(client, gameLogger)
        {
            if (usePing)
            {
                _timer = new Timer(SendPing, null, 30000, 30000);
            }

            WaitForOutMessages();
        }
Exemplo n.º 5
0
 public SocketPipeReader(
     IConnectionLogger logger,
     InlineSocketsOptions options,
     IConnection connection,
     INetworkSocket socket)
 {
     _logger     = logger;
     _connection = connection;
     _socket     = socket;
     _buffer     = new RollingMemory(options.MemoryPool);
 }
Exemplo n.º 6
0
        public SocketPipeWriter(
            IConnectionLogger logger,
            InlineSocketsOptions options,
            IConnection connection,
            INetworkSocket socket)
        {
            _logger = logger;
#if NETSTANDARD2_0
            _connection = connection;
#endif
            _socket = socket;
            _buffer = new RollingMemory(options.MemoryPool);
        }
Exemplo n.º 7
0
        public InlineSocketsOptionsDefaults(
            IListenerLogger listenerLogger,
            IConnectionLogger connectionLogger,
            INetworkProvider networkProvider)
        {
            _configure = options =>
            {
#if NETSTANDARD2_0
                var memoryPool = Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.KestrelMemoryPool.Create();
#else
                var socketTransportOptions         = new Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions();
                var socketTransportOptionsTypeInfo = socketTransportOptions.GetType().GetTypeInfo();
                var memoryPoolFactoryProperty      = socketTransportOptionsTypeInfo.GetDeclaredProperty("MemoryPoolFactory");
                var memoryPoolFactory = memoryPoolFactoryProperty.GetValue(socketTransportOptions) as Func <MemoryPool <byte> >;
                var memoryPool        = memoryPoolFactory.Invoke();
#endif

                options.MemoryPool             = memoryPool;
                options.CreateListener         = CreateListener;
                options.CreateConnection       = CreateConnection;
                options.CreateSocketPipelines  = CreateSocketPipelines;
                options.WrapTransportPipelines = WrapTransportPipelines;

                Listener CreateListener()
                {
                    return(new Listener(listenerLogger, options, networkProvider));
                }

                IConnection CreateConnection(INetworkSocket socket)
                {
                    return(new Connection(connectionLogger, options, socket));
                }

                (PipeReader input, PipeWriter output) CreateSocketPipelines(IConnection connection, INetworkSocket socket)
                {
                    var input  = new SocketPipeReader(connectionLogger, options, connection, socket);
                    var output = new SocketPipeWriter(connectionLogger, options, connection, socket);

                    return(input, output);
                }

                static IDuplexPipe WrapTransportPipelines(IConnection connection, IDuplexPipe transport)
                {
                    var input = new CancelNotificationPipeReader(transport.Input, connection.CancelPendingRead);

                    return(new DuplexPipe(input, transport.Output));
                }
            };
        }
Exemplo n.º 8
0
        public Connection(
            IConnectionLogger logger,
            InlineSocketsOptions options,
            INetworkSocket socket)
        {
            Features       = new FeatureCollection(this);
            _logger        = logger;
            _options       = options;
            _socket        = socket;
            RemoteEndPoint = _socket.RemoteEndPoint;
            LocalEndPoint  = _socket.LocalEndPoint;

            (_socketInput, _socketOutput) = options.CreateSocketPipelines(this, socket);

            _connectionClosedTokenSource = new CancellationTokenSource();
            _connectionClosedTokenSource.Token.Register(() => _logger.LogTrace("TODO: ConnectionClosed"));
        }
        public void TestInitialise()
        {
            _ClassFactorySnapshot = Factory.TakeSnapshot();

            _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>();
            _WebServer = new Mock<IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _LogDatabase = new Mock<ILogDatabase>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _LogSession = new Mock<LogSession>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _ExceptionCaughtEvent = new EventRecorder<EventArgs<Exception>>();

            _ConnectionLogger = Factory.Singleton.Resolve<IConnectionLogger>();
            _ConnectionLogger.WebServer = _WebServer.Object;
            _ConnectionLogger.LogDatabase = _LogDatabase.Object;

            _Provider = new Mock<IConnectionLoggerProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _ConnectionLogger.Provider = _Provider.Object;
        }
Exemplo n.º 10
0
        public void TestInitialise()
        {
            _ClassFactorySnapshot = Factory.TakeSnapshot();

            _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>();
            _WebServer        = new Mock <IWebServer>()
            {
                DefaultValue = DefaultValue.Mock
            }.SetupAllProperties();
            _LogDatabase = new Mock <ILogDatabase>()
            {
                DefaultValue = DefaultValue.Mock
            }.SetupAllProperties();
            _LogSession = new Mock <LogSession>()
            {
                DefaultValue = DefaultValue.Mock
            }.SetupAllProperties();
            _ExceptionCaughtEvent = new EventRecorder <EventArgs <Exception> >();

            _Clock = new ClockMock();
            Factory.Singleton.RegisterInstance <IClock>(_Clock.Object);

            _NestedTransactionCount = 0;
            _LogDatabase.Setup(r => r.PerformInTransaction(It.IsAny <Func <bool> >())).Callback((Func <bool> r) => {
                if (++_NestedTransactionCount > 1)
                {
                    throw new InvalidOperationException("Nested transactions are not allowed");
                }
                r();
                --_NestedTransactionCount;
            });

            _ConnectionLogger             = Factory.Singleton.ResolveNewInstance <IConnectionLogger>();
            _ConnectionLogger.WebServer   = _WebServer.Object;
            _ConnectionLogger.LogDatabase = _LogDatabase.Object;
        }
Exemplo n.º 11
0
 public static IClient CreateClient(IClientListener clientListener, string address, IConnectionLogger clientLogger = null)
 {
     return(new WebSocketClient(clientListener, address, clientLogger));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Создание внешнего серевера на основе TCP-соединения
 /// </summary>
 /// <param name="client">TCP-соединение</param>
 internal TcpReadConnection(TcpClient client, IConnectionLogger gameLogger)
 {
     _tcpClient = client;
     _logger    = gameLogger;
 }
        public void ConnectionLogger_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            _ConnectionLogger = Factory.Singleton.Resolve<IConnectionLogger>();
            Assert.IsNotNull(_ConnectionLogger.Provider);

            TestUtilities.TestProperty(_ConnectionLogger, "Provider", _ConnectionLogger.Provider, _Provider.Object);
            TestUtilities.TestProperty(_ConnectionLogger, "LogDatabase", null, _LogDatabase.Object);
            TestUtilities.TestProperty(_ConnectionLogger, "WebServer", null, _WebServer.Object);
        }