Exemplo n.º 1
0
        /// <summary>
        /// Runs an asynchronious operation using a STA thread
        /// </summary>
        /// <param name="workerParams"></param>
        /// <param name="work"></param>
        /// <param name="completeHandler"></param>
        public static void RunSTA(ProgressWorkerParams workerParams, Action <IProgressVisualizer> work, Action completeHandler)
        {
            if (work == null)
            {
                throw new ArgumentNullException("work");
            }

            IProgressVisualizer progressVisualizer = null;

            AsyncHelper.RunAsyncSTA(
                operation =>
            {
                progressVisualizer = (new DefaultProgressService()).CreateVisualizer(workerParams);

                work(progressVisualizer);
            },
                () =>
            {
                progressVisualizer.Complete();
                if (completeHandler != null)
                {
                    completeHandler();
                }
            });
            Application.DoEvents();
        }
Exemplo n.º 2
0
 public UpdateCliCommand(ITransactionFactory transactionFactory, IExceptionHandler exceptionHandler, ExecutionContext executionContext, ICommandResultVisualizer commandResultVisualizer, ICliUpdater cliUpdater, IFileSystem fileSystem, IProgressVisualizer progressVisualizer, IUserInterface userInterface) : base(transactionFactory, exceptionHandler, executionContext, commandResultVisualizer)
 {
     this.cliUpdater         = cliUpdater;
     this.fileSystem         = fileSystem;
     this.progressVisualizer = progressVisualizer;
     this.userInterface      = userInterface;
 }
Exemplo n.º 3
0
        private static ProgressObserver Observe(IProgressController controller, IProgressVisualizer visualizer)
        {
            ProgressObserver observer = CreateObserver(controller, visualizer, null);

            observedControllersMap.Add(controller, observer);
            return(observer);
        }
            public ExecutionVerifier(IProgressVisualizer visualizer, ProgressObserver testSubject)
            {
                Assert.IsNotNull(visualizer != null, "IProgressVisualizer is expected");
                Assert.IsNotNull(testSubject != null, "ProgressObserver is expected");

                this.visualizer  = visualizer;
                this.testSubject = testSubject;
            }
            public ExecutionVerifier(IProgressVisualizer visualizer, ProgressObserver testSubject)
            {
                visualizer.Should().NotBeNull();
                testSubject.Should().NotBeNull();

                this.visualizer  = visualizer;
                this.testSubject = testSubject;
            }
Exemplo n.º 6
0
        public IDisposableCommandLineParser BuildCommandLineInstance(IUserInterface userInterface,
                                                                     IProgressVisualizer progressVisualizer,
                                                                     ICommandResultVisualizer commandResultVisualizer,
                                                                     CancellationToken cancellationToken)
        {
            ILifetimeScope lifetimeScope = commandLineContainer.LifetimeScope.BeginLifetimeScope(
                builder =>
            {
                builder.RegisterInstance(userInterface).As <IUserInterface>().SingleInstance();
                builder.RegisterInstance(progressVisualizer).As <IProgressVisualizer>().SingleInstance();
                builder.RegisterInstance(commandResultVisualizer).As <ICommandResultVisualizer>().SingleInstance();
                builder.Register(_ => cancellationToken).As <CancellationToken>().SingleInstance();
                Common.BaseDiModule.AddAutoActivatedComponents(builder);
            });

            return(new DisposableCommandLineParser(lifetimeScope, lifetimeScope.Resolve <ICommandLineParser>()));
        }
 private static void VerifyProgress(IProgressVisualizer visualizer, double mainProgress, ProgressStepViewModel current, double subProgress)
 {
     Assert.AreEqual(mainProgress, visualizer.ViewModel.MainProgress.Value, FloatingPointError, "Unexpected main progress");
     if (current == null)
     {
         Assert.IsNull(visualizer.ViewModel.Current, "Not expecting any current step");
     }
     else
     {
         Assert.AreSame(current, visualizer.ViewModel.Current, "Unexpected current step");
         if (double.IsNaN(subProgress))
         {
             Assert.IsTrue(double.IsNaN(current.Progress.Value), "Unexpected sub progress");
         }
         else
         {
             Assert.AreEqual(subProgress, current.Progress.Value, FloatingPointError, "Unexpected sub progress");
         }
     }
 }
 private static void VerifyProgress(IProgressVisualizer visualizer, double mainProgress, ProgressStepViewModel current, double subProgress)
 {
     visualizer.ViewModel.MainProgress.Value.Should().BeApproximately(mainProgress, FloatingPointError, "Unexpected main progress");
     if (current == null)
     {
         visualizer.ViewModel.Current.Should().BeNull("Not expecting any current step");
     }
     else
     {
         visualizer.ViewModel.Current.Should().Be(current, "Unexpected current step");
         if (double.IsNaN(subProgress))
         {
             double.IsNaN(current.Progress.Value).Should().BeTrue("Unexpected sub progress");
         }
         else
         {
             current.Progress.Value.Should().BeApproximately(subProgress, FloatingPointError, "Unexpected sub progress");
         }
     }
 }
        public static void Run(
            [NotNull] IServiceProvider provider,
            bool allowCancel,
            [NotNull] Action <IProgressVisualizer> work,
            [CanBeNull] Action completeHandler)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (work == null)
            {
                throw new ArgumentNullException("work");
            }

            IProgressVisualizer progressVisualizer = null;

            AsyncHelper.RunAsync(
                asyncOp =>
            {
                progressVisualizer = provider
                                     .GetRequiredService <IProgressService>()
                                     .CreateVisualizer(allowCancel);

                work(progressVisualizer);
            },
                () =>
            {
                progressVisualizer.Complete();
                if (completeHandler != null)
                {
                    completeHandler();
                }
            });

            Application.DoEvents();
        }
        internal ProgressObserver(IServiceProvider serviceProvider, IProgressVisualizer host, IProgressEvents progressEvents, ProgressControllerViewModel state)
        {
            // Event registration must be on the UI thread
            ThreadHelper.ThrowIfNotOnUIThread();

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

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

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

            Debug.Assert(progressEvents.Steps != null, "Expected to be initialized");

            this.serviceProvider = serviceProvider;
            this.host = host;
            this.progressEvents = progressEvents;

            this.progressEvents.Started += this.ControllerStarted;
            this.progressEvents.Finished += this.ControllerFinished;
            this.progressEvents.StepExecutionChanged += this.OnStepExecutionChanged;
            this.progressEvents.CancellationSupportChanged += this.OnCancellationSupportChanged;

            this.viewModelRoot = state ?? new ProgressControllerViewModel();
            this.InitializeStepViewModels();

            this.host.ViewModel = this.viewModelRoot;
        }
