Ejemplo n.º 1
0
        /// <summary>
        /// This method takes a user specified directory path and generates the CDK deployment project at this location.
        /// If the provided directory path is an empty string, then a default directory is created to save the CDK deployment project.
        /// </summary>
        /// <param name="saveCdkDirectoryPath">An absolute or a relative path provided by the user.</param>
        /// <param name="projectDisplayName">The name of the deployment project that will be displayed in the list of available deployment options.</param>
        /// <returns></returns>
        public async Task ExecuteAsync(string saveCdkDirectoryPath, string projectDisplayName)
        {
            var orchestrator    = new Orchestrator(_session, new[] { RecipeLocator.FindRecipeDefinitionsPath() });
            var recommendations = await GenerateRecommendationsToSaveDeploymentProject(orchestrator);

            var selectedRecommendation = _consoleUtilities.AskToChooseRecommendation(recommendations);

            if (string.IsNullOrEmpty(saveCdkDirectoryPath))
            {
                saveCdkDirectoryPath = GenerateDefaultSaveDirectoryPath();
            }

            var newDirectoryCreated = CreateSaveCdkDirectory(saveCdkDirectoryPath);

            var(isValid, errorMessage) = ValidateSaveCdkDirectory(saveCdkDirectoryPath);
            if (!isValid)
            {
                if (newDirectoryCreated)
                {
                    _directoryManager.Delete(saveCdkDirectoryPath);
                }
                errorMessage = $"Failed to generate deployment project.{Environment.NewLine}{errorMessage}";
                throw new InvalidSaveDirectoryForCdkProject(errorMessage.Trim());
            }

            var directoryUnderSourceControl = await IsDirectoryUnderSourceControl(saveCdkDirectoryPath);

            if (!directoryUnderSourceControl)
            {
                var userPrompt = "Warning: The target directory is not being tracked by source control. If the saved deployment " +
                                 "project is used for deployment it is important that the deployment project is retained to allow " +
                                 "future redeployments to previously deployed applications. " + Environment.NewLine + Environment.NewLine +
                                 "Do you still want to continue?";

                _toolInteractiveService.WriteLine();
                var yesNoResult = _consoleUtilities.AskYesNoQuestion(userPrompt, YesNo.Yes);

                if (yesNoResult == YesNo.No)
                {
                    if (newDirectoryCreated)
                    {
                        _directoryManager.Delete(saveCdkDirectoryPath);
                    }
                    return;
                }
            }

            _cdkProjectHandler.CreateCdkProject(selectedRecommendation, _session, saveCdkDirectoryPath);
            await GenerateDeploymentRecipeSnapShot(selectedRecommendation, saveCdkDirectoryPath, projectDisplayName);

            var saveCdkDirectoryFullPath = _directoryManager.GetDirectoryInfo(saveCdkDirectoryPath).FullName;

            _toolInteractiveService.WriteLine();
            _toolInteractiveService.WriteLine($"The CDK deployment project is saved at: {saveCdkDirectoryFullPath}");

            await _deploymentManifestEngine.UpdateDeploymentManifestFile(saveCdkDirectoryFullPath, _targetApplicationFullPath);
        }
        public void DeleteTemporaryCdkProject(string cdkProjectPath)
        {
            var parentPath = Path.GetFullPath(Constants.CDK.ProjectsDirectory);

            cdkProjectPath = Path.GetFullPath(cdkProjectPath);

            if (!cdkProjectPath.StartsWith(parentPath))
            {
                return;
            }

            try
            {
                _directoryManager.Delete(cdkProjectPath, true);
            }
            catch (Exception)
            {
                _interactiveService.LogErrorMessageLine($"We were unable to delete the temporary project that was created for this deployment. Please manually delete it at this location: {cdkProjectPath}");
            }
        }
Ejemplo n.º 3
0
 public void DeleteDirectory(string name, string path)
 {
     _directoryManager.Delete(CreateDirectoryPath(name, path), true);
 }