Example #1
0
        public void CreateDirectory(string path)
        {
            if (!IsPathInCone(path, out string processedPath))
            {
                _basis.CreateDirectory(path);
                return;
            }

            path = processedPath;
            string rel = path.Substring(_root.FullPath.Length).Trim('/', '\\');

            if (string.IsNullOrEmpty(rel))
            {
                return;
            }

            string[]            parts      = rel.Split('/', '\\');
            FileSystemDirectory currentDir = _root;

            for (int i = 0; i < parts.Length; ++i)
            {
                FileSystemDirectory dir;
                if (!currentDir.Directories.TryGetValue(parts[i], out dir))
                {
                    dir = new FileSystemDirectory(parts[i], Path.Combine(currentDir.FullPath, parts[i]));
                    currentDir.Directories[parts[i]] = dir;
                }

                currentDir = dir;
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
        }