void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message) { if (message.ChannelName == SystemMessaging.CHANNEL) { SystemMessaging.MessageType messageType = (SystemMessaging.MessageType)message.MessageType; ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); if (messageType == SystemMessaging.MessageType.SystemStateChanged) { if (sss.CurrentState == SystemState.ShuttingDown || sss.CurrentState == SystemState.Ending) { UnsubscribeFromMessages(); } } } if (message.ChannelName == PlayerManagerMessaging.CHANNEL) { // React to player changes PlayerManagerMessaging.MessageType messageType = (PlayerManagerMessaging.MessageType)message.MessageType; switch (messageType) { case PlayerManagerMessaging.MessageType.PlayerStarted: IPlayerSlotController psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER]; HandleVideoEffectSelection(psc); break; } } }
/// <summary> /// Creates a new <see cref="BaseTimerControlledModel"/> instance and initializes the internal timer /// and message queue registrations. /// </summary> /// <param name="updateInterval">Timer update interval in milliseconds.</param> /// <remarks> /// Subclasses might need to call method <see cref="Update"/> in their constructor to initialize the initial model state, /// if appropriate. /// </remarks> protected BaseTimerControlledModel(long updateInterval) { _updateInterval = updateInterval; ISystemStateService systemStateService = ServiceRegistration.Get <ISystemStateService>(); if (systemStateService.CurrentState == SystemState.Running) { StartTimer(); } SubscribeToMessages(); }
private void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message) { if (message.ChannelName == PlaylistMessaging.CHANNEL) { PlaylistMessaging.MessageType messageType = (PlaylistMessaging.MessageType)message.MessageType; switch (messageType) { case PlaylistMessaging.MessageType.PlaylistUpdate: UpdatePlaylist(); break; case PlaylistMessaging.MessageType.CurrentItemChange: UpdateCurrentItem(); break; case PlaylistMessaging.MessageType.PropertiesChange: UpdateProperties(); break; } } else if (message.ChannelName == PlayerManagerMessaging.CHANNEL) { PlayerManagerMessaging.MessageType messageType = (PlayerManagerMessaging.MessageType)message.MessageType; switch (messageType) { case PlayerManagerMessaging.MessageType.PlayerSlotClosed: IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>(); ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); IPlayerContext pc = playerContextManager.GetPlayerContext(PlayerChoice.CurrentPlayer); if (pc == null && sss.CurrentState == SystemState.Running) { IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); workflowManager.NavigatePopToState(Consts.WF_STATE_ID_SHOW_PLAYLIST, true); } break; // We don't need to track the PlayerSlotActivated or PlayerSlotsChanged messages, because all information // we need is contained in the CurrentPlayer information } } else if (message.ChannelName == PlayerContextManagerMessaging.CHANNEL) { PlayerContextManagerMessaging.MessageType messageType = (PlayerContextManagerMessaging.MessageType)message.MessageType; switch (messageType) { case PlayerContextManagerMessaging.MessageType.CurrentPlayerChanged: UpdatePlaylist(); break; } } }
/// <summary> /// Creates a new <see cref="BaseTimerControlledModel"/> instance and initializes the internal timer /// and message queue registrations. /// </summary> /// <param name="startAtOnce">If set to <c>true</c>, the underlaying timer is started at once. Else, <see cref="StartTimer"/> /// must be called to start the timer.</param> /// <param name="updateInterval">Timer update interval in milliseconds.</param> /// <remarks> /// Subclasses might need to call method <see cref="Update"/> in their constructor to initialize the initial model state, /// if appropriate. /// </remarks> protected BaseTimerControlledModel(bool startAtOnce, long updateInterval) { _autoStart = startAtOnce; _updateInterval = updateInterval; ISystemStateService systemStateService = ServiceRegistration.Get <ISystemStateService>(); if (startAtOnce) { if (systemStateService.CurrentState == SystemState.Running) { StartTimer(); } else { SubscribeToMessages(); } } }
public void Activated(PluginRuntime pluginRuntime) { ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); if (sss.CurrentState == SystemState.Running) { RegisterKeyBindings(); } else { _messageQueue = new AsynchronousMessageQueue(typeof(StatisticsRenderer), new string[] { SystemMessaging.CHANNEL }); _messageQueue.MessageReceived += OnMessageReceived; _messageQueue.Start(); } }
private void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message) { if (message.ChannelName == PlaylistMessaging.CHANNEL) { PlaylistMessaging.MessageType messageType = (PlaylistMessaging.MessageType)message.MessageType; switch (messageType) { case PlaylistMessaging.MessageType.PlaylistUpdate: UpdatePlaylist(); break; case PlaylistMessaging.MessageType.PropertiesChange: UpdateProperties(); break; } } else if (message.ChannelName == PlayerManagerMessaging.CHANNEL) { PlayerManagerMessaging.MessageType messageType = (PlayerManagerMessaging.MessageType)message.MessageType; switch (messageType) { case PlayerManagerMessaging.MessageType.PlayerSlotClosed: IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>(); ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); IPlayerContext pc = playerContextManager.GetPlayerContext(PlayerChoice.CurrentPlayer); if (pc == null && sss.CurrentState == SystemState.Running) { IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); workflowManager.NavigatePopToState(Consts.WF_STATE_ID_EDIT_PLAYLIST, true); } break; } } else if (message.ChannelName == PlayerContextManagerMessaging.CHANNEL) { PlayerContextManagerMessaging.MessageType messageType = (PlayerContextManagerMessaging.MessageType)message.MessageType; switch (messageType) { case PlayerContextManagerMessaging.MessageType.CurrentPlayerChanged: UpdatePlaylist(); break; } } }
public void Activated(PluginRuntime pluginRuntime) { ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); if (sss.CurrentState == SystemState.Running) { _reloadSkinActions.RegisterKeyActions(); _loadSkinThemeActions.RegisterKeyActions(); } else { _messageQueue = new AsynchronousMessageQueue(typeof(ReloadSkinActions), new string[] { SystemMessaging.CHANNEL }); _messageQueue.MessageReceived += OnMessageReceived; _messageQueue.Start(); } }
public void Receive(SystemMessage message) { if (message.ChannelName == SystemMessaging.CHANNEL) { SystemMessaging.MessageType messageType = (SystemMessaging.MessageType)message.MessageType; ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); if (messageType == SystemMessaging.MessageType.SystemStateChanged) { if (sss.CurrentState == SystemState.ShuttingDown || sss.CurrentState == SystemState.Ending) { // It is necessary to block the main thread until our message delivery thread has delivered all pending // messages to avoid asynchronous threads during the shutdown phase. // It's a bit illegal to call the Shutdown() method which acquires a lock in this synchronous message // handler method. But as we know that the SystemStateChanged message is only called by our application // main thread which doesn't hold locks, this won't cause deadlocks. // How ugly, but that's life. _owner.Shutdown(); } } } }
/// <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(); } }
protected void Update() { ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); if (sss.CurrentState != SystemState.Running) { return; } INotificationService notificationService = ServiceRegistration.Get <INotificationService>(); int numNotifications = notificationService.Notifications.Count; IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); if (numNotifications == 0 && workflowManager.CurrentNavigationContext.WorkflowState.StateId == Consts.WF_STATE_ID_WATCH_NOTIFICATIONS) { // Don't pop the watch-notifications state from the navigation stack if we are in a sub state workflowManager.NavigatePopToStateAsync(Consts.WF_STATE_ID_WATCH_NOTIFICATIONS, true); } IsNotificationsHintVisible = !workflowManager.IsStateContainedInNavigationStack(Consts.WF_STATE_ID_WATCH_NOTIFICATIONS) && numNotifications > 0; NumNotificationsTotal = numNotifications; IsNotificationsAvailable = numNotifications > 0; IsMoreThanOneNotificationAvailable = numNotifications > 1; if (numNotifications <= 1) { NMoreNotificationsText = string.Empty; } else if (numNotifications == 2) { NMoreNotificationsText = LocalizationHelper.Translate(Consts.RES_ONE_MORE_NOTIFICATION); } else { NMoreNotificationsText = LocalizationHelper.Translate(Consts.RES_N_MORE_NOTIFICATIONS, numNotifications - 1); } INotification notification = notificationService.PeekNotification(); CurrentNotification = notification; if (notification != null) { if (string.IsNullOrEmpty(notification.CustomIconPath)) { switch (notification.Type) { case NotificationType.UserInteractionRequired: NotificationSymbolRelFilePath = Consts.REL_PATH_USER_INTERACTION_REQUIRED_ICON; break; case NotificationType.Info: NotificationSymbolRelFilePath = Consts.REL_PATH_INFO_ICON; break; case NotificationType.Warning: NotificationSymbolRelFilePath = Consts.REL_PATH_WARNING_ICON; break; case NotificationType.Error: NotificationSymbolRelFilePath = Consts.REL_PATH_ERROR_ICON; break; } } else { NotificationSymbolRelFilePath = notification.CustomIconPath; } HasSubWorkflow = notification.HandlerWorkflowState.HasValue; } }
protected bool IsSystemActive() { ISystemStateService sss = ServiceRegistration.Get <ISystemStateService>(); return(sss.CurrentState == SystemState.Running); }
public GetSystemInfoCommandHandler(ISystemStateService systemStateService) { _systemStateService = systemStateService; }