/// <summary> /// This method updates the deployment manifest json file by adding the directory path at which the CDK deployment project is saved. /// If the manifest file does not exists then a new file is generated. /// <param name="saveCdkDirectoryFullPath">The absolute path to the directory at which the CDK deployment project is saved</param> /// <param name="targetApplicationFullPath">The absolute path to the target application csproj or fsproj file.</param> /// <exception cref="FailedToUpdateDeploymentManifestFileException">Thrown if an error occured while trying to update the deployment manifest file.</exception> /// </summary> /// <returns></returns> public async Task UpdateDeploymentManifestFile(string saveCdkDirectoryFullPath, string targetApplicationFullPath) { try { if (!_directoryManager.Exists(saveCdkDirectoryFullPath)) { return; } var deploymentManifestFilePath = GetDeploymentManifestFilePath(targetApplicationFullPath); var targetApplicationDirectoryPath = _directoryManager.GetDirectoryInfo(targetApplicationFullPath).Parent.FullName; var saveCdkDirectoryRelativePath = _directoryManager.GetRelativePath(targetApplicationDirectoryPath, saveCdkDirectoryFullPath); DeploymentManifestModel deploymentManifestModel; if (_fileManager.Exists(deploymentManifestFilePath)) { deploymentManifestModel = await ReadManifestFile(deploymentManifestFilePath); if (deploymentManifestModel.DeploymentProjects == null) { deploymentManifestModel.DeploymentProjects = new List <DeploymentManifestEntry> { new DeploymentManifestEntry(saveCdkDirectoryRelativePath) }; } else { deploymentManifestModel.DeploymentProjects.Add(new DeploymentManifestEntry(saveCdkDirectoryRelativePath)); } } else { var deploymentManifestEntries = new List <DeploymentManifestEntry> { new DeploymentManifestEntry(saveCdkDirectoryRelativePath) }; deploymentManifestModel = new DeploymentManifestModel(deploymentManifestEntries); } var manifestFileJsonString = SerializeManifestModel(deploymentManifestModel); await _fileManager.WriteAllTextAsync(deploymentManifestFilePath, manifestFileJsonString); } catch (Exception ex) { throw new FailedToUpdateDeploymentManifestFileException($"Failed to update the deployment manifest file " + $"for the deployment project stored at '{saveCdkDirectoryFullPath}'", ex); } }
/// <summary> /// This method parses the <see cref="DeploymentManifestModel"/> into a string /// </summary> /// <param name="deploymentManifestModel"><see cref="DeploymentManifestModel"/></param> /// <returns>A formatted string representation of <see cref="DeploymentManifestModel"></returns> private string SerializeManifestModel(DeploymentManifestModel deploymentManifestModel) { return(JsonConvert.SerializeObject(deploymentManifestModel, Formatting.Indented)); }