示例#1
0
        /// <summary>
        /// build the context menu each time it opens to ensure appropriate options
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = false;
            _notifyIcon.ContextMenuStrip.Items.Clear();

            //see if we are still connected.
            if (_plexService == null)
            {
                Connect();
            }

            if (_plexService != null)// && ((ICommunicationObject)_plexService).State == CommunicationState.Opened)
            {
                try
                {
                    var state = _plexService.GetStatus();
                    switch (state)
                    {
                    case PlexState.Running:
                        _notifyIcon.ContextMenuStrip.Items.Add("Open Web Manager", null, OpenManager_Click);
                        _notifyIcon.ContextMenuStrip.Items.Add("Stop Plex", null, StopPlex_Click);
                        break;

                    case PlexState.Stopped:
                        _notifyIcon.ContextMenuStrip.Items.Add("Start Plex", null, StartPlex_Click);
                        break;

                    case PlexState.Pending:
                        _notifyIcon.ContextMenuStrip.Items.Add("Restart Pending");
                        break;

                    case PlexState.Stopping:
                        _notifyIcon.ContextMenuStrip.Items.Add("Stopping");
                        break;

                    default:
                        _notifyIcon.ContextMenuStrip.Items.Add("Plex state unknown");
                        break;
                    }
                    _notifyIcon.ContextMenuStrip.Items.Add("View Logs", null, ViewLogs_Click);
                    _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
                    _notifyIcon.ContextMenuStrip.Items.Add("Settings", null, SettingsCommand);
                }
                catch
                {
                    Disconnect();
                    _notifyIcon.ContextMenuStrip.Items.Add("Unable to connect to service. Check settings");
                }
            }
            else
            {
                Disconnect();
                _notifyIcon.ContextMenuStrip.Items.Add("Unable to connect to service. Check settings");
            }
            _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            _notifyIcon.ContextMenuStrip.Items.Add("Connection Settings", null, ConnectionSettingsCommand);
            _notifyIcon.ContextMenuStrip.Items.Add("About", null, AboutCommand);
            _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            _notifyIcon.ContextMenuStrip.Items.Add("Exit", null, ExitCommand);
        }
示例#2
0
        /// <summary>
        /// build the context menu each time it opens to ensure appropriate options
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = false;
            _notifyIcon.ContextMenuStrip.Items.Clear();

            //see if we are still connected.
            if (_plexService == null)
            {
                Connect();
            }

            if (_plexService != null)// && ((ICommunicationObject)_plexService).State == CommunicationState.Opened)
            {
                var settings = Settings.Deserialize(_plexService.GetSettings());
                try
                {
                    var state = _plexService.GetStatus();
                    switch (state)
                    {
                    case PlexState.Running:
                        _notifyIcon.ContextMenuStrip.Items.Add("Open Web Manager", null, OpenManager_Click);
                        _notifyIcon.ContextMenuStrip.Items.Add("Stop Plex", null, StopPlex_Click);
                        break;

                    case PlexState.Stopped:
                        _notifyIcon.ContextMenuStrip.Items.Add("Start Plex", null, StartPlex_Click);
                        break;

                    case PlexState.Pending:
                        _notifyIcon.ContextMenuStrip.Items.Add("Restart Pending");
                        break;

                    case PlexState.Stopping:
                        _notifyIcon.ContextMenuStrip.Items.Add("Stopping");
                        break;

                    default:
                        _notifyIcon.ContextMenuStrip.Items.Add("Plex state unknown");
                        break;
                    }
                    _notifyIcon.ContextMenuStrip.Items.Add("View Logs", null, ViewLogs_Click);
                    _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
                    var auxAppsToLink = settings.AuxiliaryApplications.Where(aux => !string.IsNullOrEmpty(aux.Url)).ToList();
                    if (auxAppsToLink.Count > 0)
                    {
                        var auxAppsItem = new ToolStripMenuItem {
                            Text = "Auxiliary Applications"
                        };
                        auxAppsToLink.ForEach(aux =>
                        {
                            auxAppsItem.DropDownItems.Add(aux.Name, null, (s, a) =>
                            {
                                try
                                {
                                    Process.Start(aux.Url);
                                }
                                catch (Exception ex) { MessageBox.Show(ex.Message, "Woops!", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                            });
                        });
                        _notifyIcon.ContextMenuStrip.Items.Add(auxAppsItem);
                        _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
                    }
                    var settingsItem = _notifyIcon.ContextMenuStrip.Items.Add("Settings", null, SettingsCommand);
                    if (_settingsWindow != null)
                    {
                        settingsItem.Enabled = false;
                    }
                }
                catch
                {
                    Disconnect();
                    _notifyIcon.ContextMenuStrip.Items.Add("Unable to connect to service. Check settings");
                }
            }
            else
            {
                Disconnect();
                _notifyIcon.ContextMenuStrip.Items.Add("Unable to connect to service. Check settings");
            }
            _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            var connectionSettingsItem = _notifyIcon.ContextMenuStrip.Items.Add("Connection Settings", null, ConnectionSettingsCommand);

            if (_connectionSettingsWindow != null)
            {
                connectionSettingsItem.Enabled = false;
            }
            var aboutItem = _notifyIcon.ContextMenuStrip.Items.Add("About", null, AboutCommand);

            if (AboutWindow.Shown)
            {
                aboutItem.Enabled = false;
            }
            _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            var exitItem = _notifyIcon.ContextMenuStrip.Items.Add("Exit", null, ExitCommand);

            if (AboutWindow.Shown || _connectionSettingsWindow != null || _settingsWindow != null)
            {
                exitItem.Enabled = false;
            }
        }