private void ProcessFile(IFile sourceFile, string sourceRel, string targetDir, IGlobalRunSpec spec, IProcessor fallback, IEnumerable <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors, IReadOnlyList <IOperationProvider> locOperations) { IProcessor runner = fileGlobProcessors.FirstOrDefault(x => x.Key.IsMatch(sourceRel)).Value ?? fallback; if (runner == null) { throw new InvalidOperationException("At least one of [runner] or [fallback] cannot be null"); } if (locOperations != null) { runner = runner.CloneAndAppendOperations(locOperations); } if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel)) { targetRel = sourceRel; } string targetPath = Path.Combine(targetDir, targetRel); //TODO: Update context with the current file & such here bool customBufferSize = TryGetBufferSize(sourceFile, out int bufferSize); bool customFlushThreshold = TryGetFlushThreshold(sourceFile, out int flushThreshold); string fullTargetDir = Path.GetDirectoryName(targetPath); sourceFile.MountPoint.EnvironmentSettings.Host.FileSystem.CreateDirectory(fullTargetDir); try { using (Stream source = sourceFile.OpenRead()) using (Stream target = sourceFile.MountPoint.EnvironmentSettings.Host.FileSystem.CreateFile(targetPath)) { if (!customBufferSize) { runner.Run(source, target); } else { if (!customFlushThreshold) { runner.Run(source, target, bufferSize); } else { runner.Run(source, target, bufferSize, flushThreshold); } } } } catch (Exception ex) { throw new ContentGenerationException($"Error while processing file {sourceFile.FullPath}", ex); } }
private IReadOnlyList <IFileChange2> GetFileChangesInternal(IEngineEnvironmentSettings environmentSettings, IDirectory sourceDir, string targetDir, IGlobalRunSpec spec) { EngineConfig cfg = new EngineConfig(environmentSettings, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection); IProcessor fallback = Processor.Create(cfg, spec.Operations); List <IFileChange2> changes = new List <IFileChange2>(); List <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors = CreateFileGlobProcessors(sourceDir.MountPoint.EnvironmentSettings, spec); foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories)) { string sourceRel = file.PathRelativeTo(sourceDir); string fileName = Path.GetFileName(sourceRel); bool checkingDirWithPlaceholderFile = false; if (spec.IgnoreFileNames.Contains(fileName)) { // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed. // The change checking / reporting is different, setting this variable tracks it. checkingDirWithPlaceholderFile = true; } foreach (IPathMatcher include in spec.Include) { if (include.IsMatch(sourceRel)) { bool excluded = false; foreach (IPathMatcher exclude in spec.Exclude) { if (exclude.IsMatch(sourceRel)) { excluded = true; break; } } if (!excluded) { if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel)) { targetRel = sourceRel; } string targetPath = Path.Combine(targetDir, targetRel); if (checkingDirWithPlaceholderFile) { targetPath = Path.GetDirectoryName(targetPath); targetRel = Path.GetDirectoryName(targetRel); if (environmentSettings.Host.FileSystem.DirectoryExists(targetPath)) { changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Overwrite)); } else { changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Create)); } } else if (environmentSettings.Host.FileSystem.FileExists(targetPath)) { changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Overwrite)); } else { changes.Add(new FileChange(sourceRel, targetRel, ChangeKind.Create)); } } break; } } } return(changes); }
private void RunInternal(IEngineEnvironmentSettings environmentSettings, IDirectory sourceDir, string targetDir, IGlobalRunSpec spec) { EngineConfig cfg = new EngineConfig(environmentSettings, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection); IProcessor fallback = Processor.Create(cfg, spec.Operations); List <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors = CreateFileGlobProcessors(sourceDir.MountPoint.EnvironmentSettings, spec); foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories)) { string sourceRel = file.PathRelativeTo(sourceDir); string fileName = Path.GetFileName(sourceRel); bool checkingDirWithPlaceholderFile = false; if (spec.IgnoreFileNames.Contains(fileName)) { // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed. // The change checking / reporting is different, setting this variable tracks it. checkingDirWithPlaceholderFile = true; } foreach (IPathMatcher include in spec.Include) { if (include.IsMatch(sourceRel)) { bool excluded = false; foreach (IPathMatcher exclude in spec.Exclude) { if (exclude.IsMatch(sourceRel)) { excluded = true; break; } } if (!excluded) { bool copy = false; foreach (IPathMatcher copyOnly in spec.CopyOnly) { if (copyOnly.IsMatch(sourceRel)) { copy = true; break; } } spec.LocalizationOperations.TryGetValue(sourceRel, out IReadOnlyList <IOperationProvider> locOperations); if (checkingDirWithPlaceholderFile) { CreateTargetDir(environmentSettings, sourceRel, targetDir, spec); } else if (!copy) { ProcessFile(file, sourceRel, targetDir, spec, fallback, fileGlobProcessors, locOperations); } else { string targetPath = CreateTargetDir(environmentSettings, sourceRel, targetDir, spec); using (Stream sourceStream = file.OpenRead()) using (Stream targetStream = environmentSettings.Host.FileSystem.CreateFile(targetPath)) { sourceStream.CopyTo(targetStream); } } } break; } } } }
private void RunInternal(IDirectory sourceDir, string targetDir, IGlobalRunSpec spec) { EngineConfig cfg = new EngineConfig(EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection); IProcessor fallback = Processor.Create(cfg, spec.Operations); List <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors = CreateFileGlobProcessors(spec); foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories)) { string sourceRel = file.PathRelativeTo(sourceDir); string fileName = Path.GetFileName(sourceRel); if (fileName == spec.PlaceholderFilename) { // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed. // So this happens before all the include / exclude / copy checks. CreateTargetDir(sourceRel, targetDir, spec); continue; } foreach (IPathMatcher include in spec.Include) { if (include.IsMatch(sourceRel)) { bool excluded = false; foreach (IPathMatcher exclude in spec.Exclude) { if (exclude.IsMatch(sourceRel)) { excluded = true; break; } } if (!excluded) { bool copy = false; foreach (IPathMatcher copyOnly in spec.CopyOnly) { if (copyOnly.IsMatch(sourceRel)) { copy = true; break; } } IReadOnlyList <IOperationProvider> locOperations; spec.LocalizationOperations.TryGetValue(sourceRel, out locOperations); if (!copy) { ProcessFile(file, sourceRel, targetDir, spec, fallback, fileGlobProcessors, locOperations); } else if (locOperations != null) { ProcessFile(file, sourceRel, targetDir, spec, fallback, Empty <KeyValuePair <IPathMatcher, IProcessor> > .List.Value, locOperations); } else { string targetPath = CreateTargetDir(sourceRel, targetDir, spec); using (Stream sourceStream = file.OpenRead()) using (Stream targetStream = File.Create(targetPath)) { sourceStream.CopyTo(targetStream); } } } break; } } } }
private static string CreateTargetDir(IEngineEnvironmentSettings environmentSettings, string sourceRel, string targetDir, IGlobalRunSpec spec) { if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel)) { targetRel = sourceRel; } string targetPath = Path.Combine(targetDir, targetRel); string fullTargetDir = Path.GetDirectoryName(targetPath); environmentSettings.Host.FileSystem.CreateDirectory(fullTargetDir); return(targetPath); }
public void Run(IGlobalRunSpec spec, IDirectory sourceDir, string targetDir) { RunInternal(sourceDir, targetDir, spec); }
private static List <KeyValuePair <IPathMatcher, IProcessor> > CreateFileGlobProcessors(IGlobalRunSpec spec) { List <KeyValuePair <IPathMatcher, IProcessor> > processorList = new List <KeyValuePair <IPathMatcher, IProcessor> >(); foreach (KeyValuePair <IPathMatcher, IRunSpec> runSpec in spec.Special) { IReadOnlyList <IOperationProvider> operations = runSpec.Value.GetOperations(spec.Operations); EngineConfig config = new EngineConfig(EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection); IProcessor processor = Processor.Create(config, operations); processorList.Add(new KeyValuePair <IPathMatcher, IProcessor>(runSpec.Key, processor)); } return(processorList); }
public void Run(IGlobalRunSpec spec, IDirectory sourceDir, string targetDir) { RunInternal(sourceDir.MountPoint.EnvironmentSettings, sourceDir, targetDir, spec); }
public IReadOnlyList <IFileChange> GetFileChanges(IGlobalRunSpec spec, IDirectory sourceDir, string targetDir) { return(GetFileChangesInternal(sourceDir.MountPoint.EnvironmentSettings, sourceDir, targetDir, spec)); }
public IReadOnlyList <IFileChange2> GetFileChanges(IGlobalRunSpec spec, IDirectory sourceDir, string targetRoot, string targetDir) { return(_basicOrchestrator.GetFileChanges(spec, sourceDir, targetRoot, targetDir)); }
public void Run(IGlobalRunSpec runSpec, IDirectory directoryInfo, string target) { _basicOrchestrator.Run(runSpec, directoryInfo, target); }
IReadOnlyList <IFileChange> IOrchestrator.GetFileChanges(IGlobalRunSpec spec, IDirectory sourceDir, string targetDir) { return(GetFileChanges(spec, sourceDir, targetDir)); }
private IReadOnlyList <IFileChange2> GetFileChangesInternal(IEngineEnvironmentSettings environmentSettings, IDirectory sourceDir, string targetRoot, string targetDir, IGlobalRunSpec spec) { List <IFileChange2> changes = new List <IFileChange2>(); string fullTargetPath = Path.Combine(targetRoot, targetDir); foreach (IFile file in sourceDir.EnumerateFiles("*", SearchOption.AllDirectories)) { string sourceRel = file.PathRelativeTo(sourceDir); string fileName = Path.GetFileName(sourceRel); bool checkingDirWithPlaceholderFile = false; if (spec.IgnoreFileNames.Contains(fileName)) { // The placeholder file should never get copied / created / processed. It just causes the dir to get created if needed. // The change checking / reporting is different, setting this variable tracks it. checkingDirWithPlaceholderFile = true; } foreach (IPathMatcher include in spec.Include) { if (include.IsMatch(sourceRel)) { bool excluded = false; foreach (IPathMatcher exclude in spec.Exclude) { if (exclude.IsMatch(sourceRel)) { excluded = true; break; } } if (!excluded) { if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel)) { targetRel = sourceRel; } string targetPath = Path.Combine(fullTargetPath, targetRel); string targetRelativePath = targetDir.CombinePaths(targetRel).TrimStart('/'); string sourceRelativePath = file.FullPath.CombinePaths().TrimStart('/'); if (checkingDirWithPlaceholderFile) { targetPath = Path.GetDirectoryName(targetPath); if (environmentSettings.Host.FileSystem.DirectoryExists(targetPath)) { changes.Add(new FileChange(sourceRelativePath, targetRelativePath, ChangeKind.Overwrite)); } else { changes.Add(new FileChange(sourceRelativePath, targetRelativePath, ChangeKind.Create)); } } else if (environmentSettings.Host.FileSystem.FileExists(targetPath)) { changes.Add(new FileChange(sourceRelativePath, targetRelativePath, ChangeKind.Overwrite)); } else { changes.Add(new FileChange(sourceRelativePath, targetRelativePath, ChangeKind.Create)); } } break; } } } return(changes); }
public IReadOnlyList <IFileChange2> GetFileChanges(IGlobalRunSpec spec, IDirectory sourceDir, string targetDir) { return(GetFileChangesInternal(sourceDir, targetDir, spec)); }
private void ProcessFile(IFile sourceFile, string sourceRel, string targetDir, IGlobalRunSpec spec, IProcessor fallback, IEnumerable <KeyValuePair <IPathMatcher, IProcessor> > fileGlobProcessors) { IProcessor runner = fileGlobProcessors.FirstOrDefault(x => x.Key.IsMatch(sourceRel)).Value ?? fallback; if (runner == null) { throw new InvalidOperationException("At least one of [runner] or [fallback] cannot be null"); } if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel)) { targetRel = sourceRel; } string targetPath = Path.Combine(targetDir, targetRel); //TODO: Update context with the current file & such here bool customBufferSize = TryGetBufferSize(sourceFile, out int bufferSize); bool customFlushThreshold = TryGetFlushThreshold(sourceFile, out int flushThreshold); string fullTargetDir = Path.GetDirectoryName(targetPath); _fileSystem.CreateDirectory(fullTargetDir); try { using (Stream source = sourceFile.OpenRead()) using (Stream target = _fileSystem.CreateFile(targetPath)) { if (!customBufferSize) { runner.Run(source, target); } else { if (!customFlushThreshold) { runner.Run(source, target, bufferSize); } else { runner.Run(source, target, bufferSize, flushThreshold); } } } } catch (TemplateAuthoringException ex) { throw new TemplateAuthoringException($"Template authoring error encountered while processing file {sourceFile.FullPath}: {ex.Message}", ex.ConfigItem, ex); } catch (Exception ex) { throw new ContentGenerationException($"Error while processing file {sourceFile.FullPath}", ex); } }
private static string CreateTargetDir(IPhysicalFileSystem fileSystem, string sourceRel, string targetDir, IGlobalRunSpec spec) { if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel)) { targetRel = sourceRel; } string targetPath = Path.Combine(targetDir, targetRel); string fullTargetDir = Path.GetDirectoryName(targetPath); fileSystem.CreateDirectory(fullTargetDir); return(targetPath); }