Example #1
0
        public async Task <bool> Run()
        {
            var manifestData = GetDeploymentManifest();

            Console.Write("Deployment environment: ");
            var deploymentEnvironment = Console.ReadLine();

            foreach (var deploymentTarget in manifestData.Manifest.Targets.Where(x => x.EnvironmentName == deploymentEnvironment))
            {
                Console.WriteLine($"Starting deployment for application [{deploymentTarget.ApplicationName}] and environment [{deploymentTarget.EnvironmentName}]");

                var setup = await GetDeploymentSetup(deploymentTarget);

                foreach (var configuration in deploymentTarget.Configurations)
                {
                    Console.WriteLine($"Starting deployment for configuration {configuration.Name}");

                    string cfgProfileId = await GetConfigurationProfileSummary(setup.Application, configuration.Name);

                    var dataFilePath = Path.Combine(manifestData.ManifestParentDirectory, configuration.File);
                    if (!File.Exists(dataFilePath))
                    {
                        Console.WriteLine($"Can't find file specified: [{dataFilePath}]'");
                        return(false);
                    }

                    var content = Encoding.ASCII.GetBytes(File.ReadAllText(dataFilePath));

                    using (var dataStream = new MemoryStream(content))
                    {
                        var createVersionResult = await _client.CreateHostedConfigurationVersionAsync(
                            new CreateHostedConfigurationVersionRequest
                        {
                            ApplicationId          = setup.Application.Id,
                            ConfigurationProfileId = cfgProfileId,
                            Content     = dataStream,
                            ContentType = "text/plain"
                        });

                        Console.WriteLine($"New configuration version created. Version: [{createVersionResult.VersionNumber}]");

                        var deploymentStartResult = await _deploymentService.StartDeployment(setup.Application.Id, setup.Environment.Id,
                                                                                             setup.DeploymentStrategy.Id, cfgProfileId, createVersionResult.VersionNumber.ToString());

                        await _deploymentService.WaitDeployment(deploymentStartResult);
                    }

                    Console.WriteLine($"Deployment for configuration {configuration.Name} finished.");
                }

                Console.WriteLine($"Deployment for application [{deploymentTarget.ApplicationName}] and environment [{deploymentTarget.EnvironmentName}] finished.");
            }

            Console.WriteLine($"Deployment using manifest [{manifestData.ManifestFilePath}] finished.");

            return(false);
        }