private void createHTSConnection()
 {
     _logger.Info("[TVHclient] LiveTvService.createHTSConnection()");
     Version version = Assembly.GetEntryAssembly().GetName().Version;
     _htsConnection = new HTSConnectionAsync(this, "TVHclient4Emby", version.ToString(), _logger);
     _connected = false;
 }
        public void onError(Exception ex)
        {
            _logger.ErrorException("[TVHclient] HTSConnectionHandler recorded a HTSP error: " + ex.Message, ex);
            _htsConnection.stop();
            _htsConnection = null;
            _connected = false;

            _liveTvService.sendDataSourceChanged();

            ensureConnection();

            throw ex;
        }
        private void ensureConnection()
        {
            _logger.Info("[TVHclient] HTSConnectionHandler.ensureConnection()");
            if (_htsConnection == null || _htsConnection.needsRestart())
            {
                _logger.Info("[TVHclient] HTSConnectionHandler.ensureConnection() : create new HTS-Connection");
                Version version = Assembly.GetEntryAssembly().GetName().Version;
                _htsConnection = new HTSConnectionAsync(this, "TVHclient4Emby", version.ToString(), _logger);
                _connected = false;
            }

            lock (_lock)
            {
                if (!_connected)
                {
                    _logger.Info("[TVHclient] HTSConnectionHandler.ensureConnection: Used connection parameters: " +
                        "TVH Server = '" + _tvhServerName + "'; " +
                        "HTTP Port = '" + _httpPort + "'; " +
                        "HTSP Port = '" + _htspPort + "'; " +
                        "User = '******'; " +
                        "Password set = '" + (_password.Length > 0) + "'");

                    _htsConnection.open(_tvhServerName, _htspPort);
                    _connected = _htsConnection.authenticate(_userName, _password);

                    _logger.Info("[TVHclient] HTSConnectionHandler.ensureConnection: connection established " + _connected);
                }
            }
        }