void OnBackendServerDisconnected(DeviceConnection connection) { lock (_syncObj) _isHomeServerConnected = false; IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>(); importerWorker.Suspend(); UpdateCurrentlyImportingShares(null); // Mark all shares as not being imported ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDisconnected); }
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); ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Clearing pending import jobs and suspending importer worker"); IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>(); importerWorker.Suspend(); importerWorker.CancelPendingJobs(); ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Notifying the MediaPortal server about the detachment"); UPnPServerControllerServiceProxy sc = ServerControllerServiceProxy; ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>(); if (sc != null) try { sc.DetachClient(systemResolver.LocalSystemId); sc.AttachedClientsChanged -= OnAttachedClientsChanged; sc.ConnectedClientsChanged -= OnConnectedClientsChanged; } catch (Exception e) { ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Error detaching from home server '{0}'", e, HomeServerSystemId); } UPnPContentDirectoryServiceProxy cd = ContentDirectoryServiceProxy; if (cd != null) try { cd.PlaylistsChanged -= OnContentDirectoryPlaylistsChanged; cd.MIATypeRegistrationsChanged -= OnContentDirectoryMIATypeRegistrationsChanged; cd.RegisteredSharesChangeCounterChanged -= OnRegisteredSharesChangeCounterChanged; } catch (Exception e) { ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Error unregistering from state variable change events", e); } 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; } UpdateCurrentlyImportingShares(null); // Mark all shares as not being imported 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 } }