Ejemplo n.º 1
0
        public void AttachClient(string clientSystemId)
        {
            ISQLDatabase database    = ServiceRegistration.Get <ISQLDatabase>();
            ITransaction transaction = database.BeginTransaction();

            try
            {
                using (IDbCommand command = ClientManager_SubSchema.InsertAttachedClientCommand(transaction, clientSystemId, null, null))
                    command.ExecuteNonQuery();
                transaction.Commit();
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("ClientManager: Error attaching client '{0}'", e, clientSystemId);
                transaction.Rollback();
                throw;
            }
            ServiceRegistration.Get <ILogger>().Info("ClientManager: Client with system ID '{0}' attached", clientSystemId);
            // Establish the UPnP connection to the client, if available in the network
            IDictionary <string, MPClientMetadata> attachedClients = ReadAttachedClientsFromDB();

            lock (_syncObj)
                _attachedClients = attachedClients;
            _controlPoint.AddAttachedClient(clientSystemId);
            ClientManagerMessaging.SendClientAttachmentChangeMessage(ClientManagerMessaging.MessageType.ClientAttached, clientSystemId);
        }
Ejemplo n.º 2
0
        public void DetachClientAndRemoveShares(string clientSystemId)
        {
            ISQLDatabase database    = ServiceRegistration.Get <ISQLDatabase>();
            ITransaction transaction = database.BeginTransaction();

            try
            {
                using (IDbCommand command = ClientManager_SubSchema.DeleteAttachedClientCommand(transaction, clientSystemId))
                    command.ExecuteNonQuery();

                IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>();
                mediaLibrary.DeleteMediaItemOrPath(clientSystemId, null, true);
                mediaLibrary.RemoveSharesOfSystem(clientSystemId);

                transaction.Commit();
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("ClientManager: Error detaching client '{0}'", e, clientSystemId);
                transaction.Rollback();
                throw;
            }
            ServiceRegistration.Get <ILogger>().Info("ClientManager: Client with system ID '{0}' detached", clientSystemId);
            // Last action: Remove the client from the collection of attached clients and disconnect the client connection, if connected
            _attachedClients = ReadAttachedClientsFromDB();
            _controlPoint.RemoveAttachedClient(clientSystemId);
            ClientManagerMessaging.SendClientAttachmentChangeMessage(ClientManagerMessaging.MessageType.ClientDetached, clientSystemId);
        }
Ejemplo n.º 3
0
 public void DetachClient(Guid clientId)
 {
     ClientManagerMessaging.SendClientAttachmentChangeMessage(ClientManagerMessaging.MessageType.ClientDetached, clientId.ToString());
 }