コード例 #1
0
        public WebSocketClient(IWebSocketConfiguration configuration)
        {
            _configuration = configuration;
            var connectionType = configuration.IsSecureConnection ? "wss" : "ws";

            _url = new Uri($"{connectionType}://{configuration.WebSocketHost}:{configuration.WebSocketPort}/{configuration.UrlParameters}");
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the type
        /// </summary>
        /// <param name="dependencyService">A service that can be used to retrieve dependencies that were injected</param>
        /// <param name="loggerFactory">A factory that can be used to create loggers</param>
        /// <param name="metricFactory">A factory that can be used to create metrics</param>
        /// <param name="webSocketConfiguration">The configuration of the web socket</param>
        /// <param name="bufferPool">The buffer pool used to retreive arrays</param>
        public WebSocketHandler(IDependencyService dependencyService, IWebSocketConfiguration webSocketConfiguration, IMetricFactory metricFactory, ILoggerFactory loggerFactory, IBufferPool bufferPool)
        {
            Guard.NotNull(nameof(metricFactory), metricFactory);
            Guard.NotNull(nameof(loggerFactory), loggerFactory);
            Guard.NotNull(nameof(bufferPool), bufferPool);
            Guard.NotNull(nameof(webSocketConfiguration), webSocketConfiguration);

            WebSocketConfiguration = webSocketConfiguration;
            BufferPool             = bufferPool;
            SessionId     = Guid.NewGuid();
            MetricFactory = metricFactory;
            Logger        = loggerFactory.CreateLogger($"Session Handler: {SessionId:N}");

            DependencyService = dependencyService;

            _errorCounter        = metricFactory.CreateCounter("WebSocket error counter", "Tracks the number of errors that have occurred since the start of the service", false, new string[0]);
            _serviceSessionGauge = metricFactory.CreateGauge("WebSocket sessions in progress", "Tracks the number of sessions underway", false, new string[0]);
            _sessionTimes        = metricFactory.CreateSummary("WebSocket session iteration times", "Tracks the time taken to execute an iteration in the session", 10, false, new string[0]);
            _receiveTimes        = metricFactory.CreateSummary("WebSocket message receive time", "Tracks the time taken to receive a message", 10, false, new string[0]);
        }