Пример #1
0
        private static ProgressControl VisualizeInHost(IProgressControlHost host)
        {
            Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");
            var progressControl = new ProgressControl();

            host.Host(progressControl);
            return(progressControl);
        }
Пример #2
0
        private void TransferState()
        {
            Debug.Assert(this.ActiveSection != null, "Not attached to any section attached");

            if (this.ActiveSection != null)
            {
                this.ActiveSection.ViewModel.State = this.VisualStateManager.ManagedState;

                IProgressControlHost progressHost = this.ActiveSection.ProgressHost;
                Debug.Assert(progressHost != null, "IProgressControlHost is expected");
                this.progressStepRunner.ChangeHost(progressHost);
            }
        }
Пример #3
0
        public static IProgressEvents StartAsync(IServiceProvider sp, IProgressControlHost host, Func <IProgressController, ProgressStepDefinition[]> stepFactory)
        {
            if (sp == null)
            {
                throw new ArgumentNullException(nameof(sp));
            }

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

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

            Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");

            // Initialize a controller and an observer
            var controller = new SequentialProgressController(sp);

            controller.Initialize(stepFactory(controller));

            IVsOutputWindowPane sonarLintPane = VsShellUtils.GetOrCreateSonarLintOutputPane(sp);

            bool logFullMessage;

#if DEBUG
            logFullMessage = true;
#else
            logFullMessage = false;
#endif
            var notifier = new VsOutputWindowPaneNotifier(sp,
                                                          sonarLintPane,
                                                          ensureOutputVisible: true,
                                                          messageFormat: Strings.UnexpectedWorkflowError,
                                                          logFullException: logFullMessage);
            controller.ErrorNotificationManager.AddNotifier(notifier);

            Observe(controller, host);
            controller.RunOnFinished(r => observedControllersMap.Remove(controller));
#pragma warning disable 4014 // We do want to start and forget. All the errors will be forwarded via the error notification manager
            controller.StartAsync();
#pragma warning restore 4014

            return(controller);
        }
        public static IProgressEvents StartAsync(IServiceProvider sp, IProgressControlHost host, Func<IProgressController, ProgressStepDefinition[]> stepFactory)
        {
            if (sp == null)
            {
                throw new ArgumentNullException(nameof(sp));
            }

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

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

            Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");

            // Initialize a controller and an observer
            var controller = new SequentialProgressController(sp);
            controller.Initialize(stepFactory(controller));

            IVsOutputWindowPane sonarLintPane = VsShellUtils.GetOrCreateSonarLintOutputPane(sp);

            bool logFullMessage;
#if DEBUG
            logFullMessage = true;
#else
            logFullMessage = false;
#endif
            var notifier = new VsOutputWindowPaneNotifier(sp,
                sonarLintPane,
                ensureOutputVisible: true,
                messageFormat: Strings.UnexpectedWorkflowError,
                logFullException: logFullMessage);
            controller.ErrorNotificationManager.AddNotifier(notifier);

            Observe(controller, host);
            controller.RunOnFinished(r => observedControllersMap.Remove(controller));
#pragma warning disable 4014 // We do want to start and forget. All the errors will be forwarded via the error notification manager
            controller.Start();
#pragma warning restore 4014

            return controller;
        }
Пример #5
0
        /// <summary>
        /// Will use the specified <paramref name="host"/> to visualize the progress of <paramref name="controller"/>
        /// </summary>
        public static ProgressObserver Observe(IProgressController controller, IProgressControlHost host)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

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

            Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");

            ProgressControl visualizer = VisualizeInHost(host);

            return(Observe(controller, visualizer));
        }
Пример #6
0
        /// <summary>
        /// Re-hosts all the current observers into the specified <paramref name="host"/>
        /// </summary>
        public static void ChangeHost(IProgressControlHost host)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");

            Lazy <ProgressControl> visualizer = new Lazy <ProgressControl>(() => VisualizeInHost(host));

            observedControllersMap.ToList().ForEach(kv =>
            {
                if (!kv.Value.IsFinished)
                {
                    ProgressControllerViewModel state = kv.Value.State;
                    kv.Value.Dispose(); // Dispose previous observer
                    observedControllersMap[kv.Key] = CreateObserver(kv.Key, visualizer.Value, state);
                }
            });
        }
Пример #7
0
 void IProgressStepRunnerWrapper.ChangeHost(IProgressControlHost host)
 {
     ProgressStepRunner.ChangeHost(host);
 }
        void IProgressStepRunnerWrapper.ChangeHost(IProgressControlHost host)
        {
            Assert.IsNotNull(host);

            this.currentHost = host;
        }
 public void AssertCurrentHost(IProgressControlHost expectedHost)
 {
     Assert.AreSame(expectedHost, this.currentHost);
 }
        void IProgressStepRunnerWrapper.ChangeHost(IProgressControlHost host)
        {
            host.Should().NotBeNull();

            this.CurrentHost = host;
        }
Пример #11
0
 public void AssertCurrentHost(IProgressControlHost expectedHost)
 {
     Assert.AreSame(expectedHost, this.currentHost);
 }
Пример #12
0
        void IProgressStepRunnerWrapper.ChangeHost(IProgressControlHost host)
        {
            Assert.IsNotNull(host);

            this.currentHost = host;
        }
        /// <summary>
        /// Will use the specified <paramref name="host"/> to visualize the progress of <paramref name="controller"/>
        /// </summary>
        public static ProgressObserver Observe(IProgressController controller, IProgressControlHost host)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

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

            Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");

            ProgressControl visualizer = VisualizeInHost(host);
            return Observe(controller, visualizer);
        }
 private static ProgressControl VisualizeInHost(IProgressControlHost host)
 {
     Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");
     var progressControl = new ProgressControl();
     host.Host(progressControl);
     return progressControl;
 }
        /// <summary>
        /// Re-hosts all the current observers into the specified <paramref name="host"/>
        /// </summary>
        public static void ChangeHost(IProgressControlHost host)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be called on the UI thread");

            Lazy<ProgressControl> visualizer = new Lazy<ProgressControl>(() => VisualizeInHost(host));
            observedControllersMap.ToList().ForEach(kv =>
            {
                if (!kv.Value.IsFinished)
                {
                    ProgressControllerViewModel state = kv.Value.State;
                    kv.Value.Dispose(); // Dispose previous observer
                    observedControllersMap[kv.Key] = CreateObserver(kv.Key, visualizer.Value, state);
                }
            });
        }