Exemple #1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var menuCommand = (MenuCommand)sender;

            // Clear Sarif Result command should be function no matter if any selected item
            IEnumerable <SarifErrorListItem> selectedItems = this.selectionService.SelectedItems;

            if ((selectedItems == null || !selectedItems.Any()) &&
                menuCommand.CommandID.ID != ClearSarifResultsCommandId)
            {
                return;
            }

            switch (menuCommand.CommandID.ID)
            {
            case ClearSarifResultsCommandId:
                ErrorListService.CleanAllErrors();
                break;

            case UsefulResultCommandId:
                var feedback = new FeedbackModel(
                    selectedItems.GetCombinedRuleIds(),
                    selectedItems.GetCombinedToolNames(),
                    selectedItems.GetCombinedToolVersions(),
                    selectedItems.GetCombinedSnippets(),
                    FeedbackType.UsefulResult,
                    null,
                    CodeAnalysisResultManager.Instance.GetPartitionedLog(selectedItems));
                ErrorListService.SendFeedback(feedback);
                break;

            case FalsePositiveResultCommandId:
            case NonActionableResultCommandId:
            case LowValueResultCommandId:
            case NonShippingCodeResultCommandId:
            case OtherResultCommandId:
                DisplayFeedbackDialog(menuCommand.CommandID.ID, selectedItems);
                break;

            case SuppressResultCommandId:
                SuppressResults(selectedItems);
                break;

            default:
                // Unrecognized command; do nothing.
                break;
            }
        }