Пример #1
0
        /// <summary>
        /// Event handler triggered when the menu item is clicked.
        /// </summary>
        /// <param name="sender">The object which triggered the event.</param>
        /// <param name="e">The event arguments.</param>
        private void RunAsMenuItem_Click(object sender, System.EventArgs e)
        {
            // Obtain a list of all selected entries to execute and loop through them.
            PwEntry[] selectedEntries = this.mainWindow.GetSelectedEntries();

            // If there are no entries (the array is null), just return as we
            // probably entered this through the keyboard shotcut event.
            if (selectedEntries == null)
            {
                return;
            }

            // TODO: Add confirmation when executing more than one application.

            foreach (PwEntry entry in selectedEntries)
            {
                PasswordEntryManager entryManager = new PasswordEntryManager(this.mainWindow.ActiveDatabase, entry);

                try
                {
                    // Create and run an executor for the password entry.
                    ApplicationExecutor executor = new ApplicationExecutor(entryManager);
                    executor.Run();
                }
                catch (ApplicationExecutionException ex)
                {
                    // If there was an error, display a suitable error message.
                    string errorMessage = string.Concat(
                        "Unable to execute application for password entry '", entryManager.GetTitle(), "':",
                        Environment.NewLine,
                        Environment.NewLine,
                        ex.Message);

                    MessageBox.Show(
                        this.mainWindow,
                        errorMessage,
                        "Run As Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
        }