Exemplo n.º 11
0
        internal ProgressObserver(IServiceProvider serviceProvider, IProgressVisualizer host, IProgressEvents progressEvents, ProgressControllerViewModel state)
        {
            // Event registration must be on the UI thread
            ThreadHelper.ThrowIfNotOnUIThread();

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

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

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

            Debug.Assert(progressEvents.Steps != null, "Expected to be initialized");

            this.serviceProvider = serviceProvider;
            this.host            = host;
            this.progressEvents  = progressEvents;

            this.progressEvents.Started                    += this.ControllerStarted;
            this.progressEvents.Finished                   += this.ControllerFinished;
            this.progressEvents.StepExecutionChanged       += this.OnStepExecutionChanged;
            this.progressEvents.CancellationSupportChanged += this.OnCancellationSupportChanged;

            this.viewModelRoot = state ?? new ProgressControllerViewModel();
            this.InitializeStepViewModels();

            this.host.ViewModel = this.viewModelRoot;
        }
        public static ProgressObserver StartObserving(IServiceProvider serviceProvider, IProgressEvents progressEvents, IProgressVisualizer visualizer, ProgressControllerViewModel state)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

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

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

            CheckSupportedProgressEvents(progressEvents);

            ProgressObserver observer = CreateAndConfigureInstance(serviceProvider, visualizer, progressEvents, null, state);

            Debug.Assert(observer != null, "Failed to create observer on the UI thread");

            return observer;
        }
 public static ProgressObserver StartObserving(IServiceProvider serviceProvider, IProgressEvents progressEvents, IProgressVisualizer visualizer)
 {
     return StartObserving(serviceProvider, progressEvents, visualizer, null);
 }
        public static ProgressObserver StartObserving(IProgressController controller, IProgressVisualizer visualizer, ProgressControllerViewModel state)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

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

            CheckSupportedController(controller);
            ProgressObserver observer = CreateAndConfigureInstance((IServiceProvider)controller, visualizer, controller.Events, new RelayCommand((s) => controller.TryAbort()), state);

            Debug.Assert(observer != null, "Failed to create observer on the UI thread");

            return observer;
        }
 public static ProgressObserver StartObserving(IProgressController controller, IProgressVisualizer visualizer)
 {
     return StartObserving(controller, visualizer, null);
 }
            public ExecutionVerifier(IProgressVisualizer visualizer, ProgressObserver testSubject)
            {
                Assert.IsNotNull(visualizer != null, "IProgressVisualizer is expected");
                Assert.IsNotNull(testSubject != null, "ProgressObserver is expected");

                this.visualizer = visualizer;
                this.testSubject = testSubject;
            }
 private static void VerifyProgress(IProgressVisualizer visualizer, double mainProgress, ProgressStepViewModel current, double subProgress)
 {
     Assert.AreEqual(mainProgress, visualizer.ViewModel.MainProgress.Value, FloatingPointError, "Unexpected main progress");
     if (current == null)
     {
         Assert.IsNull(visualizer.ViewModel.Current, "Not expecting any current step");
     }
     else
     {
         Assert.AreSame(current, visualizer.ViewModel.Current, "Unexpected current step");
         if (double.IsNaN(subProgress))
         {
             Assert.IsTrue(double.IsNaN(current.Progress.Value), "Unexpected sub progress");
         }
         else
         {
             Assert.AreEqual(subProgress, current.Progress.Value, FloatingPointError, "Unexpected sub progress");
         }
     }
 }
