Example #1
0
        private async void InitializeDriver()
        {
            var driver = await _runtimeModeDriversService
                         .GetDriverById(Guid.Parse(this.DeviceMomento.State.RelatedDriverId));

            _applicationSettingsService.Load();
            DriverMomento = driver.CreateMomento();
            InitFormatters();
            _tcpDeviceConnection = _applicationConnectionService.CreateTcpDeviceConnection(
                DriverMomento.State.GetTcpAddress(), DriverMomento.State.GetTcpPort(),
                _applicationSettingsService.QueryTimeoutPeriod * 1000);
            _tcpDeviceConnection.ConnectionRestoredAction += async() =>
            {
                try
                {
                    _isOnline = true;
                    if (_isConnectionWasOnline)
                    {
                        _connectionLogger.ConnectionResroted(_logger);
                    }
                    _isConnectionWasOnline = true;
                }
                catch
                {
                }
            };

            _tcpDeviceConnection.ConnectionLostAction += () =>
            {
                if (_isOnline)
                {
                    _isDeviceInitialized = false;
                    _connectionLogger.ConnectionLost(_logger);
                    _isOnline = false;
                }
            };
        }