예제 #1
0
        protected override async Task LoadDataOverride()
        {
            try
            {
                Debug.WriteLine("Loading list of services.");
                _gaeApplication = _dataSource.Value.GetApplicationAsync();
                IList <ServiceViewModel> services = await LoadServiceList();

                Children.Clear();
                foreach (var item in services)
                {
                    Children.Add(item);
                }
                if (Children.Count == 0)
                {
                    Children.Add(s_noItemsPlacehoder);
                }
                EventsReporterWrapper.ReportEvent(GaeServicesLoadedEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.OutputLine(Resources.CloudExplorerGaeFailedServicesMessage);
                GcpOutputWindow.OutputLine(ex.Message);
                GcpOutputWindow.Activate();

                EventsReporterWrapper.ReportEvent(GaeServicesLoadedEvent.Create(CommandStatus.Failure));
                throw new CloudExplorerSourceException(ex.Message, ex);
            }
        }
        protected override async void OnIsExpandedChanged(bool newValue)
        {
            base.OnIsExpandedChanged(newValue);
            try
            {
                // If this is the first time the node has been expanded load it's resources.
                if (!_resourcesLoaded && newValue)
                {
                    _resourcesLoaded = true;
                    _versions        = await root.DataSource.Value.GetVersionListAsync(Service.Id);

                    Children.Clear();
                    if (_versions == null)
                    {
                        Children.Add(s_errorPlaceholder);
                    }
                    else
                    {
                        PresentViewModels();
                        UpdateContextMenu();
                    }
                }

                EventsReporterWrapper.ReportEvent(GaeVersionsLoadedEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.OutputLine(Resources.CloudExplorerGaeFailedVersionsMessage);
                GcpOutputWindow.OutputLine(ex.Message);
                GcpOutputWindow.Activate();

                EventsReporterWrapper.ReportEvent(GaeVersionsLoadedEvent.Create(CommandStatus.Failure));
                throw new CloudExplorerSourceException(ex.Message, ex);
            }
        }
예제 #3
0
        private void OnStartInstanceCommand()
        {
            try
            {
                if (!UserPromptUtils.ActionPrompt(
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPrompt, Instance.Name),
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPromptCaption, Instance.Name),
                        actionCaption: Resources.UiStartButtonCaption))
                {
                    Debug.WriteLine($"The user cancelled starting instance {Instance.Name}.");
                    return;
                }

                var operation = _owner.DataSource.StartInstance(Instance);
                UpdateInstanceState(operation);

                EventsReporterWrapper.ReportEvent(StartGceInstanceEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.Activate();
                GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGceFailedToStartInstanceMessage, Instance.Name, ex.Message));

                EventsReporterWrapper.ReportEvent(StartGceInstanceEvent.Create(CommandStatus.Failure));
            }
        }
예제 #4
0
        protected override async Task LoadDataOverride()
        {
            try
            {
                Debug.WriteLine("Loading list of instances.");
                var instances = await LoadInstanceList();

                Children.Clear();
                if (instances == null)
                {
                    Children.Add(s_errorPlaceholder);
                }
                else
                {
                    foreach (var item in instances)
                    {
                        Children.Add(item);
                    }
                    if (Children.Count == 0)
                    {
                        Children.Add(s_noItemsPlacehoder);
                    }
                }
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.OutputLine(Resources.CloudExplorerSqlFailedMessage);
                GcpOutputWindow.OutputLine(ex.Message);
                GcpOutputWindow.Activate();

                throw new CloudExplorerSourceException(ex.Message, ex);
            }
        }
예제 #5
0
        private void OnStartInstanceCommand()
        {
            try
            {
                if (!UserPromptUtils.YesNoPrompt(
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPrompt, Instance.Name),
                        String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPromptCaption, Instance.Name)))
                {
                    Debug.WriteLine($"The user cancelled starting instance {Instance.Name}.");
                    return;
                }

                var operation = _owner.DataSource.StartInstance(Instance);
                UpdateInstanceState(operation);
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.Activate();
                GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGceFailedToStartInstanceMessage, Instance.Name, ex.Message));
            }
            catch (OAuthException ex)
            {
                ShowOAuthErrorDialog(ex);
            }
        }
