Пример #1
0
        public BindingProcessImpl(IHost host,
                                  BindCommandArgs bindingArgs,
                                  ISolutionBindingOperation solutionBindingOperation,
                                  INuGetBindingOperation nugetBindingOperation,
                                  IUnboundProjectFinder unboundProjectFinder,
                                  IBindingConfigProvider bindingConfigProvider,
                                  SonarLintMode bindingMode,
                                  bool isFirstBinding = false)
        {
            this.host        = host ?? throw new ArgumentNullException(nameof(host));
            this.bindingArgs = bindingArgs ?? throw new ArgumentNullException(nameof(bindingArgs));
            this.solutionBindingOperation = solutionBindingOperation ?? throw new ArgumentNullException(nameof(solutionBindingOperation));
            this.NuGetBindingOperation    = nugetBindingOperation ?? throw new ArgumentNullException(nameof(nugetBindingOperation));
            this.unboundProjectFinder     = unboundProjectFinder ?? throw new ArgumentNullException(nameof(unboundProjectFinder));
            this.bindingConfigProvider    = bindingConfigProvider ?? throw new ArgumentNullException(nameof(bindingConfigProvider));
            this.bindingMode = bindingMode;

            Debug.Assert(bindingArgs.ProjectKey != null);
            Debug.Assert(bindingArgs.ProjectName != null);
            Debug.Assert(bindingArgs.Connection != null);

            this.projectSystem = this.host.GetService <IProjectSystemHelper>();
            this.projectSystem.AssertLocalServiceIsNotNull();

            this.InternalState = new BindingProcessState(isFirstBinding);
        }
        public BindingWorkflow(IHost host, BindCommandArgs bindingArgs)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            if (bindingArgs == null)
            {
                throw new ArgumentNullException(nameof(bindingArgs));
            }
            Debug.Assert(bindingArgs.ProjectKey != null);
            Debug.Assert(bindingArgs.ProjectName != null);
            Debug.Assert(bindingArgs.Connection != null);

            this.host          = host;
            this.bindingArgs   = bindingArgs;
            this.projectSystem = this.host.GetService <IProjectSystemHelper>();
            this.projectSystem.AssertLocalServiceIsNotNull();

            this.solutionBindingOperation = new SolutionBindingOperation(
                this.host,
                this.bindingArgs.Connection,
                this.bindingArgs.ProjectKey);
        }
        private void OnBind(BindCommandArgs args)
        {
            Debug.Assert(this.OnBindStatus(args));

            host.GetMefService <ITelemetryLogger>()?.ReportEvent(TelemetryEvent.BindCommandCommandCalled);

            this.workflowExecutor.BindProject(args);
        }
Пример #4
0
        void IBindingWorkflowExecutor.BindProject(BindCommandArgs bindingArgs)
        {
            var workflow = CreateBindingWorkflow(bindingArgs);

            IProgressEvents progressEvents = workflow.Run();

            Debug.Assert(progressEvents != null, "BindingWorkflow.Run returned null");
            this.SetBindingInProgress(progressEvents, bindingArgs);
        }
Пример #5
0
 private bool OnBindStatus(BindCommandArgs args)
 {
     return(args != null &&
            args.ProjectKey != null &&
            this.host.VisualStateManager.IsConnected &&
            !this.host.VisualStateManager.IsBusy &&
            VsShellUtils.IsSolutionExistsAndFullyLoaded() &&
            VsShellUtils.IsSolutionExistsAndNotBuildingAndNotDebugging() &&
            (this.projectSystemHelper.GetSolutionProjects()?.Any() ?? false));
 }
Пример #6
0
        private void OnBind(BindCommandArgs args)
        {
            Debug.Assert(this.OnBindStatus(args));

            var componentModel = host.GetService <SComponentModel, IComponentModel>();

            TelemetryLoggerAccessor.GetLogger(componentModel)?.ReportEvent(TelemetryEvent.BindCommandCommandCalled);

            this.workflowExecutor.BindProject(args);
        }
        public BindingWorkflow(IHost host,
                               BindCommandArgs bindingArgs,
                               ISolutionBindingOperation solutionBindingOperation,
                               INuGetBindingOperation nugetBindingOperation,
                               ISolutionBindingInformationProvider bindingInformationProvider,
                               bool isFirstBinding = false)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            if (bindingArgs == null)
            {
                throw new ArgumentNullException(nameof(bindingArgs));
            }
            Debug.Assert(bindingArgs.ProjectKey != null);
            Debug.Assert(bindingArgs.ProjectName != null);
            Debug.Assert(bindingArgs.Connection != null);

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

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

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

            this.host          = host;
            this.bindingArgs   = bindingArgs;
            this.projectSystem = this.host.GetService <IProjectSystemHelper>();
            this.projectSystem.AssertLocalServiceIsNotNull();

            this.solutionBindingOperation   = solutionBindingOperation;
            this.NuGetBindingOperation      = nugetBindingOperation;
            this.bindingInformationProvider = bindingInformationProvider;
            this.IsFirstBinding             = isFirstBinding;
        }
