public ClientConnection(UPnPControlPoint controlPoint, DeviceConnection connection, ClientDescriptor clientDescriptor)
 {
     _controlPoint     = controlPoint;
     _connection       = connection;
     _clientDescriptor = clientDescriptor;
     _connection.DeviceDisconnected += OnUPnPDeviceDisconnected;
     try
     {
         CpService ccsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.CLIENT_CONTROLLER_SERVICE_ID);
         if (ccsStub == null)
         {
             throw new InvalidDataException("ClientController service not found in device '{0}' of type '{1}:{2}'",
                                            clientDescriptor.MPFrontendServerUUID,
                                            UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE_VERSION);
         }
         lock (_connection.CPData.SyncObj)
             _clientController = new UPnPClientControllerServiceProxy(ccsStub);
         // TODO: other services
     }
     catch (Exception)
     {
         _connection.DeviceDisconnected -= OnUPnPDeviceDisconnected;
         throw;
     }
 }
示例#2
0
 protected void CompleteClientConnection(ClientDescriptor client)
 {
   if (!ValidateAttachmentState(client))
     return;
   UpdateClientSystem(client.MPFrontendServerUUID, client.System, client.ClientName);
   ClientManagerMessaging.SendConnectionStateChangedMessage(ClientManagerMessaging.MessageType.ClientOnline, client);
 }
示例#3
0
 void OnClientConnected(ClientDescriptor client)
 {
   UpdateClientSetOnline(client.MPFrontendServerUUID, client.System);
   // This method is called as a result of our control point's attempt to connect to the (allegedly attached) client;
   // But maybe the client isn't attached any more to this server (it could have detached while the server wasn't online).
   // So we will validate if the client is still attached.
   ServiceRegistration.Get<IThreadPool>().Add(() => CompleteClientConnection(client));
 }
        public override bool Equals(object obj)
        {
            ClientDescriptor other = obj as ClientDescriptor;

            if (obj == null)
            {
                return(false);
            }
            return(other == this);
        }
示例#5
0
 protected bool ValidateAttachmentState(ClientDescriptor client)
 {
   string clientSystemId = client.MPFrontendServerUUID;
   ServiceRegistration.Get<ILogger>().Info("ClientManager: Validating attachment state of client '{0}' (system ID '{1}')",
       client.ClientName, clientSystemId);
   ClientConnection connection = _controlPoint.GetClientConnection(clientSystemId);
   if (connection != null)
   {
     string homeServerSystemId = connection.ClientController.GetHomeServerSystemId();
     ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
     if (homeServerSystemId != systemResolver.LocalSystemId)
     {
       ServiceRegistration.Get<ILogger>().Info(
           "ClientManager: Client '{0}' is no longer attached to this server, cleaning up client data", clientSystemId);
       DetachClientAndRemoveShares(clientSystemId);
       return false;
     }
   }
   return true;
 }
 public ClientConnection(UPnPControlPoint controlPoint, DeviceConnection connection, ClientDescriptor clientDescriptor)
 {
   _controlPoint = controlPoint;
   _connection = connection;
   _clientDescriptor = clientDescriptor;
   _connection.DeviceDisconnected += OnUPnPDeviceDisconnected;
   try
   {
     CpService ccsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.CLIENT_CONTROLLER_SERVICE_ID);
     if (ccsStub == null)
       throw new InvalidDataException("ClientController service not found in device '{0}' of type '{1}:{2}'",
           clientDescriptor.MPFrontendServerUUID,
           UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE_VERSION);
     lock (_connection.CPData.SyncObj)
       _clientController = new UPnPClientControllerServiceProxy(ccsStub);
     // TODO: other services
   }
   catch (Exception)
   {
     _connection.DeviceDisconnected -= OnUPnPDeviceDisconnected;
     throw;
   }
 }
示例#7
0
 void OnClientDisconnected(ClientDescriptor client)
 {
   UpdateClientSetOffline(client.MPFrontendServerUUID);
   ClientManagerMessaging.SendConnectionStateChangedMessage(ClientManagerMessaging.MessageType.ClientOffline, client);
 }
        public const string CLIENT_SYSTEM     = "ClientSystemId";   // Contains a string with the system ID of a client

        /// <summary>
        /// Sends a message concerning a client.
        /// </summary>
        /// <param name="messageType">One of the <see cref="MessageType"/> messages.</param>
        /// <param name="client">Descriptor describing the client which is affected.</param>
        public static void SendConnectionStateChangedMessage(MessageType messageType, ClientDescriptor client)
        {
            SystemMessage msg = new SystemMessage(messageType);

            msg.MessageData[CLIENT_DESCRIPTOR] = client;
            ServiceRegistration.Get <IMessageBroker>().Send(CHANNEL, msg);
        }
 protected void InvokeClientDisconnected(ClientDescriptor clientDescriptor)
 {
   ClientStateChangedDlgt dlgt = ClientDisconnected;
   if (dlgt != null)
     dlgt(clientDescriptor);
 }
 protected void InvokeClientUnavailable(ClientDescriptor clientDescriptor)
 {
   ClientStateChangedDlgt dlgt = ClientUnavailable;
   if (dlgt != null)
     dlgt(clientDescriptor);
 }
 protected void CheckConnect(ClientDescriptor clientDescriptor)
 {
   // Check if client is attached and connect if it is an attached client
   string clientSystemId = clientDescriptor.MPFrontendServerUUID;
   lock (_networkTracker.SharedControlPointData.SyncObj)
   {
     if (!_attachedClientSystemIds.Contains(clientSystemId))
       return;
     if (_clientConnections.ContainsKey(clientSystemId))
       return;
   }
   DeviceConnection connection;
   try
   {
     connection = _controlPoint.Connect(clientDescriptor.ClientDeviceDescriptor.RootDescriptor, clientSystemId,
         UPnPExtendedDataTypes.ResolveDataType);
   }
   catch (Exception e)
   {
     ServiceRegistration.Get<ILogger>().Warn(
         "UPnPServerControlPoint: Error connecting to UPnP MP2 frontend server '{0}'", e, clientSystemId);
     return;
   }
   try
   {
     ClientConnection clientConnection = new ClientConnection(_controlPoint, connection, clientDescriptor);
     lock (_networkTracker.SharedControlPointData.SyncObj)
       _clientConnections.Add(clientDescriptor.MPFrontendServerUUID, clientConnection);
     clientConnection.ClientDeviceDisconnected += OnClientDisconnected;
   }
   catch (Exception e)
   {
     ServiceRegistration.Get<ILogger>().Warn(
         "UPnPServerControlPoint: Error connecting to services of UPnP MP2 frontend server '{0}'", e, clientSystemId);
     _controlPoint.Disconnect(connection);
     return;
   }
   InvokeClientConnected(clientDescriptor);
 }
    public const string CLIENT_SYSTEM = "ClientSystemId"; // Contains a string with the system ID of a client

    /// <summary>
    /// Sends a message concerning a client.
    /// </summary>
    /// <param name="messageType">One of the <see cref="MessageType"/> messages.</param>
    /// <param name="client">Descriptor describing the client which is affected.</param>
    public static void SendConnectionStateChangedMessage(MessageType messageType, ClientDescriptor client)
    {
      SystemMessage msg = new SystemMessage(messageType);
      msg.MessageData[CLIENT_DESCRIPTOR] = client;
      ServiceRegistration.Get<IMessageBroker>().Send(CHANNEL, msg);
    }