public void ShowCurrentlyPlaying(bool asynchronously)
        {
            Guid currentlyPlayingStateId;

            lock (SyncObj)
            {
                if (IsCurrentlyPlayingWorkflowStateActive)
                {
                    return;
                }
                IPlayerContext pc = GetPlayerContext(_currentPlayerIndex);
                if (pc == null)
                {
                    return;
                }
                currentlyPlayingStateId = pc.CurrentlyPlayingWorkflowStateId;
            }
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            if (asynchronously)
            {
                workflowManager.NavigatePushAsync(currentlyPlayingStateId);
            }
            else
            {
                workflowManager.NavigatePush(currentlyPlayingStateId);
            }
            // TODO: Would be good if we could wait for the CP screen to be shown. But to achieve that, we need the ScreenManager to send
            // a message when a screen change has completed.
        }
        public void ShowFullscreenContent(bool asynchronously)
        {
            Guid fullscreenContentStateId;

            lock (SyncObj)
            {
                if (IsFullscreenContentWorkflowStateActive)
                {
                    return;
                }
                IPlayerContext pc = PrimaryPlayerContext;
                if (pc == null)
                {
                    return;
                }
                fullscreenContentStateId = pc.FullscreenContentWorkflowStateId;
            }
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            if (asynchronously)
            {
                workflowManager.NavigatePushAsync(fullscreenContentStateId);
            }
            else
            {
                workflowManager.NavigatePush(fullscreenContentStateId);
            }
            // TODO: Would be good if we could wait for the FSC screen to be shown. But to achieve that, we need the ScreenManager to send
            // a message when a screen change has completed.
        }
 public void EnterModelContext(MediaPortal.UI.Presentation.Workflow.NavigationContext oldContext, MediaPortal.UI.Presentation.Workflow.NavigationContext newContext)
 {
     _messageQueue.Start();
     // when entering OV model context and no siteutils have been loaded yet - run Automatic Update
     // todo : let the user configure if he wants to run the AutoUpdate or be asked, configure x hours before doing/asking again
     if (!OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
     {
         if (_settingsWatcher.Settings.LastAutomaticUpdate.AddHours(4) < DateTime.Now &&
             OnlineVideos.Sites.Updater.VersionCompatible)
         {
             IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();
             workflowManager.NavigatePushAsync(Guids.DialogStateSiteUpdate);
         }
         else
         {
             // show the busy indicator, because loading site dlls takes some seconds
             ServiceRegistration.Get <ISuperLayerManager>().ShowBusyScreen();
             try
             {
                 OnlineVideoSettings.Instance.BuildSiteUtilsList();
                 RebuildSitesList();
             }
             catch (Exception ex)
             {
                 Log.Error(ex);
             }
             finally
             {
                 ServiceRegistration.Get <ISuperLayerManager>().HideBusyScreen();
             }
         }
     }
 }
        void ShowDetails(List <DetailVideoInfo> choices)
        {
            DetailsVideosList = new List <VideoViewModel>();
            choices.ForEach(r => { r.CleanDescriptionAndTitle(); DetailsVideosList.Add(new VideoViewModel(r, SelectedCategory != null ? SelectedCategory.Category : null, SelectedSite.Site.Settings, true)); });
            ImageDownloader.GetImages <DetailVideoInfo>(choices);
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePushAsync(Guids.WorkflowStateDetails, new NavigationContextConfig()
            {
                NavigationContextDisplayLabel = SelectedVideo.Title
            });
        }
        void ShowCategories(IList <Category> categories, string navigationLabel)
        {
            CategoriesList = new ItemsList();
            foreach (Category c in categories)
            {
                CategoriesList.Add(new CategoryViewModel(c));
            }
            ImageDownloader.GetImages <Category>(categories);
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePushAsync(Guids.WorkflowStateCategories, new NavigationContextConfig()
            {
                NavigationContextDisplayLabel = navigationLabel
            });
        }
        void ShowVideos(CategoryViewModel category, List <VideoInfo> videos)
        {
            SelectedCategory = category;
            VideosList       = new ItemsList();
            videos.ForEach(r => { r.CleanDescriptionAndTitle(); VideosList.Add(new VideoViewModel(r, SelectedCategory != null ? SelectedCategory.Category : null, SelectedSite.Site.Settings, false)); });

            if (SelectedSite.Site.HasNextPage)
            {
                VideosList.Add(new VideoViewModel(Translation.Instance.NextPage, "NextPage.png"));
            }

            ImageDownloader.GetImages <VideoInfo>(videos);
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePushAsync(Guids.WorkflowStateVideos, new NavigationContextConfig()
            {
                NavigationContextDisplayLabel = SelectedCategory.Name
            });
        }
        public void SelectSiteGroup(SiteGroupViewModel siteGroupModel)
        {
            if (BackgroundTask.Instance.IsExecuting)
            {
                return;
            }
            SitesList.Clear();
            foreach (string siteName in siteGroupModel.Sites)
            {
                var siteutils = OnlineVideoSettings.Instance.SiteUtilsList;
                SitesList.Add(new SiteViewModel(siteutils[siteName]));
            }
            sitesListHasAllSites = false;
            SitesList.FireChange();
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePushAsync(Guids.WorkflowStateSites, new NavigationContextConfig()
            {
                NavigationContextDisplayLabel = siteGroupModel.Labels["Name"].ToString()
            });
        }
        public void StartPartyMode()
        {
            ServiceRegistration.Get <ILogger>().Info("PartyMusicPlayerModel: Starting party mode");
            SaveSettings();
            if (!LoadPlaylist())
            {
                return;
            }

            LoadPlayRepeatMode();

            IPlayerContextManager pcm = ServiceRegistration.Get <IPlayerContextManager>();
            IPlayerContext        audioPlayerContext = pcm.OpenAudioPlayerContext(Consts.MODULE_ID_PARTY_MUSIC_PLAYER, Consts.RES_PLAYER_CONTEXT_NAME, false,
                                                                                  Consts.WF_STATE_ID_PARTY_MUSIC_PLAYER, Consts.WF_STATE_ID_PARTY_MUSIC_PLAYER);
            IPlaylist playlist = audioPlayerContext.Playlist;

            playlist.StartBatchUpdate();
            try
            {
                playlist.Clear();
                foreach (MediaItem mediaItem in _mediaItems)
                {
                    playlist.Add(mediaItem);
                }
                playlist.PlayMode   = PlayMode;
                playlist.RepeatMode = RepeatMode;
                _playerContext      = audioPlayerContext;
            }
            finally
            {
                playlist.EndBatchUpdate();
            }

            audioPlayerContext.Play();

            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePushAsync(Consts.WF_STATE_ID_PARTY_MUSIC_PLAYER);
        }
        /// <summary>
        /// Checks if our "currently playing" and "fullscreen content" states still fit to the
        /// appropriate players, i.e. if we are in a "currently playing" state and the current player context was
        /// changed, the workflow state will be adapted to match the new current player context's "currently playing" state.
        /// The same check will happen for the primary player context and the "fullscreen content" state.
        /// </summary>
        /// <remarks>
        /// This method must not be called when the player manager's lock is held.
        /// </remarks>
        protected void CheckMediaWorkflowStates_NoLock()
        {
            ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>();

            if (sss.CurrentState != SystemState.Running)
            {
                // Only automatically change workflow states in running state
                return;
            }
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.StartBatchUpdateAsync();
            ILogger        log           = ServiceRegistration.Get <ILogger>();
            IPlayerManager playerManager = ServiceRegistration.Get <IPlayerManager>();

            try
            {
                for (int i = 0; i < _playerWfStateInstances.Count; i++)
                {
                    // Find the first workflow state of our cached player workflow states which doesn't fit any more
                    // and update to the new player workflow state of the same player workflow state type, if necessary.
                    PlayerWFStateInstance wfStateInstance = _playerWfStateInstances[i];
                    Guid?  newStateId;
                    string stateName;
                    switch (wfStateInstance.WFStateType)
                    {
                    case PlayerWFStateType.CurrentlyPlaying:
                        newStateId = GetPotentialCPStateId();
                        stateName  = "Currently Playing";
                        break;

                    case PlayerWFStateType.FullscreenContent:
                        newStateId = GetPotentialFSCStateId();
                        stateName  = "Fullscreen Content";
                        break;

                    default:
                        throw new NotImplementedException(string.Format("No handler for player workflow state type '{0}'",
                                                                        wfStateInstance.WFStateType));
                    }
                    if (newStateId != wfStateInstance.WFStateId)
                    {
                        // Found the first player workflow state which doesn't fit any more
                        log.Debug("PlayerContextManager: {0} Workflow State '{1}' doesn't fit any more to the current situation. Leaving workflow state.",
                                  stateName, wfStateInstance.WFStateId);
                        lock (playerManager.SyncObj)
                            // Remove all workflow states until the player workflow state which doesn't fit any more
                            _playerWfStateInstances.RemoveRange(i, _playerWfStateInstances.Count - i);
                        workflowManager.NavigatePopToStateAsync(wfStateInstance.WFStateId, true);
                        if (newStateId.HasValue)
                        {
                            log.Debug("PlayerContextManager: Auto-switching to new {0} Workflow State '{1}'",
                                      stateName, newStateId.Value);
                            workflowManager.NavigatePushAsync(newStateId.Value);
                        }
                        break;
                    }
                }
            }
            finally
            {
                workflowManager.EndBatchUpdateAsync();
            }
        }