Пример #8
0
        private void OnBindingFinished(BindCommandArgs bindingArgs, bool isFinishedSuccessfully)
        {
            this.IsBindingInProgress = false;
            this.host.VisualStateManager.ClearBoundProject();

            if (isFinishedSuccessfully)
            {
                this.host.VisualStateManager.SetBoundProject(bindingArgs.Connection.ServerUri, bindingArgs.Connection.Organization?.Key, bindingArgs.ProjectKey);

                // The conflicts controller is only applicable in legacy connected mode
                // However, it is safe to call it regardless - in new connected mode it will
                // not return any conflicts.
                var conflictsController = this.host.GetService <IRuleSetConflictsController>();
                conflictsController.AssertLocalServiceIsNotNull();

                if (conflictsController.CheckForConflicts())
                {
                    // In some cases we will end up navigating to the solution explorer, this will make sure that
                    // we're back in team explorer to view the conflicts
                    this.host.GetMefService <ITeamExplorerController>()?.ShowSonarQubePage();
                }
                else
                {
                    VsShellUtils.ActivateSolutionExplorer(this.host);
                }
            }
            else
            {
                IUserNotification notifications = this.host.ActiveSection?.UserNotifications;
                if (notifications != null)
                {
                    // Create a command with a fixed argument with the help of ContextualCommandViewModel that creates proxy command for the contextual (fixed) instance and the passed in ICommand that expects it
                    var rebindCommandVM = new ContextualCommandViewModel(
                        bindingArgs,
                        new RelayCommand <BindCommandArgs>(this.OnBind, this.OnBindStatus));
                    notifications.ShowNotificationError(Strings.FailedToToBindSolution, NotificationIds.FailedToBindId, rebindCommandVM.Command);
                }
            }
        }
        internal /* for testing purposes */ IBindingWorkflow CreateBindingWorkflow(BindCommandArgs bindingArgs)
        {
            //Choose the type of binding
            var configProvider = this.host.GetService <IConfigurationProvider>();

            configProvider.AssertLocalServiceIsNotNull();

            var currentConfiguration = configProvider.GetConfiguration();

            SonarLintMode          modeToBind;
            INuGetBindingOperation nugetBindingOp;

            if (currentConfiguration.Mode == SonarLintMode.LegacyConnected)
            {
                host.Logger.WriteLine(Strings.Bind_UpdatingLegacyBinding);
                modeToBind     = SonarLintMode.LegacyConnected;
                nugetBindingOp = new NuGetBindingOperation(host, host.Logger);
            }
            else
            {
                // If we are currently in standalone then the project is being bound for the first time.
                // If we are in connected mode then the binding is being updated.
                host.Logger.WriteLine(
                    currentConfiguration.Mode == SonarLintMode.Standalone ?
                    Strings.Bind_FirstTimeBinding :
                    Strings.Bind_UpdatingNewStyleBinding);

                modeToBind     = SonarLintMode.Connected;
                nugetBindingOp = new NoOpNuGetBindingOperation(host.Logger);
            }

            var solutionBindingOp = new SolutionBindingOperation(
                host,
                bindingArgs.Connection,
                bindingArgs.ProjectKey,
                modeToBind);

            return(new BindingWorkflow(host, bindingArgs, solutionBindingOp, nugetBindingOp));
        }