예제 #6
0
        public CsprojProject(Project project, string targetFramework)
        {
            GcpOutputWindow.OutputDebugLine($"Found project {project.FullName} targeting {targetFramework}");

            _project = project;
            switch (targetFramework)
            {
            case "netcoreapp1.0":
                ProjectType = KnownProjectTypes.NetCoreWebApplication1_0;
                break;

            case "netcoreapp1.1":
                ProjectType = KnownProjectTypes.NetCoreWebApplication1_1;
                break;

            case "netcoreapp2.0":
                ProjectType = KnownProjectTypes.NetCoreWebApplication2_0;
                break;

            default:
                GcpOutputWindow.OutputDebugLine($"Unsopported target framework {targetFramework}");
                ProjectType = KnownProjectTypes.None;
                break;
            }
        }
        public override string GetExternalToolsPath()
        {
            var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
            var result           = Path.Combine(programFilesPath, $@"Microsoft Visual Studio\2017\{_edition}\Web\External");

            GcpOutputWindow.OutputDebugLine($"External tools path: {result}");
            return(result);
        }
예제 #8
0
        public string GetMsdeployPath()
        {
            var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
            var result           = Path.Combine(programFilesPath, @"IIS\Microsoft Web Deploy V3\msdeploy.exe");

            GcpOutputWindow.OutputDebugLine($"Msdeploy path: {result}");
            return(result);
        }
예제 #9
0
        public string GetMsbuildPath()
        {
            var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
            var result           = Path.Combine(programFilesPath, @"MSBuild\14.0\Bin\MSBuild.exe");

            GcpOutputWindow.OutputDebugLine($"Msbuild path: {result}");
            return(result);
        }
예제 #10
0
        public string GetDotnetPath()
        {
            var programFilesPath = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
            var result           = Path.Combine(programFilesPath, @"dotnet\dotnet.exe");

            GcpOutputWindow.OutputDebugLine($"Dotnet path: {result}");
            return(result);
        }
예제 #11
0
        public string GetMsbuildPath()
        {
            var programFilesPath = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
            var result           = Path.Combine(programFilesPath, $@"Microsoft Visual Studio\2017\{_edition}\MSBuild\15.0\Bin\MSBuild.exe");

            GcpOutputWindow.OutputDebugLine($"Program Files: {programFilesPath}");
            GcpOutputWindow.OutputDebugLine($"Msbuild V15 Path: {result}");
            return(result);
        }
예제 #12
0
        public string GetMsdeployPath()
        {
            var programFilesPath = Environment.GetEnvironmentVariable("ProgramFiles");
            var result           = Path.Combine(programFilesPath, @"IIS\Microsoft Web Deploy V3\msdeploy.exe");

            GcpOutputWindow.OutputDebugLine($"Program Files: {programFilesPath}");
            GcpOutputWindow.OutputDebugLine($"Msdeploy V15 path: {result}");
            return(result);
        }
        public string GetRemoteDebuggerToolsPath()
        {
            var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
            // TODO: add x86 support later
            var result = Path.Combine(programFilesPath, @"Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64\*");

            GcpOutputWindow.OutputDebugLine($"Program Files: {programFilesPath}");
            GcpOutputWindow.OutputDebugLine($"Debugger remote tools V14 path: {result}");
            return(result);
        }
        public override string GetRemoteDebuggerToolsPath()
        {
            var programFilesPath = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
            // TODO: add x86 support later
            var result = Path.Combine(programFilesPath, $@"Microsoft Visual Studio\2017\{_edition}\Common7\IDE\Remote Debugger\x64\*");

            GcpOutputWindow.OutputDebugLine($"Program Files: {programFilesPath}");
            GcpOutputWindow.OutputDebugLine($"Debugger remote tools V15 path: {result}");
            return(result);
        }