Exemplo n.º 18
0
 public SdkInstaller(IFileUnpackService fileUnpackService, IProgressVisualizer progressVisualizer, ISettingsProvider settingsProvider)
 {
     this.fileUnpackService  = fileUnpackService;
     this.progressVisualizer = progressVisualizer;
     this.settingsProvider   = settingsProvider;
 }
Exemplo n.º 19
0
 private static ProgressObserver CreateAndConfigureInstance(IServiceProvider serviceProvider, IProgressVisualizer visualizer, IProgressEvents progressEvents, ICommand cancelCommand, ProgressControllerViewModel state)
 {
     return(VsThreadingHelper.RunInline(serviceProvider, VsTaskRunContext.UIThreadNormalPriority, () =>
     {
         ProgressObserver returnValue = new ProgressObserver(serviceProvider, visualizer, progressEvents, state);
         returnValue.CancelCommand = cancelCommand;
         return returnValue;
     }, null));
 }
Exemplo n.º 20
0
 public static ProgressObserver StartObserving(IServiceProvider serviceProvider, IProgressEvents progressEvents, IProgressVisualizer visualizer)
 {
     return(StartObserving(serviceProvider, progressEvents, visualizer, null));
 }
Exemplo n.º 21
0
        public static ProgressObserver StartObserving(IServiceProvider serviceProvider, IProgressEvents progressEvents, IProgressVisualizer visualizer, ProgressControllerViewModel state)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

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

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

            CheckSupportedProgressEvents(progressEvents);

            ProgressObserver observer = CreateAndConfigureInstance(serviceProvider, visualizer, progressEvents, null, state);

            Debug.Assert(observer != null, "Failed to create observer on the UI thread");

            return(observer);
        }
 private static ProgressObserver Observe(IProgressController controller, IProgressVisualizer visualizer)
 {
     ProgressObserver observer = CreateObserver(controller, visualizer, null);
     observedControllersMap.Add(controller, observer);
     return observer;
 }
Exemplo n.º 23
0
 public static ProgressObserver StartObserving(IProgressController controller, IProgressVisualizer visualizer)
 {
     return(StartObserving(controller, visualizer, null));
 }
Exemplo n.º 24
0
 private static ProgressObserver CreateObserver(IProgressController controller, IProgressVisualizer visualizer, ProgressControllerViewModel state)
 {
     return(ProgressObserver.StartObserving(controller, visualizer, state));
 }
 private static ProgressObserver CreateAndConfigureInstance(IServiceProvider serviceProvider, IProgressVisualizer visualizer, IProgressEvents progressEvents, ICommand cancelCommand, ProgressControllerViewModel state)
 {
     return VsThreadingHelper.RunInline(serviceProvider, VsTaskRunContext.UIThreadNormalPriority, () =>
     {
         ProgressObserver returnValue = new ProgressObserver(serviceProvider, visualizer, progressEvents, state);
         returnValue.CancelCommand = cancelCommand;
         return returnValue;
     }, null);
 }
 private static ProgressObserver CreateObserver(IProgressController controller, IProgressVisualizer visualizer, ProgressControllerViewModel state)
 {
     return ProgressObserver.StartObserving(controller, visualizer, state);
 }
Exemplo n.º 27
0
        public static ProgressObserver StartObserving(IProgressController controller, IProgressVisualizer visualizer, ProgressControllerViewModel state)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

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

            CheckSupportedController(controller);
            ProgressObserver observer = CreateAndConfigureInstance((IServiceProvider)controller, visualizer, controller.Events, new RelayCommand((s) => controller.TryAbort()), state);

            Debug.Assert(observer != null, "Failed to create observer on the UI thread");

            return(observer);
        }
Exemplo n.º 28
0
 void Awake()
 {
     boardSizer     = GetComponent <Board>();
     progressVisual = GetComponent <BoardProgressVisualizer>();
 }