Пример #10
0
        internal /*for testing purposes*/ void SetBindingInProgress(IProgressEvents progressEvents, BindCommandArgs bindingArgs)
        {
            this.OnBindingStarted();

            ProgressNotificationListener progressListener = new ProgressNotificationListener(progressEvents, this.host.Logger);

            progressListener.MessageFormat = Strings.BindingSolutionPrefixMessageFormat;

            progressEvents.RunOnFinished(result =>
            {
                progressListener.Dispose();

                this.OnBindingFinished(bindingArgs, result == ProgressControllerResult.Succeeded);
            });
        }
        internal static /* for testing purposes */ IBindingProcess CreateBindingProcess(IHost host, BindCommandArgs bindingArgs)
        {
            // Choose the type of binding
            var configProvider = host.GetService <IConfigurationProviderService>();

            configProvider.AssertLocalServiceIsNotNull();

            var currentConfiguration = configProvider.GetConfiguration();

            SonarLintMode          modeToBind;
            INuGetBindingOperation nugetBindingOp;

            // If we are currently in standalone then the project is being bound for the first time.
            // Otherwise, we are updating an existing binding
            var isFirstBinding = currentConfiguration.Mode == SonarLintMode.Standalone;

            if (currentConfiguration.Mode == SonarLintMode.LegacyConnected)
            {
                host.Logger.WriteLine(Strings.Bind_UpdatingLegacyBinding);
                modeToBind     = SonarLintMode.LegacyConnected;
                nugetBindingOp = new NuGetBindingOperation(host, host.Logger);
            }
            else
            {
                host.Logger.WriteLine(
                    isFirstBinding ?
                    Strings.Bind_FirstTimeBinding :
                    Strings.Bind_UpdatingNewStyleBinding);

                modeToBind     = SonarLintMode.Connected;
                nugetBindingOp = new NoOpNuGetBindingOperation(host.Logger);
            }

            var solutionBindingOp = new SolutionBindingOperation(
                host,
                modeToBind,
                host.Logger);

            var unboundProjectFinder = new UnboundProjectFinder(host, host.Logger);

            var cSharpVBBindingConfigProvider = new CSharpVBBindingConfigProvider(host.SonarQubeService, nugetBindingOp, host.Logger);
            var cppConfigProvider             = new CFamilyBindingConfigProvider(host.SonarQubeService, host.Logger);

            var ruleConfigProvider = new CompositeBindingConfigProvider(cSharpVBBindingConfigProvider, cppConfigProvider);
            var bindingProcess     = new BindingProcessImpl(host, bindingArgs, solutionBindingOp, nugetBindingOp, unboundProjectFinder, ruleConfigProvider, modeToBind, isFirstBinding);

            return(bindingProcess);
        }
        private void OnBind(BindCommandArgs args)
        {
            Debug.Assert(this.OnBindStatus(args));

            this.workflowExecutor.BindProject(args);
        }
Пример #13
0
        internal static /* for testing purposes */ IBindingWorkflow CreateBindingWorkflow(IHost host, BindCommandArgs bindingArgs)
        {
            //Choose the type of binding
            var configProvider = host.GetService <IConfigurationProvider>();

            configProvider.AssertLocalServiceIsNotNull();

            var currentConfiguration = configProvider.GetConfiguration();

            SonarLintMode          modeToBind;
            INuGetBindingOperation nugetBindingOp;

            // If we are currently in standalone then the project is being bound for the first time.
            // Otherwise, we are updating an existing binding
            var isFirstBinding = currentConfiguration.Mode == SonarLintMode.Standalone;

            if (currentConfiguration.Mode == SonarLintMode.LegacyConnected)
            {
                host.Logger.WriteLine(Strings.Bind_UpdatingLegacyBinding);
                modeToBind     = SonarLintMode.LegacyConnected;
                nugetBindingOp = new NuGetBindingOperation(host, host.Logger);
            }
            else
            {
                host.Logger.WriteLine(
                    isFirstBinding ?
                    Strings.Bind_FirstTimeBinding :
                    Strings.Bind_UpdatingNewStyleBinding);

                modeToBind     = SonarLintMode.Connected;
                nugetBindingOp = new NoOpNuGetBindingOperation(host.Logger);
            }

            var solutionBindingOp = new SolutionBindingOperation(
                host,
                bindingArgs.Connection,
                bindingArgs.ProjectKey,
                bindingArgs.ProjectName,
                modeToBind,
                host.Logger);

            var bindingInformationProvider = new SolutionBindingInformationProvider(host);

            return(new BindingWorkflow(host, bindingArgs, solutionBindingOp, nugetBindingOp, bindingInformationProvider, isFirstBinding));
        }