//private static Stream ImageToPNGStream(Image image)
        //{
        //    Stream stream = new System.IO.MemoryStream();
        //    image.Save(stream, ImageFormat.Png);
        //    stream.Position = 0;
        //    return stream;
        //}
        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 ConnectionAsync(this, "TVHclient4Emby-" + version.ToString(), "" + Message.HTSP_VERSION, _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);
                }
            }
        }
 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();
 }