/// <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");
                    }
                }
            }
        }
Example #2
0
        /// <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>
        ///     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>
        /// 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 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>
        /// 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);
            }
        }
Example #7
0
        /// <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);
            }
        }