Ejemplo n.º 1
0
        /// <summary>
        /// Queries the user and generates an app.yaml and Docker file.
        /// </summary>
        private void GenerateConfiguration()
        {
            var selectedProject = SolutionHelper.CurrentSolution.SelectedProject.ParsedProject;

            Debug.WriteLine($"Generating configuration for project: {selectedProject.FullPath}");
            var appEngineConfiguration = GoogleCloudExtensionPackage.Instance.GetMefService <IAppEngineConfiguration>();
            ProjectConfigurationStatus configurationStatus = appEngineConfiguration.CheckProjectConfiguration(selectedProject);

            // If the app.yaml already exists allow the user to skip its generation to preserve the existing file.
            if (!configurationStatus.HasAppYaml ||
                UserPromptUtils.Default.ActionPrompt(
                    prompt: Resources.GenerateConfigurationAppYamlOverwriteMessage,
                    title: Resources.GenerateConfigurationOverwritePromptTitle,
                    actionCaption: Resources.UiOverwriteButtonCaption,
                    cancelCaption: Resources.UiSkipFileButtonCaption))
            {
                Debug.WriteLine($"Generating app.yaml for {selectedProject.FullPath}");
                try
                {
                    appEngineConfiguration.AddAppYamlItem(selectedProject);
                }
                catch (Exception error)

                {
                    UserPromptUtils.Default.ErrorPrompt(
                        string.Format(
                            Resources.GenerateConfigurationFileGenerationErrorMessage,
                            AppEngineConfiguration.AppYamlName),
                        Resources.GenerateConfigurationFileGeneratinErrorTitle,
                        error.Message);
                    return;
                }

                GcpOutputWindow.Default.OutputLine(Resources.GenerateConfigurationAppYamlGeneratedMessage);
            }

            // If the Dockerfile already exists allow the user to skip its generation to preserve the existing file.
            if (!configurationStatus.HasDockerfile ||
                UserPromptUtils.Default.ActionPrompt(
                    prompt: Resources.GenerateConfigurationDockerfileOverwriteMessage,
                    title: Resources.GenerateConfigurationOverwritePromptTitle,
                    actionCaption: Resources.UiOverwriteButtonCaption,
                    cancelCaption: Resources.UiSkipFileButtonCaption))
            {
                Debug.WriteLine($"Generating Dockerfile for {selectedProject.FullPath}");
                try
                {
                    NetCoreAppUtils.GenerateDockerfile(selectedProject);
                }
                catch (Exception exception)
                {
                    UserPromptUtils.Default.ErrorPrompt(
                        string.Format(
                            Resources.GenerateConfigurationFileGenerationErrorMessage,
                            NetCoreAppUtils.DockerfileName),
                        Resources.GenerateConfigurationFileGeneratinErrorTitle,
                        exception.Message);
                    return;
                }

                GcpOutputWindow.Default.OutputLine(Resources.GenerateConfigurationDockerfileGeneratedMessage);
            }
        }