예제 #15
0
        public override async void Publish()
        {
            var context = new Context
            {
                CredentialsPath = CredentialsStore.Default.CurrentAccountPath,
                ProjectId       = CredentialsStore.Default.CurrentProjectId,
                AppName         = GoogleCloudExtensionPackage.ApplicationName,
                AppVersion      = GoogleCloudExtensionPackage.ApplicationVersion,
            };
            var options = new NetCoreDeployment.DeploymentOptions
            {
                Version = Version,
                Promote = Promote,
                Context = context
            };
            var project = _publishDialog.Project;

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

            _publishDialog.FinishFlow();

            NetCorePublishResult 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 NetCoreDeployment.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);
            }
        }
        protected override async Task LoadDataOverride()
        {
            try
            {
                Debug.WriteLine("Loading list of services.");

                GaeApplication = await _dataSource.Value.GetApplicationAsync();

                if (GaeApplication == null)
                {
                    var noAppEngineAppPlaceholder = new TreeLeaf
                    {
                        Caption     = Resources.CloudExplorerGaeNoAppFoundCaption,
                        IsError     = true,
                        ContextMenu = new ContextMenu
                        {
                            ItemsSource = new List <MenuItem>
                            {
                                new MenuItem {
                                    Header = Resources.CloudExplorerGaeSetAppRegionMenuHeader, Command = new ProtectedCommand(OnSetAppRegion)
                                }
                            }
                        }
                    };

                    Children.Clear();
                    Children.Add(noAppEngineAppPlaceholder);
                    return;
                }

                IList <ServiceViewModel> services = await LoadServiceList();

                Children.Clear();
                foreach (var item in services)
                {
                    Children.Add(item);
                }
                if (Children.Count == 0)
                {
                    Children.Add(s_noItemsPlacehoder);
                }
                EventsReporterWrapper.ReportEvent(GaeServicesLoadedEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.OutputLine(Resources.CloudExplorerGaeFailedServicesMessage);
                GcpOutputWindow.OutputLine(ex.Message);
                GcpOutputWindow.Activate();

                EventsReporterWrapper.ReportEvent(GaeServicesLoadedEvent.Create(CommandStatus.Failure));
                throw new CloudExplorerSourceException(ex.Message, ex);
            }
        }
예제 #17
0
        public override async void Publish()
        {
            var project = _publishDialog.Project;

            try
            {
                ShellUtils.SaveAllFiles();

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

                _publishDialog.FinishFlow();

                bool result;
                using (var frozen = StatusbarHelper.Freeze())
                    using (var animationShown = StatusbarHelper.ShowDeployAnimation())
                        using (var progress = StatusbarHelper.ShowProgressBar(String.Format(Resources.GcePublishProgressMessage, SelectedInstance.Name)))
                            using (var deployingOperation = ShellUtils.SetShellUIBusy())
                            {
                                result = await WindowsVmDeployment.PublishProjectAsync(
                                    project.FullPath,
                                    SelectedInstance,
                                    SelectedCredentials,
                                    progress,
                                    (l) => GcpOutputWindow.OutputLine(l));
                            }

                if (result)
                {
                    GcpOutputWindow.OutputLine(String.Format(Resources.GcePublishSuccessMessage, project.Name, SelectedInstance.Name));
                    StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage);

                    var url = SelectedInstance.GetDestinationAppUri();
                    GcpOutputWindow.OutputLine(String.Format(Resources.PublishUrlMessage, url));
                    if (OpenWebsite)
                    {
                        Process.Start(url);
                    }
                }
                else
                {
                    GcpOutputWindow.OutputLine(String.Format(Resources.GcePublishFailedMessage, project.Name));
                    StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);
                }
            }
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                GcpOutputWindow.OutputLine(String.Format(Resources.GcePublishFailedMessage, project.Name));
                StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);
            }
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void OnGenerateConfiguration(object sender, EventArgs e)
        {
            ErrorHandlerUtils.HandleExceptions(() =>
            {
                var selectedProject = SolutionHelper.CurrentSolution.SelectedProject;
                Debug.WriteLine($"Generating configuration for project: {selectedProject.FullPath}");
                var configurationStatus = AppEngineFlexDeployment.CheckProjectConfiguration(selectedProject);

                // If the app.yaml already exists allow the user to skip its generation to preserve the existing file.
                if (!configurationStatus.HasAppYaml ||
                    UserPromptUtils.ActionPrompt(
                        prompt: Resources.GenerateConfigurationAppYamlOverwriteMessage,
                        title: Resources.GenerateConfigurationOverwritePromptTitle,
                        actionCaption: Resources.UiOverwriteButtonCaption,
                        cancelCaption: Resources.UiSkipFileButtonCaption))
                {
                    Debug.WriteLine($"Generating app.yaml for {selectedProject.FullPath}");
                    if (!AppEngineFlexDeployment.GenerateAppYaml(selectedProject))
                    {
                        UserPromptUtils.ErrorPrompt(
                            String.Format(Resources.GenerateConfigurationFileGenerationErrorMessage, AppEngineFlexDeployment.AppYamlName),
                            Resources.GenerateConfigurationFileGeneratinErrorTitle);
                        return;
                    }
                    GcpOutputWindow.OutputLine(Resources.GenerateConfigurationAppYamlGeneratedMessage);
                }

                // If the Dockerfile already exists allow the user to skip its generation to preserve the existing file.
                if (!configurationStatus.HasDockerfile ||
                    UserPromptUtils.ActionPrompt(
                        prompt: Resources.GenerateConfigurationDockerfileOverwriteMessage,
                        title: Resources.GenerateConfigurationOverwritePromptTitle,
                        actionCaption: Resources.UiOverwriteButtonCaption,
                        cancelCaption: Resources.UiSkipFileButtonCaption))
                {
                    Debug.WriteLine($"Generating Dockerfile for {selectedProject.FullPath}");
                    if (!AppEngineFlexDeployment.GenerateDockerfile(selectedProject))
                    {
                        UserPromptUtils.ErrorPrompt(
                            String.Format(Resources.GenerateConfigurationFileGenerationErrorMessage, AppEngineFlexDeployment.DockerfileName),
                            Resources.GenerateConfigurationFileGeneratinErrorTitle);
                        return;
                    }
                    GcpOutputWindow.OutputLine(Resources.GenerateConfigurationDockerfileGeneratedMessage);
                }
            });
        }
