internal ProgressActiveScope(RangeProgress progress, LongRunningState isLongRunning)
        {
            _progress = progress;

            SetActive(true);

            if (isLongRunning == LongRunningState.Yes)
            {
                SetIsRunningForLong(true);
            }
            else
            {
                SetIsRunningForLong(false);
                if (isLongRunning == LongRunningState.Detect)
                {
                    _delayForLongRunningSetFlag = new Timer(_delayForLongRunningSetFlag_Tick, null, 1000, -1);
                }
            }

            _internalProgress = ObservableProgress <int> .CreateForUi((value) =>
            {
                _progress.Current = value;
            });

            GC.SuppressFinalize(this);
        }
示例#2
0
 public ObservableProgressWithSubscription(ObservableProgress <T> progress, IDisposable subscription)
 {
     _progress     = progress;
     _subscription = subscription;
 }
        /// <summary>
        /// Publishes the ASP.NET Core project to App Engine Flex and reports progress to the UI.
        /// </summary>
        /// <param name="project">The project to deploy.</param>
        /// <param name="options">The <see cref="DeploymentOptions"/> to use.</param>
        public async Task PublishProjectAsync(IParsedProject project, DeploymentOptions options)
        {
            try
            {
                await GoogleCloudExtensionPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync();

                ShellUtils.SaveAllFiles();

                await GcpOutputWindow.ActivateAsync();

                await GcpOutputWindow.ClearAsync();

                await GcpOutputWindow.OutputLineAsync(string.Format(Resources.FlexPublishStepStartMessage, project.Name));

                TimeSpan deploymentDuration;
                AppEngineFlexDeploymentResult result;
                using (await StatusbarHelper.FreezeAsync())
                    using (await StatusbarHelper.ShowDeployAnimationAsync())
                        using (IDisposableProgress progress =
                                   await StatusbarHelper.ShowProgressBarAsync(Resources.FlexPublishProgressMessage))
                            using (await ShellUtils.SetShellUIBusyAsync())
                            {
                                DateTime startDeploymentTime = DateTime.Now;
                                result = await PublishProjectAsync(project, options, progress);

                                deploymentDuration = DateTime.Now - startDeploymentTime;
                            }

                if (result != null)
                {
                    await GcpOutputWindow.OutputLineAsync(string.Format(Resources.FlexPublishSuccessMessage, project.Name));

                    await StatusbarHelper.SetTextAsync(Resources.PublishSuccessStatusMessage);

                    string url = result.GetDeploymentUrl();
                    await GcpOutputWindow.OutputLineAsync(string.Format(Resources.PublishUrlMessage, url));

                    if (options.OpenWebsite)
                    {
                        Process.Start(url);
                    }

                    EventsReporterWrapper.ReportEvent(
                        GaeDeployedEvent.Create(CommandStatus.Success, deploymentDuration));
                }
                else
                {
                    await GcpOutputWindow.OutputLineAsync(string.Format(Resources.FlexPublishFailedMessage, project.Name));

                    await StatusbarHelper.SetTextAsync(Resources.PublishFailureStatusMessage);

                    EventsReporterWrapper.ReportEvent(GaeDeployedEvent.Create(CommandStatus.Failure, deploymentDuration));
                }
            }
            catch (Exception)
            {
                EventsReporterWrapper.ReportEvent(GaeDeployedEvent.Create(CommandStatus.Failure));
                await GcpOutputWindow.OutputLineAsync(string.Format(Resources.FlexPublishFailedMessage, project.Name));

                await StatusbarHelper.SetTextAsync(Resources.PublishFailureStatusMessage);
            }
        }
        /// <summary>
        /// Builds the project and deploys it to Google Kubernetes Engine.
        /// </summary>
        /// <param name="project">The project to build and deploy.</param>
        /// <param name="options">Options for deploying and building.</param>
        public async Task DeployProjectToGkeAsync(IParsedProject project, Options options)
        {
            try
            {
                await GcpOutputWindow.ClearAsync();

                await GcpOutputWindow.ActivateAsync();

                await GcpOutputWindow.OutputLineAsync(string.Format(Resources.GkePublishDeployingToGkeMessage, project.Name));

                TimeSpan deploymentDuration;
                Result   result;
                using (await StatusbarService.FreezeAsync())
                    using (await StatusbarService.ShowDeployAnimationAsync())
                        using (IDisposableProgress progress =
                                   await StatusbarService.ShowProgressBarAsync(Resources.GkePublishDeploymentStatusMessage))
                            using (await ShellUtils.SetShellUIBusyAsync())
                            {
                                DateTime deploymentStartTime = DateTime.Now;

                                string imageTag = await BuildImageAsync(project, options, progress);

                                if (imageTag != null)
                                {
                                    result = await PublishImageToGkeAsync(imageTag, options, progress);
                                }
                                else
                                {
                                    result = Result.FailedResult;
                                }

                                deploymentDuration = DateTime.Now - deploymentStartTime;
                            }

                OutputResultData(project, options, result);

                if (options.OpenWebsite && result.ServiceExposed && result.ServicePublicIpAddress != null)
                {
                    BrowserService.OpenBrowser($"http://{result.ServicePublicIpAddress}");
                }

                if (result.Failed)
                {
                    await StatusbarService.SetTextAsync(Resources.PublishFailureStatusMessage);

                    EventsReporterWrapper.ReportEvent(GkeDeployedEvent.Create(CommandStatus.Failure));
                }
                else
                {
                    await StatusbarService.SetTextAsync(Resources.PublishSuccessStatusMessage);

                    EventsReporterWrapper.ReportEvent(
                        GkeDeployedEvent.Create(CommandStatus.Success, deploymentDuration));
                }
            }
            catch (Exception)
            {
                await GcpOutputWindow.OutputLineAsync(
                    string.Format(Resources.GkePublishDeploymentFailureMessage, project.Name));

                await StatusbarService.SetTextAsync(Resources.PublishFailureStatusMessage);

                EventsReporterWrapper.ReportEvent(GkeDeployedEvent.Create(CommandStatus.Failure));
            }
        }