Exemple #1
0
        /// <summary>
        /// Erzeugt eine neue Beschreibung.
        /// </summary>
        /// <param name="state">Der aktuelle Zustand des Servers.</param>
        /// <param name="profiles">Die Liste der unterstützten DVB.NET Geräteprofile.</param>
        /// <param name="version">Die versionsbezeichnung.</param>
        /// <param name="useS3">Gesetzt, wenn für den Schlafzustand S3 und nicht S4 verwendet werden soll.</param>
        private ServerInfo(TrayColors state, Dictionary <string, ProfileInfo> profiles, string version, bool useS3)
        {
            // Remember
            m_S3Hibernate = useS3;
            m_Version     = version;
            m_State       = state;

            // Create synchronized copy
            lock (profiles)
                foreach (var current in profiles)
                {
                    m_Profiles[current.Key] = current.Value.Clone(this);
                }
        }
        private void SetNotifyIcon( NotifyIcon icon, TrayColors state )
        {
            // Store
            icon.Icon = m_TrayIcons[state];

            // Report
            Log( "{0} := {1}", icon.Text, state );
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="oldState"></param>
        /// <param name="newState"></param>
        /// <param name="mustHibernate"></param>
        /// <param name="pendingExtensions"></param>
        /// <returns>Gesetzt, wenn der Dialog geöffnet wurde und inaktiv, wenn er geschlossen wurde. <i>null</i> zeigt an,
        /// dass die Kontrolle über den Schlafzustand nicht hier erfolgt.</returns>
        private bool? GetHibernationDialogState( ProcessingItem controller, TrayColors oldState, TrayColors newState, bool mustHibernate, bool pendingExtensions )
        {
            // Only if watching local server
            if (!frameLocal.Enabled)
                return null;

            // Only if this is the local server (do not hide hibernation if active)
            var view = controller.View;
            if (!view.Settings.IsLocal)
                return null;

            // Can not hibernate
            if (m_Settings.HibernationDelay < 1)
            {
                // Dialog should not be shown
                HideHibernation();

                // Not responsible
                return null;
            }

            // See if hibernation is temporarily disabled
            if (m_BlockHibernate < DateTime.MaxValue)
                if (DateTime.UtcNow <= m_BlockHibernate)
                    return false;

            // Only if server is now idle
            if (TrayColors.Standard != newState)
                if (TrayColors.Green != newState)
                    return false;

            // See if hibernation dialog has run through
            if (null != m_Hibernation)
                if (m_Hibernation.MustHibernateNow)
                {
                    // See if there are pending extensions
                    if (!pendingExtensions)
                        m_Hibernation.TryHibernate( controller );

                    // No change required
                    return null;
                }
                else if (m_Hibernation.Visible)
                    return null;

            // Only if we come from recording
            if (!mustHibernate)
                return false;

            // Release
            if (null != m_Hibernation)
            {
                // Shutdown
                m_Hibernation.Dispose();

                // Forget
                m_Hibernation = null;
            }

            // Create dialog
            m_Hibernation = new HibernateDialog();

            // Initialize and show up
            m_Hibernation.Owner = this;
            m_Hibernation.Start( m_Settings.HibernationDelay );
            m_Hibernation.Show();

            // Hibernation dialog is running
            return true;
        }
        private bool GetHibernationDialogPoppedUp( ProcessingItem controller, TrayColors oldState, TrayColors newState, bool mustHibernate, bool pendingExtensions )
        {
            // Do the check
            bool? dialogState = GetHibernationDialogState( controller, oldState, newState, mustHibernate, pendingExtensions );

            // Just don't mess around with the hibernation dialog
            if (!dialogState.HasValue)
                return false;

            // Dialog should not be shown
            if (!dialogState.Value)
                HideHibernation();

            // Actually we feel responsible but optimize a bit to avoid too many callbacks
            return mustHibernate;
        }
        internal bool ProcessStateAndCheckHibernation( ProcessingItem controller, TrayColors state, bool mustHibernate, bool pendingExtensions )
        {
            // Load view
            var view = controller.View;

            // Report
            Log( "{0}:{1} report received for {2}", view.Settings.ServerName, view.Settings.ServerPort, state );

            // May be (normally) on the wrong thread
            if (InvokeRequired)
            {
                // Forward
                return (bool)Invoke( new ReportPattern( ProcessStateAndCheckHibernation ), controller, state, mustHibernate, pendingExtensions );
            }

            // Get the previous state
            TrayColors oldState = TrayColors.Unknown;

            // Find the view
            int index = lstServers.Items.IndexOf( view );
            if (index >= 0)
                if (index < m_Icons.Count)
                {
                    // Attach to the icon
                    var tray = m_Icons[index];

                    // Find
                    foreach (var test in m_TrayIcons)
                        if (ReferenceEquals( test.Value, tray.Icon ))
                        {
                            // Remember
                            oldState = test.Key;

                            // Stop
                            break;
                        }

                    // Set the new state
                    SetNotifyIcon( tray, state );
                }

            // Prepare next loop
            view.EndProcessing();

            // Process transition
            return GetHibernationDialogPoppedUp( controller, oldState, state, mustHibernate, pendingExtensions );
        }