예제 #19
0
        private static IParsedProject ParseCsprojProject(Project project)
        {
            GcpOutputWindow.OutputDebugLine($"Parsing .csproj {project.FullName}");

            try
            {
                var dom = XDocument.Load(project.FullName);
                var sdk = dom.Root.Attribute(SdkAttributeName);
                if (sdk != null)
                {
                    GcpOutputWindow.OutputDebugLine($"Found a .NET Core style .csproj {sdk.Value}");
                    if (sdk.Value == AspNetCoreSdk)
                    {
                        var targetFramework = dom.Root
                                              .Elements(PropertyGroupElementName)
                                              .Descendants(TargetFrameworkElementName)
                                              .Select(x => x.Value)
                                              .FirstOrDefault();
                        return(new DotNetCore.CsprojProject(project, targetFramework));
                    }
                }

                var projectGuids = dom.Root
                                   .Elements(XName.Get(PropertyGroupElementName, MsbuildNamespace))
                                   .Descendants(XName.Get(PropertyTypeGuidsElementName, MsbuildNamespace))
                                   .Select(x => x.Value)
                                   .FirstOrDefault();

                if (projectGuids == null)
                {
                    return(null);
                }

                var guids = projectGuids.Split(';');
                if (guids.Contains(WebApplicationGuid))
                {
                    return(new DotNet4.CsprojProject(project));
                }
            }
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                GcpOutputWindow.OutputDebugLine($"Invalid project file {project.FullName}");
            }
            return(null);
        }
        private void OutputResultData(GkeDeploymentResult result, GkeDeployment.DeploymentOptions options)
        {
            GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentSuccessMessage, _publishDialog.Project.Name));
            if (result.DeploymentUpdated)
            {
                GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentUpdatedMessage, options.DeploymentName));
            }
            if (result.DeploymentScaled)
            {
                GcpOutputWindow.OutputLine(
                    String.Format(Resources.GkePublishDeploymentScaledMessage, options.DeploymentName, options.Replicas));
            }

            if (result.ServiceUpdated)
            {
                GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishServiceUpdatedMessage, options.DeploymentName));
            }
            if (result.ServiceExposed)
            {
                if (result.PublicServiceIpAddress != null)
                {
                    GcpOutputWindow.OutputLine(
                        String.Format(Resources.GkePublishServiceIpMessage, DeploymentName, result.PublicServiceIpAddress));
                }
                else
                {
                    if (ExposePublicService)
                    {
                        GcpOutputWindow.OutputLine(Resources.GkePublishServiceIpTimeoutMessage);
                    }
                    else
                    {
                        GcpOutputWindow.OutputLine(
                            String.Format(
                                Resources.GkePublishServiceClusterIpMessage, DeploymentName, result.ClusterServiceIpAddress));
                    }
                }
            }
            if (result.ServiceDeleted)
            {
                GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishServiceDeletedMessage, DeploymentName));
            }
        }
