void OnUPnPRootDeviceAdded(RootDescriptor rootDescriptor)
        {
            ICollection <ServerDescriptor> availableServers;

            using (_networkTracker.SharedControlPointData.Lock.EnterWrite())
            {
                ServerDescriptor serverDescriptor = ServerDescriptor.GetMPBackendServerDescriptor(rootDescriptor);
                if (serverDescriptor == null || _availableServers.Contains(serverDescriptor))
                {
                    return;
                }
                SystemName preferredLink = serverDescriptor.GetPreferredLink();
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerWatcher: Found MediaPortal 2 BackendServer '{0}' at host '{1}' (IP address: '{2}')",
                                                          serverDescriptor.ServerName, preferredLink.HostName, preferredLink.Address);
                _availableServers.Add(serverDescriptor);
                availableServers = _availableServers;
            }
            InvokeAvailableBackendServersChanged(availableServers, true);
        }
        void OnUPnPRootDeviceRemoved(RootDescriptor rootDescriptor)
        {
            ICollection <ServerDescriptor> availableServers;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                ServerDescriptor serverDescriptor = ServerDescriptor.GetMPBackendServerDescriptor(rootDescriptor);
                if (serverDescriptor == null || !_availableServers.Contains(serverDescriptor))
                {
                    return;
                }
                SystemName preferredLink = serverDescriptor.GetPreferredLink();
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerWatcher: MediaPortal 2 BackendServer '{0}' at host '{1}' (IP address: '{2}') was removed from the network",
                                                          serverDescriptor.ServerName, preferredLink.HostName, preferredLink.Address);
                _availableServers.Remove(serverDescriptor);
                availableServers = _availableServers;
            }
            InvokeAvailableBackendServersChanged(availableServers, false);
        }
Beispiel #3
0
    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);
      _ = CompleteServerConnectionAsync();
    }
        /// <summary>
        /// Tries to determine the server IP address from the current server connection.
        /// </summary>
        /// <param name="serverAddress">If successful, contains the IP address of the server.</param>
        /// <returns></returns>
        protected bool TryGetServerIPAddress(out IPAddress localAddress, out IPAddress serverAddress)
        {
            localAddress  = null;
            serverAddress = null;

            var cp = ServiceRegistration.Get <IServerConnectionManager>().ControlPoint;

            if (cp == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("WakeOnLanClient: Could not get server IP address, UPnPControlPoint not found");
                return(false);
            }

            if (cp.Connection == null)
            {
                //Don't log here, the server isn't connected (yet), we'll retry getting the address when it connects.
                return(false);
            }

            ServerDescriptor serverDescriptor = ServerDescriptor.GetMPBackendServerDescriptor(cp.Connection.RootDescriptor);

            if (serverDescriptor == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("WakeOnLanClient: Could not get server IP address, unable to verify UPnP root descriptor");
                return(false);
            }

            SystemName preferredLink = serverDescriptor.GetPreferredLink();

            if (IPAddress.TryParse(preferredLink.Address, out serverAddress))
            {
                localAddress = cp.Connection.RootDescriptor.SSDPRootEntry.PreferredLink.Endpoint.EndPointIPAddress;
                ServiceRegistration.Get <ILogger>().Debug("WakeOnLanClient: Got server IP address '{0}' for '{1}', local address '{2}'", serverAddress, preferredLink.HostName, localAddress);
                return(true);
            }
            return(false);
        }