Exemple #1
0
        public Stream OpenRead(string path)
        {
            if (!IsPathInCone(path, out string processedPath))
            {
                return(_basis.OpenRead(path));
            }

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

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

            for (int i = 0; i < parts.Length - 1; ++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;
            }

            FileSystemFile targetFile;

            if (!currentDir.Files.TryGetValue(parts[parts.Length - 1], out targetFile))
            {
                throw new FileNotFoundException("File not found", path);
            }

            return(targetFile.OpenRead());
        }
Exemple #2
0
 internal static JObject ReadObject(this IPhysicalFileSystem fileSystem, string path)
 {
     using (var fileStream = fileSystem.OpenRead(path))
         using (var textReader = new StreamReader(fileStream, System.Text.Encoding.UTF8, true))
             using (var jsonReader = new JsonTextReader(textReader))
             {
                 return(JObject.Load(jsonReader));
             }
 }
Exemple #3
0
        public void Run(string runSpecPath, IDirectory sourceDir, string targetDir)
        {
            IGlobalRunSpec spec;

            using (Stream stream = _fileSystem.OpenRead(runSpecPath))
            {
                spec = RunSpecLoader(stream);
                EngineConfig config    = new EngineConfig(_logger, EngineConfig.DefaultWhitespaces, EngineConfig.DefaultLineEndings, spec.RootVariableCollection);
                IProcessor   processor = Processor.Create(config, spec.Operations);
                stream.Position = 0;
                using (MemoryStream ms = new MemoryStream())
                {
                    processor.Run(stream, ms);
                    ms.Position = 0;
                    spec        = RunSpecLoader(ms);
                }
            }

            RunInternal(sourceDir, targetDir, spec);
        }