예제 #21
0
        private void OnGetPublishSettings()
        {
            ExtensionAnalytics.ReportCommand(CommandName.GetPublishSettingsForGceInstance, CommandInvocationSource.Button);

            Debug.WriteLine($"Generating Publishing settings for {Instance.Name}");

            var storePath = PromptForPublishSettingsPath(Instance.Name);

            if (storePath == null)
            {
                Debug.WriteLine("User canceled saving the pubish settings.");
                return;
            }

            var profile = Instance.GeneratePublishSettings();

            File.WriteAllText(storePath, profile);
            GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGcePublishingSettingsSavedMessage, storePath));
        }
        protected override async Task LoadDataOverride()
        {
            try
            {
                Debug.WriteLine("Loading list of services.");
                Task <Application> gaeApplicationTask        = DataSource.Value.GetApplicationAsync();
                Task <List <ServiceViewModel> > servicesTask = LoadServiceList();
                await Task.WhenAll(gaeApplicationTask, servicesTask);

                GaeApplication = gaeApplicationTask.Result;
                var services = servicesTask.Result;
                Children.Clear();
                if (services == null)
                {
                    Children.Add(s_errorPlaceholder);
                }
                else
                {
                    foreach (var item in services)
                    {
                        Children.Add(item);
                    }
                    if (Children.Count == 0)
                    {
                        Children.Add(s_noItemsPlacehoder);
                    }
                }
                EventsReporterWrapper.ReportEvent(GaeServicesLoadedEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.OutputLine(Resources.CloudExplorerGaeFailedServicesMessage);
                GcpOutputWindow.OutputLine(ex.Message);
                GcpOutputWindow.Activate();

                EventsReporterWrapper.ReportEvent(GaeServicesLoadedEvent.Create(CommandStatus.Failure));
                throw new CloudExplorerSourceException(ex.Message, ex);
            }
        }
        /// <summary>
        /// Update the children (GAE instances) of this version.
        /// </summary>
        private async void UpdateChildren()
        {
            try
            {
                Children.Clear();
                Children.Add(s_loadingPlaceholder);

                var instances = await LoadInstanceList();

                Children.Clear();
                if (instances == null)
                {
                    Children.Add(s_errorPlaceholder);
                }
                else
                {
                    foreach (var item in instances)
                    {
                        Children.Add(item);
                    }
                    if (Children.Count == 0)
                    {
                        Children.Add(s_noItemsPlacehoder);
                    }
                }
                EventsReporterWrapper.ReportEvent(GaeInstancesLoadedEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                GcpOutputWindow.OutputLine(Resources.CloudExplorerGaeFailedInstancesMessage);
                GcpOutputWindow.OutputLine(ex.Message);
                GcpOutputWindow.Activate();

                Children.Add(s_errorPlaceholder);
                EventsReporterWrapper.ReportEvent(GaeInstancesLoadedEvent.Create(CommandStatus.Failure));
                throw new CloudExplorerSourceException(ex.Message, ex);
            }
        }
예제 #24
0
        private void OnSavePublishSettingsCommand()
        {
            Debug.WriteLine($"Generating Publishing settings for {Instance.Name}");

            var credentials = WindowsCredentialsChooserWindow.PromptUser(
                Instance,
                new WindowsCredentialsChooserWindow.Options
            {
                Title               = Resources.CloudExplorerGceSavePubSettingsCredentialsTitle,
                Message             = Resources.CloudExplorerGceSavePubSettingsCredentialsMessage,
                ActionButtonCaption = Resources.UiSaveButtonCaption
            });

            if (credentials == null)
            {
                Debug.WriteLine("User canceled when selecting credentials.");
                return;
            }

            var projectId = CredentialsStore.Default.CurrentProjectId;
            var storePath = PromptForPublishSettingsPath($"{projectId}-{Instance.Name}-{credentials.User}");

            if (storePath == null)
            {
                Debug.WriteLine("User canceled saving the pubish settings.");
                return;
            }

            EventsReporterWrapper.ReportEvent(SavePublishSettingsEvent.Create());
            var profile = Instance.GeneratePublishSettings(
                userName: credentials.User,
                password: credentials.Password);

            File.WriteAllText(storePath, profile);
            GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGcePublishingSettingsSavedMessage, storePath));
        }
