private void ImportFile(string filePattern, FileSet fs) { var fileNameReplacement = String.Empty; if (filePattern.Contains("=")) { fileNameReplacement = filePattern.Substring(0, filePattern.IndexOf("=")); filePattern = filePattern.Substring(filePattern.IndexOf("=") + 1); } var di = new DirectoryInfo(Path.Combine(".", Path.GetDirectoryName(filePattern))); filePattern = Path.GetFileName(filePattern); var matchingFiles = new FileInfo[] { }; if (di.Exists) { matchingFiles = di.GetFiles(filePattern); } if (!matchingFiles.Any()) { var curColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\n\nWARNING:\n\n - No INPUT files matched {0} in {1}\n", filePattern, di.FullName); var fsf = new FileSetFile(); fsf.RelativePath = Path.GetFileName(filePattern); fs.FileSetFiles.Add(fsf); Console.ForegroundColor = curColor; } foreach (var fi in matchingFiles) { var fsf = new FileSetFile(); fsf.RelativePath = String.IsNullOrEmpty(fileNameReplacement) ? fi.Name : fileNameReplacement; fsf.OriginalRelativePath = fi.FullName.Substring(this.SSoTmeProject.RootPath.Length).Replace("\\", "/"); fs.FileSetFiles.Add(fsf); if (fi.Exists) { if (fi.IsBinaryFile()) { fsf.ZippedBinaryFileContents = File.ReadAllBytes(fi.FullName).Zip(); } else { fsf.ZippedFileContents = File.ReadAllText(fi.FullName).Zip(); } } else { var curColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("INPUT Format: {0} did not match any files in {1}", filePattern, di.FullName); Console.ForegroundColor = curColor; } } }
public void AddOutputFile(string relativePath, string fileContents, bool alwaysOverwrite = true) { var fsf = new FileSetFile(); fsf.RelativePath = relativePath; fsf.FileContents = fileContents; fsf.AlwaysOverwrite = alwaysOverwrite; this.OutputFileSet.FileSetFiles.Add(fsf); }
public void WriteToRoot(string fileName, byte[] bytes) { var fs = new FileSet(); var fsf = new FileSetFile(); fsf.RelativePath = fileName; fsf.BinaryFileContents = bytes; fs.FileSetFiles.Add(fsf); fs.WriteTo(this.RootDirInfo); }
public void WriteToRoot(string fileName, string textContents) { var fs = new FileSet(); var fsf = new FileSetFile(); fsf.RelativePath = fileName; fsf.FileContents = textContents; fs.FileSetFiles.Add(fsf); fs.WriteTo(this.RootDirInfo); }
private FileSetFile FileSetFileFromResource(string basePath, string matchingResourceName, bool alwaysOvewrite) { var resourceStream = this.GetType() .Assembly .GetManifestResourceStream(matchingResourceName); var memoryStream = new MemoryStream(); resourceStream.CopyTo(memoryStream); var dotPath = matchingResourceName.Substring(basePath.Length); while (dotPath.Count(countChar => countChar == '.') > 1) { dotPath = dotPath.Substring(0, dotPath.IndexOf(".")) + "/" + dotPath.Substring(dotPath.IndexOf(".") + 1); } FileSetFile fsf = new FileSetFile(); fsf.RelativePath = dotPath; fsf.BinaryFileContents = memoryStream.ToArray(); fsf.AlwaysOverwrite = alwaysOvewrite; return(fsf); }
public void LoadInputFileSetFile(FileSetFile inputFileSetFile) { var finalPath = Path.Combine(this.RootDirInfo.FullName, Path.GetFileName(inputFileSetFile.RelativePath)); File.WriteAllText(finalPath, inputFileSetFile.FileContents); }
private void AddResourceToOutput(String basePath, string matchingResourceName, bool alwaysOvewrite) { FileSetFile fsf = FileSetFileFromResource(basePath, matchingResourceName, alwaysOvewrite); this.OutputFileSet.FileSetFiles.Add(fsf); }