/// <summary> /// Gets or sets a value indicating whether install new plugin. /// </summary> public void OnInstallNewPlugin() { var filedialog = new OpenFileDialog { Filter = @"VSSonar Plugin|*.VSQ" }; DialogResult result = filedialog.ShowDialog(); if (result == DialogResult.OK) { if (!File.Exists(filedialog.FileName)) { UserExceptionMessageBox.ShowException("Error Choosing File, File Does not exits", null); } else { var files = this.controller.DeployPlugin(filedialog.FileName); try { if (!this.InitPluginList(this.vshelper, files)) { UserExceptionMessageBox.ShowException("Cannot Install Plugin", new Exception("Error Loading Plugin"), this.controller.GetErrorData()); } } catch (Exception ex) { Debug.WriteLine(ex.Message); UserExceptionMessageBox.ShowException( "Cannot Install Plugin", new Exception("Error Loading Plugin"), this.controller.GetErrorData()); } } } }
/// <summary> /// The on associate command. /// </summary> private void OnAssociateCommand() { try { if (this.CommandText.Equals("Browser")) { foreach (var issueobj in this.model.SelectedItems) { var issue = issueobj as Issue; if (issue == null) { continue; } var resources = this.rest.GetResourcesData(this.config, issue.Component); this.visualStudioHelper.NavigateToResource(this.config.Hostname + "/resource/index/" + resources[0].Id); } } if (this.CommandText.Equals("Visual Studio")) { this.model.OnOpenInVsCommand(this.model.SelectedItems); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Open Issue in Editor: " + ex.Message + " please check vs output log for detailed information", ex); } }
/// <summary>The update associate command.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void LocalAssociationCompleted(object sender, EventArgs e) { if (!this.model.IsConnected) { return; } var listToRemo = new List <IModelBase>(); this.keyTranslator.SetLookupType(KeyLookupType.Invalid); if (string.IsNullOrEmpty(this.OpenSolutionPath)) { this.keyTranslator.SetProjectKeyAndBaseDir(this.AssociatedProject.Key, this.OpenSolutionPath, this.AssociatedProject.BranchName, ""); } else { this.keyTranslator.SetProjectKeyAndBaseDir(this.AssociatedProject.Key, this.OpenSolutionPath, this.AssociatedProject.BranchName, Path.Combine(this.OpenSolutionPath, this.OpenSolutionName)); } try { this.Profile = this.localAnalyserModule.GetProfile(this.AssociatedProject); } catch (Exception ex) { UserExceptionMessageBox.ShowException("Failed to retrieve Profile : Check Log and report : " + ex.Message, ex); return; } // sync data in plugins this.pluginManager.AssociateWithNewProject( this.AssociatedProject, this.OpenSolutionPath, this.sourcecontrol, this.Profile, this.vsVersion); foreach (IModelBase model in modelPool) { try { model.AssociateWithNewProject( this.AssociatedProject, this.OpenSolutionPath, this.sourcecontrol, this.Profile, this.vsVersion); } catch (Exception ex) { Debug.WriteLine(ex.Message); listToRemo.Add(model); } } foreach (var item in listToRemo) { modelPool.Remove(item); } }
/// <summary> /// The on open source dir command. /// </summary> private void OnOpenSourceDirCommand() { var filedialog = new OpenFileDialog { Filter = @"visual studio solution|*.sln" }; DialogResult result = filedialog.ShowDialog(); if (result == DialogResult.OK) { if (File.Exists(filedialog.FileName)) { try { this.notificationManager.AssociateProjectToSolution( Path.GetFileName(filedialog.FileName), Directory.GetParent(filedialog.FileName).ToString()); } catch (Exception ex) { UserExceptionMessageBox.ShowException(@"Could Not Associate Solution With: " + ex.Message, ex); } } else { UserExceptionMessageBox.ShowException(@"Error Choosing File, File Does not exits", null); } } }
/// <summary> /// The on test and save password. /// </summary> /// <param name="obj"> /// The obj. /// </param> private void OnTestAndSavePassword(object obj) { if (string.IsNullOrEmpty(this.ServerAddress)) { this.StatusMessage = "Failed: Address not set"; return; } var passwordBox = obj as PasswordBox; if (passwordBox != null) { try { string password = passwordBox.Password; AuthtenticationHelper.ResetConnection(); if (AuthtenticationHelper.EstablishAConnection(this.restService, this.ServerAddress.TrimEnd('/'), this.UserName, password)) { this.StatusMessage = "Authenticated"; this.SetCredentials(this.UserName, password); } else { this.StatusMessage = "Wrong Credentials"; } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Authenticate", ex); } } }
/// <summary> /// Called when [install new DLL command]. /// </summary> private void OnInstallNewDllCommand() { using (var filedialog = new OpenFileDialog { InitialDirectory = this.model.SourceDir, Filter = @"dlls|*.dll", Title = "Select dll available in project folder." }) { DialogResult result = filedialog.ShowDialog(); if (result == DialogResult.OK) { if (!File.Exists(filedialog.FileName)) { UserExceptionMessageBox.ShowException("Error Choosing File, File Does not exits", null); return; } if (!this.model.VerifyExistenceOfRoslynPlugin()) { MessageDisplayBox.DisplayMessage( "Adding new diagnostics analyzers requires Roslyn plugin installed in your SonarQube server." + "Administration rights, Administer Quality Profiles and Gates and Provision Projects permissions must be available to user.", helpurl: "https://visualstudiogallery.msdn.microsoft.com/7fc312c3-f1ab-49f8-b286-dbf7fff37305"); return; } if (this.model.AddNewRoslynPack(filedialog.FileName, true)) { this.SyncDiagInView(); MessageDisplayBox.DisplayMessage( "Rules have been created in SonarQube. Please use tools > sqale editor to enabled them or use the Roslyn Plugin to automatically sync those against your project. ", helpurl: "https://visualstudiogallery.msdn.microsoft.com/7fc312c3-f1ab-49f8-b286-dbf7fff37305"); } } } }
/// <summary> /// The initialize. /// </summary> protected override void Initialize() { try { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this)); base.Initialize(); this.SetupMenuCommands(); this.dte2 = (DTE2)GetGlobalService(typeof(DTE)); if (this.dte2 == null) { return; } try { this.visualStudioInterface = new VsPropertiesHelper(this.dte2, this); this.visualStudioInterface.WriteToVisualStudioOutput(DateTime.Now + " : VsSonarExtensionPackage Initialize"); this.VsEvents = new VsEvents(this.visualStudioInterface, this.dte2, this); var bar = this.GetService(typeof(SVsStatusbar)) as IVsStatusbar; this.StatusBar = new VSSStatusBar(bar, this.dte2); var extensionRunningPath = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty).ToString(); var uniqueId = this.dte2.Version; if (extensionRunningPath.ToLower().Contains(this.dte2.Version + "exp")) { uniqueId += "Exp"; } SonarQubeViewModelFactory.StartupModelWithVsVersion(uniqueId).InitModelFromPackageInitialization(this.visualStudioInterface, this.StatusBar, this, this.AssemblyDirectory); this.CloseToolsWindows(); this.OutputGuid = "CDA8E85D-C469-4855-878B-0E778CD0DD" + int.Parse(uniqueId.Split('.')[0]).ToString(CultureInfo.InvariantCulture); this.StartOutputWindow(this.OutputGuid); // start listening SonarQubeViewModelFactory.SQViewModel.PluginRequest += this.LoadPluginIntoNewToolWindow; this.StartSolutionListeners(this.visualStudioInterface); // configure colours DColor defaultBackground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey); DColor defaultForeground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey); SonarQubeViewModelFactory.SQViewModel.UpdateTheme(ToMediaColor(defaultBackground), ToMediaColor(defaultForeground)); } catch (Exception ex) { UserExceptionMessageBox.ShowException("SonarQubeExtension not able to start", ex); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Extension Failed to Start", ex); throw; } }
/// <summary>Generates a resource name from a given solution, it will bring Associtation View /// in case automatic associations is not possible</summary> /// <param name="solutionName">The solution Name.</param> /// <param name="solutionPath">The solution Path.</param> /// <returns>The <see cref="Resource"/>.</returns> public Resource GetResourceForSolution(string solutionName, string solutionPath) { if (AuthtenticationHelper.AuthToken == null) { return(null); } try { var prop = this.configurationHelper.ReadSetting( Context.GlobalPropsId, Path.Combine(solutionPath, solutionName), "PROJECTKEY"); foreach (var project in this.associationViewModel.AvailableProjects) { if (project.Key.Equals(prop.Value)) { return(project); } } try { return(this.sonarService.GetResourcesData(AuthtenticationHelper.AuthToken, prop.Value)[0]); } catch (Exception ex) { UserExceptionMessageBox.ShowException("Associated Project does not exist in server, please configure association", ex); return(null); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } var sourceKey = VsSonarUtils.GetProjectKey(solutionPath); try { return(string.IsNullOrEmpty(sourceKey) ? null : this.sonarService.GetResourcesData(AuthtenticationHelper.AuthToken, sourceKey)[0]); } catch (Exception ex) { Debug.WriteLine(ex.Message); sourceKey = sourceKey + ":" + this.SourceControl.GetBranch().Replace("/", "_"); try { return(string.IsNullOrEmpty(sourceKey) ? null : this.sonarService.GetResourcesData(AuthtenticationHelper.AuthToken, sourceKey)[0]); } catch (Exception exceptionBranch) { Debug.WriteLine(exceptionBranch.Message); return(null); } } }
/// <summary> /// The on associate command. /// </summary> private void OnAssociateCommand() { try { if (this.CommandText.Equals("Browser")) { if (this.model.SelectedItems == null) { var resources = this.rest.GetResourcesData(AuthtenticationHelper.AuthToken, this.model.SelectedIssue.Component); this.visualStudioHelper.NavigateToResource(AuthtenticationHelper.AuthToken.Hostname + "/resource/index/" + resources[0].Id); } else { foreach (var issueobj in this.model.SelectedItems) { var issue = issueobj as Issue; if (issue == null) { continue; } if (AuthtenticationHelper.AuthToken.SonarVersion < 6.3) { var resources = this.rest.GetResourcesData(AuthtenticationHelper.AuthToken, issue.Component); this.visualStudioHelper.NavigateToResource(AuthtenticationHelper.AuthToken.Hostname + "/resource/index/" + resources[0].Id); } else { this.visualStudioHelper.NavigateToResource(AuthtenticationHelper.AuthToken.Hostname + "/component?id=" + issue.Component + "&line=" + issue.Line); } } } } if (this.CommandText.Equals("Visual Studio")) { if (this.model.SelectedItems == null) { var listOfIssues = new List <Issue>(); listOfIssues.Add(this.model.SelectedIssue); this.model.OnOpenInVsCommand(listOfIssues); } else { this.model.OnOpenInVsCommand(this.model.SelectedItems); } } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Open Issue in Editor: " + ex.Message + " please check vs output log for detailed information", ex); } }
/// <summary> /// The update local issues in view. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void UpdateLocalIssues(object sender, EventArgs e) { this.CanRunAnalysis = true; this.notificationManager.EndedWorking(); if (this.PermissionsAreNotAvailable) { MessageBox.Show("You're not authorized to execute a dry run analysis. Please contact your SonarQube administrator."); return; } try { var exceptionMsg = (LocalAnalysisEventArgs)e; if (exceptionMsg != null && exceptionMsg.Ex != null) { this.OnSelectedViewChanged(); this.IssuesGridView.Issues.Clear(); UserExceptionMessageBox.ShowException("Analysis Ended: " + exceptionMsg.ErrorMessage, exceptionMsg.Ex, exceptionMsg.Ex.StackTrace); return; } } catch (Exception ex) { this.OnSelectedViewChanged(); this.IssuesGridView.Issues.Clear(); UserExceptionMessageBox.ShowException("Analysis Ended: ", ex, ex.StackTrace); } try { if (Application.Current != null) { Application.Current.Dispatcher.Invoke( () => { this.IssuesGridView.UpdateIssues( this.localAnalyserModule.GetIssues( AuthtenticationHelper.AuthToken, this.associatedProject)); this.OnSelectedViewChanged(); }); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Analysis Finish", ex, "Cannot retrieve Any Issues From Analysis. For the installed plugins"); } this.IssuesGridView.RefreshStatistics(); }
/// <summary> /// Gets or sets a value indicating whether browse for java trigger. /// </summary> public void OnBrowseForJavaTrigger() { var filedialog = new OpenFileDialog { Filter = @"Java executable|java.exe" }; DialogResult result = filedialog.ShowDialog(); if (result == DialogResult.OK) { if (File.Exists(filedialog.FileName)) { this.JavaBinary = filedialog.FileName; } else { UserExceptionMessageBox.ShowException(@"Error Choosing File, File Does not exits", null); } } }
/// <summary> /// Called when [install new DLL command]. /// </summary> private void OnInstallNewDllCommand() { var filedialog = new OpenFileDialog { Filter = @"dlls|*.dll" }; DialogResult result = filedialog.ShowDialog(); if (result == DialogResult.OK) { if (!File.Exists(filedialog.FileName)) { UserExceptionMessageBox.ShowException("Error Choosing File, File Does not exits", null); } else { this.model.AddNewRoslynPack(filedialog.FileName); } } }
/// <summary> /// Gets or sets a value indicating whether browse for sonar runner qube trigger. /// </summary> public void OnBrowseForSonarRunnerQubeTrigger() { var filedialog = new OpenFileDialog { Filter = @"SonarQube executable|sonar-runner.bat" }; DialogResult result = filedialog.ShowDialog(); if (result == DialogResult.OK) { if (File.Exists(filedialog.FileName)) { this.SonarQubeBinary = filedialog.FileName; } else { UserExceptionMessageBox.ShowException(@"Error Choosing File, File Does not exits", null); } } }
/// <summary> /// Starts the output window. /// </summary> /// <param name="guid">The unique identifier.</param> private void StartOutputWindow(string guid) { try { var outWindow = GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow; var customGuid = new Guid(guid); if (outWindow != null) { outWindow.CreatePane(ref customGuid, "VSSonarQube Output", 1, 1); IVsOutputWindowPane customPane; outWindow.GetPane(ref customGuid, out customPane); ((VsPropertiesHelper)this.visualStudioInterface).CustomPane = customPane; ((VsPropertiesHelper)this.visualStudioInterface).CustomPane.Activate(); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("VsSonarExtensionPackage Failed Create Output Window: " + guid, ex); } }
/// <summary>The associate solution with sonar project.</summary> /// <param name="solutionName">The solution Name.</param> /// <param name="solutionPath">The solution Path.</param> /// <returns>The <see cref="Resource"/>.</returns> private Resource AssociateSolutionWithSonarProject(string solutionName, string solutionPath) { if (AuthtenticationHelper.AuthToken == null) { return(null); } try { var prop = this.configurationHelper.ReadSetting( Context.GlobalPropsId, Path.Combine(solutionPath, solutionName), "PROJECTKEY"); try { return (this.SonarRestConnector.GetResourcesData( AuthtenticationHelper.AuthToken, prop.Value)[0]); } catch (Exception ex) { UserExceptionMessageBox.ShowException("Associated Project does not exist in server, please configure association", ex); return(null); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } var sourceKey = VsSonarUtils.GetProjectKey(solutionPath); return(string.IsNullOrEmpty(sourceKey) ? null : this.SonarRestConnector.GetResourcesData( AuthtenticationHelper.AuthToken, sourceKey)[0]); }
/// <summary> /// Called when [attache to issue tracker]. /// </summary> private void OnAttachToIssueTracker() { if (this.model.SelectedItems == null || this.model.SelectedItems.Count == 0) { return; } try { if (this.CommandText.Equals("new issue and attach")) { var issues = this.model.SelectedItems.Cast <Issue>().ToList(); string id = string.Empty; var replydata = this.issueTrackerPlugin.AttachToNewDefect(issues, out id); // update issues foreach (var issue in issues) { issue.IssueTrackerId = id; } if (string.IsNullOrEmpty(replydata)) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to create defect" }); return; } var builder = new StringBuilder(); builder.AppendLine(CommentMessageForIssue + id); builder.AppendLine(replydata); this.rest.CommentOnIssues(this.config, issues, builder.ToString()); } if (this.CommandText.Equals("attach to existent")) { var id = PromptUserData.Prompt("Enter Item Id", "Issue Tracker Id"); if (string.IsNullOrEmpty(id)) { return; } try { var issues = this.model.SelectedItems.Cast <Issue>().ToList(); var replydata = this.issueTrackerPlugin.AttachToExistentDefect(issues, id); if (string.IsNullOrEmpty(replydata)) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to attach to defect" }); return; } // update issues foreach (var issue in issues) { issue.IssueTrackerId = id; } var builder = new StringBuilder(); builder.AppendLine(CommentMessageForIssue + id); builder.AppendLine(replydata); this.rest.CommentOnIssues(this.config, issues, builder.ToString()); } catch (Exception ex) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to attach to defect: " + ex.Message }); this.manager.ReportException(ex); return; } } if (this.CommandText.Equals("show info")) { var id = this.parent.CommandText; if (!this.parent.parent.defectCache.ContainsKey(id)) { try { var defect = this.issueTrackerPlugin.GetDefect(id); this.parent.parent.defectCache.Add(id, defect); } catch (Exception ex) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to get info for defect: " + ex.Message }); this.manager.ReportException(ex); return; } } var item = this.parent.parent.defectCache[id]; string message = string.Format("Summary:\t\t {0}\r\nStatus:\t\t {1}\r\nId:\t {2}\r\n", item.Summary, item.Status, item.Id); MessageDisplayBox.DisplayMessage(message, string.Empty); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Perform Operation in Plan: " + ex.Message + " please check vs output log for detailed information", ex); } }
/// <summary> /// The on associate command. /// </summary> private void OnPlanCommand() { try { if (this.CommandText.Equals("Associate to new plan")) { var availablePlans = this.rest.GetAvailableActionPlan(this.config, this.associatedProject.Key); var newPlan = PromptUserForNewPlan.Prompt(availablePlans); if (newPlan == null) { return; } this.AssociateToNewPlan(availablePlans, newPlan); foreach (var issue in this.model.SelectedItems) { var issueData = issue as Issue; issueData.ActionPlanName = newPlan.Name; issueData.ActionPlan = newPlan.Key; } this.ReloadPlanData(this.parent); } else { if (this.CommandText.Equals("Unplan")) { this.UnPlanIssues(); foreach (var issue in this.model.SelectedItems) { (issue as Issue).ActionPlanName = string.Empty; (issue as Issue).ActionPlan = Guid.Empty; } } else { var plans = this.rest.GetAvailableActionPlan(this.config, this.associatedProject.Key); foreach (var plan in plans) { if (plan.Name.Equals(this.CommandText)) { this.AttachToExistentPlan(plan); foreach (var issue in this.model.SelectedItems) { (issue as Issue).ActionPlanName = plan.Name; (issue as Issue).ActionPlan = plan.Key; } return; } } } } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Perform Operation in Plan: " + ex.Message + " please check vs output log for detailed information", ex); } }
/// <summary> /// The initialize. /// </summary> protected override void Initialize() { try { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this)); base.Initialize(); this.SetupMenuCommands(); this.dte2 = (DTE2)GetGlobalService(typeof(DTE)); if (this.dte2 == null) { return; } try { this.visualStudioInterface = new VsPropertiesHelper(this.dte2, this); this.VsEvents = new VsEvents(this.visualStudioInterface, this.dte2, this); var bar = this.GetService(typeof(SVsStatusbar)) as IVsStatusbar; this.StatusBar = new VSSStatusBar(bar, this.dte2); var extensionRunningPath = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty).ToString(); var uniqueId = this.dte2.Version; if (extensionRunningPath.ToLower().Contains(this.dte2.Version + "exp")) { uniqueId += "Exp"; } SonarQubeViewModelFactory.StartupModelWithVsVersion(uniqueId).InitModelFromPackageInitialization(this.visualStudioInterface, this.StatusBar, this, this.AssemblyDirectory); DColor defaultBackground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey); DColor defaultForeground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey); SonarQubeViewModelFactory.SQViewModel.UpdateTheme(ToMediaColor(defaultBackground), ToMediaColor(defaultForeground)); // force analysis to come to vsix var i = 0; var data = string.Empty; foreach (var item in SonarQubeViewModelFactory.StartupModelWithVsVersion(uniqueId).VSonarQubeOptionsViewData.RoslynModel.ExtensionDiagnostics) { i += item.Value.AvailableChecks.Count; foreach (var check in item.Value.AvailableChecks) { DiagnosticAnalyzer analyser = check; data += analyser.ToString(); } } this.StatusBar.DisplayMessage("checks : " + i); try { var outWindow = GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow; var customGuid = new Guid("CDA8E85D-C469-4855-878B-0E778CD0DD53"); if (outWindow != null) { outWindow.CreatePane(ref customGuid, "VSSonarQube Output", 1, 1); IVsOutputWindowPane customPane; outWindow.GetPane(ref customGuid, out customPane); ((VsPropertiesHelper)this.visualStudioInterface).CustomPane = customPane; ((VsPropertiesHelper)this.visualStudioInterface).CustomPane.Activate(); } SonarQubeViewModelFactory.SQViewModel.PluginRequest += this.LoadPluginIntoNewToolWindow; this.CloseToolWindow(); this.StartSolutionListeners(this.visualStudioInterface); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("SonarQubeExtension not able to start", ex); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Extension Failed to Start", ex); throw; } }
/// <summary> /// The on associate command. /// </summary> private void OnAssociateCommand() { try { if (this.CommandText.Equals("to user")) { string comment = string.Empty; var users = this.rest.GetUserList(this.config); var user = PromptForAssignUser.Prompt("Choose user to assign", "User selection", users, out comment); if (user == null) { return; } using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { var issues = this.model.SelectedItems; var issuesToAssign = new List <Issue>(); foreach (var issue in issues) { issuesToAssign.Add(issue as Issue); } this.rest.AssignIssuesToUser(this.config, issuesToAssign, user, "Assigned in VSSonarExtension: " + comment); this.model.RefreshView(); }; bw.RunWorkerAsync(); } } if (this.CommandText.Equals("to me")) { using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { var users = this.rest.GetUserList(this.config); var issues = this.model.SelectedItems; var issuesToAssign = new List <Issue>(); foreach (var issue in issues) { issuesToAssign.Add(issue as Issue); } this.AssignIssueToLogin(users, this.config.Username, issuesToAssign); this.model.RefreshView(); }; bw.RunWorkerAsync(); } } if (this.CommandText.Equals("assign to author")) { using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { var users = this.rest.GetUserList(this.config); var issues = this.model.SelectedItems; foreach (var issue in issues) { this.AssignIssueToAuthor(users, issue as Issue); } this.model.RefreshView(); }; bw.RunWorkerAsync(); } } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Modify Status Of Issues", ex); } }
/// <summary> /// The on associate command. /// </summary> private void OnPlanCommand() { try { if (this.CommandText.Equals("Associate to new plan")) { var availablePlans = this.rest.GetAvailableActionPlan(this.config, this.associatedProject.Key); var newPlan = PromptUserForNewPlan.Prompt(availablePlans); if (newPlan == null) { return; } foreach (var existentPlan in availablePlans) { if (existentPlan.Name.Equals(newPlan)) { var associatedWithExistent = QuestionUser.GetInput("Plan exists already, do you want to associate with current plan?"); if (associatedWithExistent) { var replies = this.rest.PlanIssues(this.config, this.model.SelectedItems, existentPlan.Key.ToString()); foreach (var itemreply in replies) { this.manager.ReportMessage(new Message() { Data = "Plan Operation Result: " + itemreply.Key + " : " + itemreply.Value }); } } return; } } try { var plan = this.rest.CreateNewPlan(this.config, this.associatedProject.Key, newPlan); var replies = this.rest.PlanIssues(this.config, this.model.SelectedItems, plan.Key.ToString()); foreach (var itemreply in replies) { manager.ReportMessage(new Message() { Data = "Plan Operation Result: " + itemreply.Key + " : " + itemreply.Value }); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Create Plan, Make sure you have permissions", ex); } } else { if (this.CommandText.Equals("Unplan")) { var replies = this.rest.UnPlanIssues(this.config, this.model.SelectedItems); foreach (var itemreply in replies) { this.manager.ReportMessage(new Message() { Data = "Unplan Operation Result: " + itemreply.Key + " : " + itemreply.Value }); } } else { var plans = this.rest.GetAvailableActionPlan(this.config, this.associatedProject.Key); foreach (var plan in plans) { if (plan.Name.Equals(this.CommandText)) { var replies = this.rest.PlanIssues(this.config, this.model.SelectedItems, plan.Key.ToString()); foreach (var itemreply in replies) { this.manager.ReportMessage(new Message() { Data = "Plan Operation Result: " + itemreply.Key + " : " + itemreply.Value }); } return; } } } } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Perform Operation in Plan: " + ex.Message + " please check vs output log for detailed information", ex); } }
/// <summary> /// The on associate command. /// </summary> private void OnAssociateCommand() { try { if (this.CommandText.Equals("False Positive")) { using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { this.manager.StartedWorking("Marking Issues as False Posiive"); var replies = this.rest.MarkIssuesAsFalsePositive(this.config, this.model.SelectedItems, string.Empty); this.VerifyChangeStatusReplies(replies, "Mark Issues as False Positive"); this.model.RefreshView(); }; bw.RunWorkerAsync(); } } if (this.CommandText.Equals("Confirm")) { using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { this.manager.StartedWorking("Confirming Issues"); var replies = this.rest.ConfirmIssues(this.config, this.model.SelectedItems, string.Empty); this.VerifyChangeStatusReplies(replies, "Confirm Issues"); this.model.RefreshView(); }; bw.RunWorkerAsync(); } } if (this.CommandText.Equals("Fix")) { using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { this.manager.StartedWorking("Marking issues as fixed"); var replies = this.rest.ResolveIssues(this.config, this.model.SelectedItems, string.Empty); this.VerifyChangeStatusReplies(replies, "Mark Issues As Fixed"); this.model.RefreshView(); }; bw.RunWorkerAsync(); } } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Modify Status Of Issues", ex); } }
/// <summary> /// The on associate command. /// </summary> private void OnAssociateCommand() { try { if (this.CommandText.Equals("assign tag")) { string newtag = string.Empty; var tags = this.rest.GetAvailableTags(AuthtenticationHelper.AuthToken); var seletectTag = PromptForTagIssue.Prompt("Choose tag to assign", "Tag selection", tags, out newtag); var tagsToApply = new List <string>(); if (!string.IsNullOrEmpty(newtag)) { tagsToApply.Add(newtag); } if (!string.IsNullOrEmpty(seletectTag)) { tagsToApply.Add(seletectTag); } if (tagsToApply.Count == 0) { return; } using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { var issues = this.model.SelectedItems; var issuesToAssign = new List <Issue>(); foreach (Issue issue in issues) { var finalTags = new List <string>(); finalTags.AddRange(tagsToApply); foreach (var tag in issue.Tags) { finalTags.Add(tag); } this.manager.ReportMessage(new Message { Id = "AssignTagMenu", Data = "Assign tags:" + this.rest.SetIssueTags(AuthtenticationHelper.AuthToken, issue as Issue, finalTags) }); foreach (var tag in finalTags) { if (!issue.Tags.Contains(tag)) { issue.Tags.Add(tag); } } } this.model.RefreshView(); }; bw.RunWorkerAsync(); } } if (this.CommandText.Equals("remove tags")) { var issues = this.model.SelectedItems; var listOfUniqueTags = new SortedSet <string>(); var uniqueTags = ""; foreach (Issue issue in issues) { foreach (var item in issue.Tags) { if (!listOfUniqueTags.Contains(item)) { listOfUniqueTags.Add(item); uniqueTags = uniqueTags + item + ","; } } } string newtag = string.Empty; var tags = this.rest.GetAvailableTags(AuthtenticationHelper.AuthToken); var seletectTag = PromptForTagIssue.Prompt("Choose tag to remove", "Tag selection", tags, out newtag, uniqueTags.TrimEnd(',')); var tagsToRemove = new List <string>(); if (!string.IsNullOrEmpty(newtag)) { tagsToRemove.AddRange(newtag.Split(',').ToList()); } if (!string.IsNullOrEmpty(seletectTag)) { tagsToRemove.Add(seletectTag); } if (tagsToRemove.Count == 0) { return; } using (var bw = new BackgroundWorker { WorkerReportsProgress = false }) { bw.RunWorkerCompleted += delegate { Application.Current.Dispatcher.Invoke(delegate { this.manager.EndedWorking(); }); }; bw.DoWork += delegate { var issuesToAssign = new List <Issue>(); foreach (Issue issue in issues) { var finalTags = new List <string>(); foreach (var tag in issue.Tags) { bool inList = false; foreach (var item in tagsToRemove) { if (tag.Equals(item)) { inList = true; } } if (!inList) { finalTags.Add(tag); } } this.manager.ReportMessage(new Message { Id = "AssignTagMenu", Data = "Assign tags:" + this.rest.SetIssueTags(AuthtenticationHelper.AuthToken, issue as Issue, finalTags) }); issue.Tags.Clear(); foreach (var tag in finalTags) { issue.Tags.Add(tag); } } this.model.RefreshView(); }; bw.RunWorkerAsync(); } } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Modify Tags on Issues", ex); } }