예제 #25
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);
            }
        }
예제 #26
0
        /// <summary>
        /// Start the publish operation.
        /// </summary>
        public override async void Publish()
        {
            if (!ValidateInput())
            {
                Debug.WriteLine("Invalid input cancelled the operation.");
                return;
            }

            var project = _publishDialog.Project;

            try
            {
                var verifyGCloudTask = VerifyGCloudDependencies();
                _publishDialog.TrackTask(verifyGCloudTask);
                if (!await verifyGCloudTask)
                {
                    Debug.WriteLine("Aborting deployment, no kubectl was found.");
                    return;
                }

                var gcloudContext = new GCloudContext
                {
                    CredentialsPath = CredentialsStore.Default.CurrentAccountPath,
                    ProjectId       = CredentialsStore.Default.CurrentProjectId,
                    AppName         = GoogleCloudExtensionPackage.ApplicationName,
                    AppVersion      = GoogleCloudExtensionPackage.ApplicationVersion,
                };

                var kubectlContextTask = GCloudWrapper.GetKubectlContextForClusterAsync(
                    cluster: SelectedCluster.Name,
                    zone: SelectedCluster.Zone,
                    context: gcloudContext);
                _publishDialog.TrackTask(kubectlContextTask);

                using (var kubectlContext = await kubectlContextTask)
                {
                    var deploymentExistsTask = KubectlWrapper.DeploymentExistsAsync(DeploymentName, kubectlContext);
                    _publishDialog.TrackTask(deploymentExistsTask);
                    if (await deploymentExistsTask)
                    {
                        if (!UserPromptUtils.ActionPrompt(
                                String.Format(Resources.GkePublishDeploymentAlreadyExistsMessage, DeploymentName),
                                Resources.GkePublishDeploymentAlreadyExistsTitle,
                                actionCaption: Resources.UiUpdateButtonCaption))
                        {
                            return;
                        }
                    }

                    var options = new GkeDeployment.DeploymentOptions
                    {
                        Cluster                     = SelectedCluster.Name,
                        Zone                        = SelectedCluster.Zone,
                        DeploymentName              = DeploymentName,
                        DeploymentVersion           = DeploymentVersion,
                        ExposeService               = ExposeService,
                        GCloudContext               = gcloudContext,
                        KubectlContext              = kubectlContext,
                        Replicas                    = int.Parse(Replicas),
                        WaitingForServiceIpCallback = () => GcpOutputWindow.OutputLine(Resources.GkePublishWaitingForServiceIpMessage)
                    };

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

                    _publishDialog.FinishFlow();

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

                    if (result != null)
                    {
                        GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentSuccessMessage, project.Name));
                        if (result.DeploymentUpdated)
                        {
                            GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentUpdatedMessage, options.DeploymentName));
                        }
                        if (result.DeploymentScaled)
                        {
                            GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentScaledMessage, options.DeploymentName, options.Replicas));
                        }

                        if (result.WasExposed)
                        {
                            if (result.ServiceIpAddress != null)
                            {
                                GcpOutputWindow.OutputLine(
                                    String.Format(Resources.GkePublishServiceIpMessage, DeploymentName, result.ServiceIpAddress));
                            }
                            else
                            {
                                GcpOutputWindow.OutputLine(Resources.GkePublishServiceIpTimeoutMessage);
                            }
                        }
                        StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage);

                        if (OpenWebsite && result.WasExposed && result.ServiceIpAddress != null)
                        {
                            Process.Start($"http://{result.ServiceIpAddress}");
                        }
                    }
                    else
                    {
                        GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name));
                        StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);
                    }
                }
            }
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name));
                StatusbarHelper.SetText(Resources.PublishFailureStatusMessage);
                _publishDialog.FinishFlow();
            }
        }
        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));
            }
        }
