protected void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
 {
     if (message.ChannelName == ServerConnectionMessaging.CHANNEL)
     {
         ServerConnectionMessaging.MessageType messageType = (ServerConnectionMessaging.MessageType)message.MessageType;
         switch (messageType)
         {
         case ServerConnectionMessaging.MessageType.HomeServerAttached:
         case ServerConnectionMessaging.MessageType.HomeServerDetached:
             FireStateChanged();
             break;
         }
     }
     else if (message.ChannelName == ContentDirectoryMessaging.CHANNEL)
     {
         ContentDirectoryMessaging.MessageType messageType = (ContentDirectoryMessaging.MessageType)message.MessageType;
         switch (messageType)
         {
         case ContentDirectoryMessaging.MessageType.RegisteredSharesChanged:
             FireStateChanged();
             break;
         }
     }
     else if (message.ChannelName == SharesMessaging.CHANNEL)
     {
         SharesMessaging.MessageType messageType = (SharesMessaging.MessageType)message.MessageType;
         switch (messageType)
         {
         case SharesMessaging.MessageType.ShareAdded:
         case SharesMessaging.MessageType.ShareRemoved:
             FireStateChanged();
             break;
         }
     }
 }
        private void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
        {
            if (message.ChannelName == ServerConnectionMessaging.CHANNEL)
            {
                ServerConnectionMessaging.MessageType messageType =
                    (ServerConnectionMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case ServerConnectionMessaging.MessageType.HomeServerAttached:
                case ServerConnectionMessaging.MessageType.HomeServerConnected:
                    _updatePending = true; //Update all
                    break;
                }
            }
            else if (message.ChannelName == ContentDirectoryMessaging.CHANNEL)
            {
                ContentDirectoryMessaging.MessageType messageType = (ContentDirectoryMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case ContentDirectoryMessaging.MessageType.ShareImportCompleted:
                    _importUpdatePending = true; //Update latest added
                    break;

                case ContentDirectoryMessaging.MessageType.MediaItemChanged:
                    if ((ContentDirectoryMessaging.MediaItemChangeType)message.MessageData[ContentDirectoryMessaging.MEDIA_ITEM_CHANGE_TYPE] != ContentDirectoryMessaging.MediaItemChangeType.None)
                    {
                        _mediaItemUpdatePending = true;
                    }
                    break;
                }
            }
            else if (message.ChannelName == SharesMessaging.CHANNEL)
            {
                SharesMessaging.MessageType messageType = (SharesMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case SharesMessaging.MessageType.ShareChanged:
                case SharesMessaging.MessageType.ShareRemoved:
                    _updatePending = true; //Update all
                    break;
                }
            }
            else if (message.ChannelName == PlayerManagerMessaging.CHANNEL)
            {
                PlayerManagerMessaging.MessageType messageType =
                    (PlayerManagerMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case PlayerManagerMessaging.MessageType.PlayerStopped:
                case PlayerManagerMessaging.MessageType.PlayerEnded:
                    _playbackUpdatePending = true; //Update most played and last played
                    break;
                }
            }
        }
        void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
        {
            if (message.ChannelName == ServerConnectionMessaging.CHANNEL)
            {
                ServerConnectionMessaging.MessageType messageType =
                    (ServerConnectionMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case ServerConnectionMessaging.MessageType.HomeServerAttached:
                case ServerConnectionMessaging.MessageType.HomeServerDetached:
                case ServerConnectionMessaging.MessageType.HomeServerConnected:
                    UpdateProperties_NoLock();
                    UpdateSharesLists_NoLock(false);
                    break;

                case ServerConnectionMessaging.MessageType.HomeServerDisconnected:
                    if (_shareProxy is ServerShares)
                    {
                        // If in edit workflow for a server share, when the server gets disconneted, go back to the shares overview
                        NavigateBackToOverview();
                    }
                    else
                    {
                        UpdateProperties_NoLock();
                        UpdateSharesLists_NoLock(false);
                    }
                    break;
                }
            }
            else if (message.ChannelName == ContentDirectoryMessaging.CHANNEL)
            {
                ContentDirectoryMessaging.MessageType messageType = (ContentDirectoryMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case ContentDirectoryMessaging.MessageType.RegisteredSharesChanged:
                    UpdateProperties_NoLock();
                    UpdateSharesLists_NoLock(false);
                    break;
                }
            }
            else if (message.ChannelName == SharesMessaging.CHANNEL)
            {
                SharesMessaging.MessageType messageType = (SharesMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case SharesMessaging.MessageType.ShareAdded:
                case SharesMessaging.MessageType.ShareRemoved:
                    UpdateProperties_NoLock();
                    UpdateSharesLists_NoLock(false);
                    break;
                }
            }
        }
