예제 #1
0
        private void StartStream()
        {
            _log.Debug("Starting push mode...");

            _synchronizer.StartPeriodicDataRecording();
            _synchronizer.SyncAll();
            Task.Factory.StartNew(() => _pushManager.StartSse());
        }
예제 #2
0
        public void StartSse_WithPushEnabled_ShouldConnect()
        {
            // Arrange.
            var response = new AuthenticationResponse
            {
                PushEnabled = true,
                Channels    = "channel-test",
                Token       = "token-test",
                Retry       = false,
                Expiration  = 1
            };

            var response2 = new AuthenticationResponse
            {
                PushEnabled = true,
                Channels    = "channel-test-2",
                Token       = "token-test-2",
                Retry       = false,
                Expiration  = 1
            };

            _authApiClient
            .SetupSequence(mock => mock.AuthenticateAsync())
            .ReturnsAsync(response)
            .ReturnsAsync(response2);

            _sseHandler
            .Setup(mock => mock.Start(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(true);

            // Act.
            var result = _pushManager.StartSse();

            // Assert.
            Assert.IsTrue(result.Result);
            _authApiClient.Verify(mock => mock.AuthenticateAsync(), Times.Once);
            _sseHandler.Verify(mock => mock.Start(response.Token, response.Channels), Times.Once);

            Thread.Sleep(3000);
            _authApiClient.Verify(mock => mock.AuthenticateAsync(), Times.AtLeast(2));
            _sseHandler.Verify(mock => mock.Start(response2.Token, response2.Channels), Times.Once);
        }
예제 #3
0
        public void Start()
        {
            _tasksManager.Start(() =>
            {
                try
                {
                    while (!_synchronizer.SyncAll(_shutdownCancellationTokenSource, asynchronous: false))
                    {
                        _wrapperAdapter.TaskDelay(500).Wait();
                    }

                    _statusManager.SetReady();
                    _telemetrySyncTask.RecordConfigInit();
                    _synchronizer.StartPeriodicDataRecording();

                    if (_streamingEnabled)
                    {
                        _log.Debug("Starting streaming mode...");
                        var connected = _pushManager.StartSse().Result;

                        if (connected)
                        {
                            return;
                        }
                    }

                    _log.Debug("Starting polling mode ...");
                    _synchronizer.StartPeriodicFetching();
                    _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.SyncMode, (int)SyncModeEnum.Polling));
                }
                catch (Exception ex)
                {
                    _log.Debug("Exception initialization SDK.", ex);
                }
            }, _shutdownCancellationTokenSource, "SDK Initialization");
        }