示例#1
0
        private string AskUserForCloudApplicationName(ProjectDefinition project, List <CloudApplication> existingApplications)
        {
            var defaultName = "";

            try
            {
                defaultName = _cloudApplicationNameGenerator.GenerateValidName(project, existingApplications);
            }
            catch { }

            var cloudApplicationName = "";

            while (true)
            {
                _toolInteractiveService.WriteLine();

                if (!existingApplications.Any())
                {
                    var title = "Name the AWS stack to deploy your application to" + Environment.NewLine +
                                "(A stack is a collection of AWS resources that you can manage as a single unit.)" + Environment.NewLine +
                                "--------------------------------------------------------------------------------";

                    cloudApplicationName =
                        _consoleUtilities.AskUserForValue(
                            title,
                            defaultName,
                            allowEmpty: false,
                            defaultAskValuePrompt: Constants.CLI.PROMPT_NEW_STACK_NAME);
                }
                else
                {
                    var title = "Select the AWS stack to deploy your application to" + Environment.NewLine +
                                "(A stack is a collection of AWS resources that you can manage as a single unit.)";

                    var userResponse =
                        _consoleUtilities.AskUserToChooseOrCreateNew(
                            existingApplications.Select(x => x.Name),
                            title,
                            askNewName: true,
                            defaultNewName: defaultName,
                            defaultChoosePrompt: Constants.CLI.PROMPT_CHOOSE_STACK_NAME,
                            defaultCreateNewPrompt: Constants.CLI.PROMPT_NEW_STACK_NAME,
                            defaultCreateNewLabel: Constants.CLI.CREATE_NEW_STACK_LABEL);

                    cloudApplicationName = userResponse.SelectedOption ?? userResponse.NewName;
                }

                if (!string.IsNullOrEmpty(cloudApplicationName) &&
                    _cloudApplicationNameGenerator.IsValidName(cloudApplicationName))
                {
                    return(cloudApplicationName);
                }

                PrintInvalidStackNameMessage();
            }
        }
        public async Task <IActionResult> StartDeploymentSession(StartDeploymentSessionInput input)
        {
            var output = new StartDeploymentSessionOutput(
                Guid.NewGuid().ToString()
                );

            var serviceProvider    = CreateSessionServiceProvider(output.SessionId, input.AWSRegion);
            var awsResourceQueryer = serviceProvider.GetRequiredService <IAWSResourceQueryer>();

            var state = new SessionState(
                output.SessionId,
                input.ProjectPath,
                input.AWSRegion,
                (await awsResourceQueryer.GetCallerIdentity()).Account,
                await _projectParserUtility.Parse(input.ProjectPath)
                );

            _stateServer.Save(output.SessionId, state);

            output.DefaultDeploymentName = _cloudApplicationNameGenerator.GenerateValidName(state.ProjectDefinition, new List <CloudApplication>());
            return(Ok(output));
        }