Beispiel #1
0
        public override async void Publish()
        {
            if (!ValidateInput())
            {
                Debug.WriteLine("Invalid input cancelled the operation.");
                return;
            }

            var project = _publishDialog.Project;

            try
            {
                ShellUtils.SaveAllFiles();

                var context = new GCloudContext
                {
                    CredentialsPath = CredentialsStore.Default.CurrentAccountPath,
                    ProjectId       = CredentialsStore.Default.CurrentProjectId,
                    AppName         = GoogleCloudExtensionPackage.ApplicationName,
                    AppVersion      = GoogleCloudExtensionPackage.ApplicationVersion,
                };
                var options = new AppEngineFlexDeployment.DeploymentOptions
                {
                    Version = Version,
                    Promote = Promote,
                    Context = context
                };

                GcpOutputWindow.Activate();
                GcpOutputWindow.Clear();
                GcpOutputWindow.OutputLine(String.Format(Resources.GcePublishStepStartMessage, project.Name));

                _publishDialog.FinishFlow();

                AppEngineFlexDeploymentResult result;
                using (var frozen = StatusbarHelper.Freeze())
                    using (var animationShown = StatusbarHelper.ShowDeployAnimation())
                        using (var progress = StatusbarHelper.ShowProgressBar(Resources.FlexPublishProgressMessage))
                            using (var deployingOperation = ShellUtils.SetShellUIBusy())
                            {
                                result = await AppEngineFlexDeployment.PublishProjectAsync(
                                    project.FullPath,
                                    options,
                                    progress,
                                    GcpOutputWindow.OutputLine);
                            }

                if (result != null)
                {
                    GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishSuccessMessage, project.Name));
                    StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage);

                    var url = result.GetDeploymentUrl();
                    GcpOutputWindow.OutputLine(String.Format(Resources.PublishUrlMessage, url));
                    if (OpenWebsite)
                    {
                        Process.Start(url);
                    }
                }
                else
                {
                    GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name));
                    StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);
                }
            }
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name));
                StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);
            }
        }
        public override async void Publish()
        {
            if (!ValidateInput())
            {
                Debug.WriteLine("Invalid input cancelled the operation.");
                return;
            }

            var project = _publishDialog.Project;

            try
            {
                var verifyGcloudTask = GCloudWrapperUtils.VerifyGCloudDependencies("beta");
                _publishDialog.TrackTask(verifyGcloudTask);
                if (!await verifyGcloudTask)
                {
                    Debug.WriteLine("Gcloud dependencies not met, aborting publish operation.");
                    return;
                }

                ShellUtils.SaveAllFiles();

                var context = new GCloudContext
                {
                    CredentialsPath = CredentialsStore.Default.CurrentAccountPath,
                    ProjectId       = CredentialsStore.Default.CurrentProjectId,
                    AppName         = GoogleCloudExtensionPackage.ApplicationName,
                    AppVersion      = GoogleCloudExtensionPackage.ApplicationVersion,
                };
                var options = new AppEngineFlexDeployment.DeploymentOptions
                {
                    Version = Version,
                    Promote = Promote,
                    Context = context
                };

                GcpOutputWindow.Activate();
                GcpOutputWindow.Clear();
                GcpOutputWindow.OutputLine(String.Format(Resources.GcePublishStepStartMessage, project.Name));

                _publishDialog.FinishFlow();

                TimeSpan deploymentDuration;
                AppEngineFlexDeploymentResult result;
                using (StatusbarHelper.Freeze())
                    using (StatusbarHelper.ShowDeployAnimation())
                        using (var progress = StatusbarHelper.ShowProgressBar(Resources.FlexPublishProgressMessage))
                            using (ShellUtils.SetShellUIBusy())
                            {
                                var startDeploymentTime = DateTime.Now;
                                result = await AppEngineFlexDeployment.PublishProjectAsync(
                                    project,
                                    options,
                                    progress,
                                    VsVersionUtils.ToolsPathProvider,
                                    GcpOutputWindow.OutputLine);

                                deploymentDuration = DateTime.Now - startDeploymentTime;
                            }

                if (result != null)
                {
                    GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishSuccessMessage, project.Name));
                    StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage);

                    var url = result.GetDeploymentUrl();
                    GcpOutputWindow.OutputLine(String.Format(Resources.PublishUrlMessage, url));
                    if (OpenWebsite)
                    {
                        Process.Start(url);
                    }

                    EventsReporterWrapper.ReportEvent(GaeDeployedEvent.Create(CommandStatus.Success, deploymentDuration));
                }
                else
                {
                    GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name));
                    StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);

                    EventsReporterWrapper.ReportEvent(GaeDeployedEvent.Create(CommandStatus.Failure));
                }
            }
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name));
                StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);

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