コード例 #1
0
        public void SetNewHomeServer(string backendServerSystemId)
        {
            ServiceRegistration.Get <ILogger>().Info("ServerConnectionManager: Attaching to MediaPortal backend server '{0}'", backendServerSystemId);

            ServiceRegistration.Get <ILogger>().Debug("ServerConnectionManager: Stopping to watch for MediaPortal servers");
            lock (_syncObj)
                if (_serverWatcher != null)
                {
                    _serverWatcher.Stop();
                    _serverWatcher = null;
                }

            ServiceRegistration.Get <ILogger>().Debug("ServerConnectionManager: Building UPnP control point for communication with the new home server");
            UPnPClientControlPoint cp;

            lock (_syncObj)
                cp = _controlPoint;
            if (cp != null)
            {
                cp.Stop(); // Must be outside the lock - sends messages
            }
            lock (_syncObj)
            {
                ISettingsManager         settingsManager = ServiceRegistration.Get <ISettingsManager>();
                ServerConnectionSettings settings        = settingsManager.Load <ServerConnectionSettings>();
                // Here, we only set the system ID of the new home server. The server's system ID will remain in the settings
                // until method SetNewHomeServer is called again.
                settings.HomeServerSystemId = backendServerSystemId;
                settingsManager.Save(settings);
                _controlPoint = BuildClientControlPoint(backendServerSystemId);
            }
            _controlPoint.Start(); // Outside the lock
            ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerAttached);
        }
コード例 #2
0
        public void DetachFromHomeServer()
        {
            ISettingsManager         settingsManager = ServiceRegistration.Get <ISettingsManager>();
            ServerConnectionSettings settings        = settingsManager.Load <ServerConnectionSettings>();

            ServiceRegistration.Get <ILogger>().Info("ServerConnectionManager: Detaching from home server '{0}'", settings.HomeServerSystemId);

            UPnPServerControllerServiceProxy sc = ServerControllerServiceProxy;

            if (sc != null)
            {
                try
                {
                    sc.AttachedClientsChanged  -= OnAttachedClientsChanged;
                    sc.ConnectedClientsChanged -= OnConnectedClientsChanged;
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("ServerConnectionManager: Error detaching from home server '{0}'", e, HomeServerSystemId);
                }
            }

            ServiceRegistration.Get <ILogger>().Debug("ServerConnectionManager: Closing server connection");
            UPnPClientControlPoint cp;

            lock (_syncObj)
                cp = _controlPoint;
            if (cp != null)
            {
                cp.Stop(); // Must be outside the lock - sends messages
            }
            lock (_syncObj)
            {
                settings.HomeServerSystemId   = null;
                settings.LastHomeServerName   = null;
                settings.LastHomeServerSystem = null;
                settingsManager.Save(settings);
                _controlPoint = null;
            }
            ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDetached);

            ServiceRegistration.Get <ILogger>().Debug("ServerConnectionManager: Starting to watch for MediaPortal servers");
            if (_serverWatcher == null)
            {
                lock (_syncObj)
                    _serverWatcher = BuildServerWatcher();
                _serverWatcher.Start(); // Outside the lock
            }
        }
コード例 #3
0
        private void OnBackendServerConnected(DeviceConnection connection)
        {
            ServerDescriptor serverDescriptor = ServerDescriptor.GetMPBackendServerDescriptor(connection.RootDescriptor);

            if (serverDescriptor == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("ServerConnectionManager: Could not connect to home server - Unable to verify UPnP root descriptor");
                return;
            }
            SystemName preferredLink = serverDescriptor.GetPreferredLink();

            ServiceRegistration.Get <ILogger>().Info("ServerConnectionManager: Connected to home server '{0}' at host '{1}' (IP address: '{2}')", serverDescriptor.MPBackendServerUUID, preferredLink.HostName, preferredLink.Address);
            lock (_syncObj)
            {
                _isHomeServerConnected = true;
                SaveLastHomeServerData(serverDescriptor);
            }

            ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerConnected);
            ServiceRegistration.Get <IThreadPool>().Add(CompleteServerConnection);
        }
コード例 #4
0
 private void OnBackendServerDisconnected(DeviceConnection connection)
 {
     lock (_syncObj)
         _isHomeServerConnected = false;
     ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDisconnected);
 }