예제 #28
0
        private async void UpdateInstanceState(GceOperation pendingOperation)
        {
            while (pendingOperation != null && !pendingOperation.OperationTask.IsCompleted)
            {
                // Since there's a pending operation the loading state needs to be set to show
                // progress ui.
                IsLoading = true;

                // Setting the content according to the operation type.
                switch (pendingOperation.OperationType)
                {
                case OperationType.StartInstance:
                    Caption = String.Format(Resources.CloudExplorerGceInstanceStartingCaption, Instance.Name);
                    break;

                case OperationType.StopInstance:
                    Caption = String.Format(Resources.CloudExplorerGceInstanceStoppingCaption, Instance.Name);
                    break;

                case OperationType.SettingTags:
                    Caption = String.Format(Resources.CloudExplorerGceInstanceSettingTagsCaption, Instance.Name);
                    break;

                case OperationType.ModifyingFirewall:
                    Caption = String.Format(Resources.CloudExplorerGceInstanceUpdatingFirewallCaption, Instance.Name);
                    break;
                }

                // Update the context menu to reflect the state.
                UpdateContextMenu();

                try
                {
                    // Await the end of the task. We can also get here if the task is faulted,
                    // in which case we need to handle that case.
                    while (true)
                    {
                        // Refresh the instance before waiting for the operation to finish.
                        Instance = await _owner.DataSource.RefreshInstance(Instance);

                        // Wait for the operation to finish up to the timeout, which we will use to refresh the
                        // state of the instance.
                        var result = await Task.WhenAny(pendingOperation.OperationTask, Task.Delay(s_pollTimeout));

                        if (result == pendingOperation.OperationTask)
                        {
                            // Await the task again to get any possible exception.
                            await pendingOperation.OperationTask;
                            break;
                        }
                    }

                    // Refresh the instance state after the operation is finished.
                    Instance = await _owner.DataSource.RefreshInstance(Instance);
                }
                catch (DataSourceException ex)
                {
                    Caption   = Instance.Name;
                    IsLoading = false;
                    IsError   = true;
                    UpdateContextMenu();

                    Debug.WriteLine($"Previous operation failed.");
                    switch (pendingOperation.OperationType)
                    {
                    case OperationType.StartInstance:
                        GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGceStartOperationFailedMessage, Instance.Name, ex.Message));
                        break;

                    case OperationType.StopInstance:
                        GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGceStopOperationFailedMessage, Instance.Name, ex.Message));
                        break;
                    }

                    // Permanent error.
                    return;
                }

                // See if there are more operations.
                pendingOperation = _owner.DataSource.GetPendingOperation(Instance);
            }

            // Normal state, no pending operations.
            IsLoading = false;
            Caption   = Instance.Name;
            UpdateContextMenu();
        }
예제 #29
0
        public override async void Publish()
        {
            var project = _publishDialog.Project;

            try
            {
                ShellUtils.SaveAllFiles();

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

                _publishDialog.FinishFlow();

                TimeSpan deploymentDuration;
                bool     result;
                using (var frozen = StatusbarHelper.Freeze())
                    using (var animationShown = StatusbarHelper.ShowDeployAnimation())
                        using (var progress = StatusbarHelper.ShowProgressBar(String.Format(Resources.GcePublishProgressMessage, SelectedInstance.Name)))
                            using (var deployingOperation = ShellUtils.SetShellUIBusy())
                            {
                                var startDeploymentTime = DateTime.Now;
                                result = await WindowsVmDeployment.PublishProjectAsync(
                                    project,
                                    SelectedInstance,
                                    SelectedCredentials,
                                    progress,
                                    VsVersionUtils.ToolsPathProvider,
                                    GcpOutputWindow.OutputLine);

                                deploymentDuration = DateTime.Now - startDeploymentTime;
                            }

                if (result)
                {
                    GcpOutputWindow.OutputLine(String.Format(Resources.GcePublishSuccessMessage, project.Name, SelectedInstance.Name));
                    StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage);

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

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

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

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