Beispiel #1
0
        /// <summary>
        /// Checks the project configuration files to see if they exist.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns>An instance of <seealso cref="ProjectConfigurationStatus"/> with the status of the config.</returns>
        public ProjectConfigurationStatus CheckProjectConfiguration(IParsedProject project)
        {
            string targetAppYaml = GetAppYamlPath(project);
            bool   hasAppYaml    = FileSystem.File.Exists(targetAppYaml);
            bool   hasDockefile  = NetCoreAppUtils.CheckDockerfile(project);

            return(new ProjectConfigurationStatus(hasAppYaml, hasDockefile));
        }
        public void BeforeEach()
        {
            _toolsPathProviderMock = new Mock <IToolsPathProvider>();
            _toolsPathProviderMock.Setup(tpp => tpp.GetDotnetPath()).Returns(DefaultDotnetPath);
            VsVersionUtils.s_toolsPathProviderOverride = _toolsPathProviderMock.Object;

            _processServiceMock = new Mock <IProcessService>();
            _fileSystemMock     = new Mock <IFileSystem> {
                DefaultValueProvider = DefaultValueProvider.Mock
            };
            _gcloudWrapperMock = new Mock <IGCloudWrapper>();
            _gcloudWrapperMock.Setup(w => w.GenerateSourceContextAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.CompletedTask);
            _environmentMock = new Mock <IEnvironment>();

            _objectUnderTest = new NetCoreAppUtils(
                _processServiceMock.ToLazy(),
                _fileSystemMock.ToLazy(),
                _gcloudWrapperMock.ToLazy(),
                _environmentMock.ToLazy());
        }
Beispiel #3
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);
            }
        }