Пример #4
0
 void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
 {
   if (message.ChannelName == SharesMessaging.CHANNEL)
   {
     IContentDirectory cd = ContentDirectory;
     SharesMessaging.MessageType messageType =
         (SharesMessaging.MessageType) message.MessageType;
     IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();
     Share share;
     switch (messageType)
     {
       case SharesMessaging.MessageType.ShareAdded:
         share = (Share) message.MessageData[SharesMessaging.SHARE];
         if (cd != null)
           cd.RegisterShareAsync(share);
         importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true);
         break;
       case SharesMessaging.MessageType.ShareRemoved:
         share = (Share) message.MessageData[SharesMessaging.SHARE];
         importerWorker.CancelJobsForPath(share.BaseResourcePath);
         if (cd != null)
           cd.RemoveShareAsync(share.ShareId);
         break;
       case SharesMessaging.MessageType.ShareChanged:
         RelocationMode relocationMode = (RelocationMode) message.MessageData[SharesMessaging.RELOCATION_MODE];
         share = (Share) message.MessageData[SharesMessaging.SHARE];
         importerWorker.CancelJobsForPath(share.BaseResourcePath);
         if (cd == null)
         {
           ISettingsManager settingsManager = ServiceRegistration.Get<ISettingsManager>();
           ServerConnectionSettings settings = settingsManager.Load<ServerConnectionSettings>();
           RelocationMode oldMode;
           if (settings.CachedSharesUpdates.TryGetValue(share.ShareId, out oldMode) && oldMode == RelocationMode.ClearAndReImport)
             // ClearAndReimport is stronger than Relocate, use ClearAndReImport
             relocationMode = oldMode;
           settings.CachedSharesUpdates[share.ShareId] = relocationMode;
           settingsManager.Save(settings);
         }
         else
         {
           cd.UpdateShareAsync(share.ShareId, share.BaseResourcePath, share.Name, share.UseShareWatcher, share.MediaCategories, relocationMode);
           switch (relocationMode)
           {
             case RelocationMode.ClearAndReImport:
               importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true);
               break;
             case RelocationMode.Relocate:
               importerWorker.ScheduleRefresh(share.BaseResourcePath, share.MediaCategories, true);
               break;
           }
         }
         break;
       case SharesMessaging.MessageType.ReImportShare:
         share = (Share) message.MessageData[SharesMessaging.SHARE];
         importerWorker.ScheduleRefresh(share.BaseResourcePath, share.MediaCategories, true);
         break;
     }
   }
   else if (message.ChannelName == ImporterWorkerMessaging.CHANNEL)
   {
     IContentDirectory cd = ContentDirectory;
     ImporterWorkerMessaging.MessageType messageType = (ImporterWorkerMessaging.MessageType) message.MessageType;
     switch (messageType)
     {
       case ImporterWorkerMessaging.MessageType.ImportStarted:
       case ImporterWorkerMessaging.MessageType.ImportCompleted:
         if (cd == null)
           break;
         ResourcePath path = (ResourcePath) message.MessageData[ImporterWorkerMessaging.RESOURCE_PATH];
         ILocalSharesManagement lsm = ServiceRegistration.Get<ILocalSharesManagement>();
         ICollection<Share> shares = lsm.Shares.Values;
         Share share = shares.BestContainingPath(path);
         if (share == null)
           break;
         if (messageType == ImporterWorkerMessaging.MessageType.ImportStarted)
           cd.ClientStartedShareImportAsync(share.ShareId);
         else
           cd.ClientCompletedShareImportAsync(share.ShareId);
         break;
     }
   }
   else if (message.ChannelName == ServerStateMessaging.CHANNEL)
   {
     //Check if Tv Server state has changed and update if necessary
     ServerStateMessaging.MessageType messageType = (ServerStateMessaging.MessageType)message.MessageType;
     if (messageType == ServerStateMessaging.MessageType.StatesChanged)
     {
       var states = message.MessageData[ServerStateMessaging.STATES] as IDictionary<Guid, object>;
       if (states != null && states.ContainsKey(ShareImportServerState.STATE_ID))
       {
         ShareImportServerState importState = states[ShareImportServerState.STATE_ID] as ShareImportServerState;
         if (importState != null)
         {
           List<ShareImportState> shareStates = new List<ShareImportState>(importState.Shares);
           lock (_syncObj)
           {
             UpdateCurrentlyImportingShares(shareStates.Where(s => s.IsImporting).Select(s => s.ShareId).ToList());
             UpdateCurrentlyImportingSharesProgresses(shareStates.Where(s => s.IsImporting).ToDictionary(s => s.ShareId, s => s.Progress));
           }
         }
       }
       else if (states != null && states.ContainsKey(DatabaseUpgradeServerState.STATE_ID))
       {
         DatabaseUpgradeServerState upgradeState = states[DatabaseUpgradeServerState.STATE_ID] as DatabaseUpgradeServerState;
         if (upgradeState != null && !upgradeState.IsUpgrading && upgradeState.Progress == 100)
         {
           ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDisconnected);
           ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerConnected);
         }
       }
     }
   }
 }
        void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
        {
            if (message.ChannelName == SharesMessaging.CHANNEL)
            {
                IContentDirectory           cd          = ContentDirectory;
                SharesMessaging.MessageType messageType =
                    (SharesMessaging.MessageType)message.MessageType;
                IImporterWorker importerWorker = ServiceRegistration.Get <IImporterWorker>();
                Share           share;
                switch (messageType)
                {
                case SharesMessaging.MessageType.ShareAdded:
                    share = (Share)message.MessageData[SharesMessaging.SHARE];
                    if (cd != null)
                    {
                        cd.RegisterShare(share);
                    }
                    importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true);
                    break;

                case SharesMessaging.MessageType.ShareRemoved:
                    share = (Share)message.MessageData[SharesMessaging.SHARE];
                    importerWorker.CancelJobsForPath(share.BaseResourcePath);
                    if (cd != null)
                    {
                        cd.RemoveShare(share.ShareId);
                    }
                    break;

                case SharesMessaging.MessageType.ShareChanged:
                    RelocationMode relocationMode = (RelocationMode)message.MessageData[SharesMessaging.RELOCATION_MODE];
                    share = (Share)message.MessageData[SharesMessaging.SHARE];
                    importerWorker.CancelJobsForPath(share.BaseResourcePath);
                    if (cd == null)
                    {
                        ISettingsManager         settingsManager = ServiceRegistration.Get <ISettingsManager>();
                        ServerConnectionSettings settings        = settingsManager.Load <ServerConnectionSettings>();
                        RelocationMode           oldMode;
                        if (settings.CachedSharesUpdates.TryGetValue(share.ShareId, out oldMode) && oldMode == RelocationMode.ClearAndReImport)
                        {
                            // ClearAndReimport is stronger than Relocate, use ClearAndReImport
                            relocationMode = oldMode;
                        }
                        settings.CachedSharesUpdates[share.ShareId] = relocationMode;
                        settingsManager.Save(settings);
                    }
                    else
                    {
                        cd.UpdateShare(share.ShareId, share.BaseResourcePath, share.Name, share.MediaCategories, relocationMode);
                        switch (relocationMode)
                        {
                        case RelocationMode.ClearAndReImport:
                            importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true);
                            break;

                        case RelocationMode.Relocate:
                            importerWorker.ScheduleRefresh(share.BaseResourcePath, share.MediaCategories, true);
                            break;
                        }
                    }
                    break;

                case SharesMessaging.MessageType.ReImportShare:
                    share = (Share)message.MessageData[SharesMessaging.SHARE];
                    importerWorker.ScheduleRefresh(share.BaseResourcePath, share.MediaCategories, true);
                    break;
                }
            }
            else if (message.ChannelName == ImporterWorkerMessaging.CHANNEL)
            {
                IContentDirectory cd = ContentDirectory;
                ImporterWorkerMessaging.MessageType messageType = (ImporterWorkerMessaging.MessageType)message.MessageType;
                switch (messageType)
                {
                case ImporterWorkerMessaging.MessageType.ImportStarted:
                case ImporterWorkerMessaging.MessageType.ImportCompleted:
                    if (cd == null)
                    {
                        break;
                    }
                    ResourcePath           path   = (ResourcePath)message.MessageData[ImporterWorkerMessaging.RESOURCE_PATH];
                    ILocalSharesManagement lsm    = ServiceRegistration.Get <ILocalSharesManagement>();
                    ICollection <Share>    shares = lsm.Shares.Values;
                    Share share = shares.BestContainingPath(path);
                    if (share == null)
                    {
                        break;
                    }
                    if (messageType == ImporterWorkerMessaging.MessageType.ImportStarted)
                    {
                        cd.ClientStartedShareImport(share.ShareId);
                    }
                    else
                    {
                        cd.ClientCompletedShareImport(share.ShareId);
                    }
                    break;
                }
            }
        }