private void ReplaceParamsInFilePath(Dictionary <string, string> genParameters) { var parameterReplacements = new FileRenameParameterReplacements(genParameters); var path = GenContext.Current.OutputPath; var filesToMove = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) .ToList() .Where(file => parameterReplacements.FileRenameParams.Any(param => file.Contains(param.Key))); if (filesToMove != null && filesToMove.Count() > 0) { foreach (var f in filesToMove) { var file = new FileInfo(f); var newPath = parameterReplacements.ReplaceInPath(f); Fs.EnsureFolder(Directory.GetParent(newPath).FullName); file.MoveTo(newPath); } } var directoriesToDelete = Directory.EnumerateDirectories(path, "*", SearchOption.AllDirectories) .ToList() .Where(file => parameterReplacements.FileRenameParams.Any(param => file.Contains(param.Key))); if (directoriesToDelete != null && directoriesToDelete.Count() > 0) { foreach (var directory in directoriesToDelete) { Fs.SafeDeleteDirectory(directory, false); } } }
internal static async Task ExtractAsync(string inputFile, string destinationDir, TextWriter output, TextWriter error) { try { if (File.Exists(inputFile)) { if (destinationDir == ".") { destinationDir = System.Environment.CurrentDirectory; } Fs.EnsureFolder(destinationDir); output.WriteCommandHeader($"Extracting {inputFile} to {destinationDir}..."); await TemplatePackage.ExtractAsync(inputFile, destinationDir, true).ConfigureAwait(false); } else { error.WriteCommandText($"{inputFile} is not a valid folder to create a Templates Package."); } } catch (Exception ex) { error.WriteException(ex, "Unexpected exception extracting templates package."); } }
public static string GetTempGenerationPath(string projectName) { string projectGuid = ToolBox.Shell.GetVsProjectId().ToString(); var projectTempFolder = Path.Combine(_tempGenerationFolder, projectGuid); Fs.EnsureFolder(projectTempFolder); var tempGenerationName = $"{projectName}_{DateTime.Now.FormatAsShortDateTime()}"; var inferredName = Naming.Infer(tempGenerationName, new List <Validator> { new SuggestedDirectoryNameValidator(projectTempFolder) }, "_"); return(Path.Combine(projectTempFolder, inferredName)); }
protected override string AcquireMstx() { var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var sourceUrl = $"{_cdnUrl}/{TemplatesPackageFileName}"; var fileTarget = Path.Combine(tempFolder, TemplatesPackageFileName); Fs.EnsureFolder(tempFolder); DownloadContent(sourceUrl, fileTarget); return(fileTarget); }
public static string GetTempGenerationPath(string projectName) { string projectGuid = ToolBox.Shell.GetProjectGuidByName(GenContext.Current.ProjectName).ToString(); var projectTempFolder = Path.Combine(_tempGenerationFolder, projectGuid); Fs.EnsureFolder(projectTempFolder); var tempGenerationName = $"{projectName}_{DateTime.Now.FormatAsShortDateTime()}"; var inferredName = NamingService.Infer(tempGenerationName, new List <Validator> { new FolderNameValidator(projectTempFolder) }, "_"); return(Path.Combine(projectTempFolder, inferredName, projectName)); }
private static string GetTempGenerationPath(string projectName) { var tempGenerationPath = Path.Combine(Path.GetTempPath(), Configuration.Current.TempGenerationFolderPath); Fs.EnsureFolder(tempGenerationPath); var tempGenerationName = $"{projectName}_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}"; var inferredName = Naming.Infer(tempGenerationName, new List <Validator>() { new DirectoryExistsValidator(tempGenerationPath) }, "_"); return(Path.Combine(tempGenerationPath, inferredName)); }
private static string PrepareResultDir(string prepareDir, string version, TextWriter output) { var prepareDirPath = new DirectoryInfo(prepareDir).Parent.FullName; var resultDir = Path.Combine(prepareDirPath, $"Preparation_v{version}"); if (Directory.Exists(resultDir)) { output.WriteCommandText("The target directory already exists, cleaning..."); Fs.SafeDeleteDirectory(resultDir); } else { Fs.EnsureFolder(resultDir); } return(resultDir); }
public static void DownloadContent(RemoteSourceDownloadOptions options, TextWriter output, TextWriter error) { try { var shortLanguage = ProgrammingLanguages.GetShortProgrammingLanguage(options.Language); output.WriteCommandHeader($"Downloading templates content from environment {options.Env.ToString()} ({options.StorageAccount})"); TemplatesSourceConfig config = GetConfigFromCdn(options.Env); TemplatesPackageInfo package = null; if (options.Version != null) { package = ResolvePackageForVersion(config, options.Version, options.Platform, shortLanguage, output); } else { package = config.Latest; } if (package != null) { Fs.EnsureFolder(options.Destination); var result = RemoteSource.DownloadCdnElement(Environments.CdnUrls[options.Env], package.Name, options.Destination); output.WriteLine(); output.WriteCommandText($"Successfully downloaded '{result}'"); output.WriteLine(); } else { output.WriteLine(); output.WriteCommandText($"Package not found for the version '{options.Version}', platform '{options.Platform}' and laguage '{options.Language}'"); output.WriteLine(); } } catch (Exception ex) { error.WriteException(ex, $"Unable to download the file content from the specified environment."); } }
private void BackupProjectFiles(TempGenerationResult result) { var projectGuid = GenContext.ToolBox.Shell.GetActiveProjectGuid(); if (string.IsNullOrEmpty(projectGuid)) { return; } var backupFolder = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Configuration.Current.BackupFolderPath, projectGuid); var fileName = Path.Combine(backupFolder, "backup.json"); if (Directory.Exists(backupFolder)) { Fs.SafeDeleteDirectory(backupFolder); } Fs.EnsureFolder(backupFolder); File.WriteAllText(fileName, JsonConvert.SerializeObject(result), Encoding.UTF8); var modifiedFiles = result.ConflictingFiles.Concat(result.ModifiedFiles); foreach (var file in modifiedFiles) { var originalFile = Path.Combine(GenContext.Current.DestinationPath, file); var backupFile = Path.Combine(backupFolder, file); var destDirectory = Path.GetDirectoryName(backupFile); Fs.SafeCopyFile(originalFile, destDirectory, true); } }