<commit_before>//-----------------------------------------------------------------------
// <copyright file="BindingWorkflow.cs" company="SonarSource SA and Microsoft Corporation">
//   Copyright (c) SonarSource SA and Microsoft Corporation.  All rights reserved.
//   Licensed under the MIT License. See License.txt in the project root for license information.
// </copyright>
//-----------------------------------------------------------------------

using Microsoft.Alm.Authentication;
using Microsoft.VisualStudio.CodeAnalysis.RuleSets;
using SonarLint.VisualStudio.Integration.Persistence;
using SonarLint.VisualStudio.Integration.Progress;
using SonarLint.VisualStudio.Integration.Resources;
using SonarLint.VisualStudio.Integration.Service;
using SonarLint.VisualStudio.Integration.Service.DataModel;
using SonarLint.VisualStudio.Integration.TeamExplorer;
using SonarLint.VisualStudio.Progress.Controller;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;

namespace SonarLint.VisualStudio.Integration.Binding
{
    /// <summary>
    /// Workflow execution for the bind command
    /// </summary>
    internal class BindingWorkflow
    {
        private readonly BindCommand owner;
        private readonly ProjectInformation project;
        private readonly IProjectSystemHelper projectSystemHelper;
        private readonly IBindingOperation solutionBindingOperation;
        private readonly ISolutionRuleStore solutionRuleStore;

        internal readonly Dictionary<string, RuleSetGroup> LanguageToGroupMapping = new Dictionary<string, RuleSetGroup>
        {
            {SonarQubeServiceWrapper.CSharpLanguage, RuleSetGroup.CSharp },
            {SonarQubeServiceWrapper.VBLanguage, RuleSetGroup.VB }
        };

        public BindingWorkflow(BindCommand owner, ProjectInformation project)
            : this(owner, project, null, null, null)
        {

        }

        internal /*for testing purposes*/ BindingWorkflow(BindCommand owner, ProjectInformation project, IProjectSystemHelper projectSystemHelper, IBindingOperation solutionBindingOperation, ISolutionRuleStore solutionRuleStore)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            this.owner = owner;
            this.project = project;
            this.projectSystemHelper = projectSystemHelper ?? new ProjectSystemHelper(this.owner.ServiceProvider);

            Lazy<SolutionBindingOperation> solutionBindingOperationInstance = new Lazy<SolutionBindingOperation>(
                () => new SolutionBindingOperation(
                    this.owner.ServiceProvider,
                    this.projectSystemHelper,
                    this.project.Key));

            this.solutionBindingOperation = solutionBindingOperation ?? solutionBindingOperationInstance.Value;
            this.solutionRuleStore = solutionRuleStore ?? solutionBindingOperationInstance.Value;
        }

        #region Workflow state

        public Dictionary<RuleSetGroup, RuleSet> Rulesets
        {
            get;
        } = new Dictionary<RuleSetGroup, RuleSet>();

        public List<NuGetPackageInfo> NuGetPackages
        {
            get;
        } = new List<NuGetPackageInfo>();
<commit_msg>Address Matthew's comment<commit_after>//-----------------------------------------------------------------------
// <copyright file="BindingWorkflow.cs" company="SonarSource SA and Microsoft Corporation">
//   Copyright (c) SonarSource SA and Microsoft Corporation.  All rights reserved.
//   Licensed under the MIT License. See License.txt in the project root for license information.
// </copyright>
//-----------------------------------------------------------------------

using Microsoft.Alm.Authentication;
using Microsoft.VisualStudio.CodeAnalysis.RuleSets;
using SonarLint.VisualStudio.Integration.Persistence;
using SonarLint.VisualStudio.Integration.Progress;
using SonarLint.VisualStudio.Integration.Resources;
using SonarLint.VisualStudio.Integration.Service;
using SonarLint.VisualStudio.Integration.Service.DataModel;
using SonarLint.VisualStudio.Integration.TeamExplorer;
using SonarLint.VisualStudio.Progress.Controller;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;

namespace SonarLint.VisualStudio.Integration.Binding
{
    /// <summary>
    /// Workflow execution for the bind command
    /// </summary>
    internal class BindingWorkflow
    {
        private readonly BindCommand owner;
        private readonly ProjectInformation project;
        private readonly IProjectSystemHelper projectSystemHelper;
        private readonly IBindingOperation solutionBindingOperation;
        private readonly ISolutionRuleStore solutionRuleStore;

        internal readonly Dictionary<string, RuleSetGroup> LanguageToGroupMapping = new Dictionary<string, RuleSetGroup>
        {
            {SonarQubeServiceWrapper.CSharpLanguage, RuleSetGroup.CSharp },
            {SonarQubeServiceWrapper.VBLanguage, RuleSetGroup.VB }
        };

        public BindingWorkflow(BindCommand owner, ProjectInformation project)
            : this(owner, project, null, null, null)
        {

        }

        internal /*for testing purposes*/ BindingWorkflow(BindCommand owner, ProjectInformation project, IProjectSystemHelper projectSystemHelper, IBindingOperation solutionBindingOperation, ISolutionRuleStore solutionRuleStore)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            this.owner = owner;
            this.project = project;
            this.projectSystemHelper = projectSystemHelper ?? new ProjectSystemHelper(this.owner.ServiceProvider);

            // This instance will be "wasted" only when created for testing purposes
            var solutionBinding = new SolutionBindingOperation(
                    this.owner.ServiceProvider,
                    this.projectSystemHelper,
                    this.project.Key);

            this.solutionBindingOperation = solutionBindingOperation ?? solutionBinding;
            this.solutionRuleStore = solutionRuleStore ?? solutionBinding;
        }

        #region Workflow state

        public Dictionary<RuleSetGroup, RuleSet> Rulesets
        {
            get;
        } = new Dictionary<RuleSetGroup, RuleSet>();

        public List<NuGetPackageInfo> NuGetPackages
        {
            get;
        } = new List<NuGetPackageInfo>();

{'fraction_non_alphanumeric': 0.1114475201845444, 'fraction_numerical': 0.0, 'mean_word_length': 2.5447112927950943, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '241067', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1560, 'n_words': 383}