Ejemplo n.º 1
1
        public SpecPath(string fullPath)
            : base(fullPath)
        {
            _parts = new List<string>();

            var path = new AssetPath(fullPath);
            if (path.Package != null) _parts.Add(path.Package);
            _parts.AddRange(path.Name.Split('/'));
        }
Ejemplo n.º 2
0
        public void Execute(AssetPath path, ProcessContentAction continuation)
        {
            var source = _cache.SourceFor(path);
            var contents = source.GetContent(_pipeline);

            continuation(contents, source.Files);
        }
 public void SetUp()
 {
     _theFileGraph = new AssetFileGraph();
     _theFile = new AssetFile("a.js");
     _thePath = new AssetPath("pak1", "a.js", AssetFolder.scripts);
     _theFileGraph.AddFile(_thePath, _theFile);
 }
Ejemplo n.º 4
0
        private IEnumerable<AssetFile> writeBinary(AssetPath asset)
        {
            var file = _pipeline.Find(asset);
            _writer.WriteFile(file.MimeType, file.FullPath, null);

            return new AssetFile[]{file};
        }
Ejemplo n.º 5
0
 public void path_with_package_and_type_specified()
 {
     var path = new AssetPath("pak1:scripts/jquery.js");
     path.Folder.ShouldEqual(AssetFolder.scripts);
     path.Name.ShouldEqual("jquery.js");
     path.Package.ShouldEqual("pak1"); 
 }
Ejemplo n.º 6
0
 public void simple_path_with_no_package_or_type()
 {
     var path = new AssetPath("jquery.js");
     path.Folder.ShouldBeNull();
     path.Name.ShouldEqual("jquery.js");
     path.Package.ShouldBeNull();
 }
Ejemplo n.º 7
0
 public void path_with_type_specified_but_no_package()
 {
     var path = new AssetPath("scripts/jquery.js");
     path.Folder.ShouldEqual(AssetFolder.scripts);
     path.Name.ShouldEqual("jquery.js");
     path.Package.ShouldBeNull();
 }
        public static HttpResponse GetAsset(this EndpointDriver endpoints, AssetFolder folder, string name, string etag = null)
        {
            var path = new AssetPath(name, folder);

            return endpoints.GetByInput(path, configure:request => {
                request.Headers.Add(HttpRequestHeader.IfNoneMatch, etag);
            });
        }
Ejemplo n.º 9
0
        private IEnumerable<AssetFile> writeTextualAsset(AssetPath asset)
        {
            var source = _cache.SourceFor(asset);
            var contents = source.GetContent(_contentPipeline);

            _writer.Write(source.Files.First().MimeType, contents);

            return source.Files;
        }
Ejemplo n.º 10
0
        public void AddFile(AssetPath path, AssetFile file)
        {
            if (!path.Folder.HasValue)
            {
                throw new ArgumentException("AssetPath must have an AssetType to be used here");
            }

            _files[path.Folder.Value].Add(file);
        }
Ejemplo n.º 11
0
        public void CreateAssetFile(string filename)
        {
            var name = filename.PathRelativeTo(_specificDirectory).Replace(Path.DirectorySeparatorChar, '/');
            var path = new AssetPath(_directory.PackageName, name, _assetFolder);
            var file = new AssetFile(name){
                FullPath = filename.ToFullPath()
            };

            _registration.AddFile(path, file);
        }
Ejemplo n.º 12
0
        public void Write(AssetPath path)
        {
            //_output.AppendHeader(HttpResponseHeader.ETag, "random");

            if (!_writer.Write(path, files => processAssetFiles(path, files)))
            {
                _output.Write("Cannot find asset " + path.ToFullName());
                _output.WriteResponseCode(HttpStatusCode.NotFound);
            }
        }
        public void adding_a_file_by_path_sets_the_folder_on_the_file()
        {
            // This is important for later
            var theFile = new AssetFile("a.js");

            var thePath = new AssetPath("pak1", "a.js", AssetFolder.styles);

            _theFileGraph.AddFile(thePath, theFile);

            theFile.Folder.ShouldEqual(thePath.Folder);
        }
Ejemplo n.º 14
0
        public IEnumerable<AssetFile> Write(AssetPath asset)
        {
            if (asset.IsImage())
            {
                return writeBinary(asset);
            }

            // TODO -- have to deal with the [package]:scripts/
            // think it'll just be testing
            return writeTextualAsset(asset);
        }
 public bool Write(AssetPath asset, Action<IEnumerable<AssetFile>> writeHeaders)
 {
     if (asset.IsBinary())
     {
         return writeBinary(asset, writeHeaders).Any();
     }
     
     // TODO -- have to deal with the [package]:scripts/
     // think it'll just be testing
     return writeTextualAsset(asset, writeHeaders).Any();
 }
Ejemplo n.º 16
0
        // Not worrying about throwing exceptions for something not found here.
        public AssetFile Find(AssetPath path)
        {
            if (path.Package.IsNotEmpty())
            {
                return _packages[path.Package].FindByPath(path).FirstOrDefault();
            }

            var files = _allPackages.SelectMany(x => x.FindByPath(path));

            return files.FirstOrDefault(x => x.Override) ?? files.FirstOrDefault();
        }
Ejemplo n.º 17
0
        private void processAssetFiles(AssetPath path, IEnumerable<AssetFile> files)
        {
            var etag = _eTagGenerator.Create(files);

            _cache.LinkFilesToResource(path.ResourceHash, files);

            _output.AppendHeader(HttpResponseHeader.ETag, etag);

            if (!FubuMode.InDevelopment())
            {
                _cachingHeaders.HeadersFor(files).Each(x => x.Write(_output));
            }
        }
Ejemplo n.º 18
0
        private IEnumerable<AssetFile> writeBinary(AssetPath asset)
        {
            var file = _fileGraph.Find(asset);

            if (file == null)
            {
                return Enumerable.Empty<AssetFile>();
            }

            _writer.WriteFile(file.MimeType, file.FullPath, null);

            return new AssetFile[]{file};
        }
Ejemplo n.º 19
0
 public void Write(AssetPath path)
 {
     var files = _writer.Write(path);
     if (files.Any())
     {
         processAssetFiles(path, files);
     }
     else
     {
         _output.WriteResponseCode(HttpStatusCode.NotFound);
         _output.Write("Cannot find asset " + path.ToFullName());
     }
 }
        private IEnumerable<AssetFile> writeTextualAsset(AssetPath asset, Action<IEnumerable<AssetFile>> writeHeaders)
        {
            var source = _cache.SourceFor(asset);
            if (source.Files.Any())
            {
                writeHeaders(source.Files);

                var contents = source.GetContent(_contentPipeline);
                _writer.Write(source.Files.First().MimeType, contents);
            }


            return source.Files;
        }
        private IEnumerable<AssetFile> writeBinary(AssetPath asset, Action<IEnumerable<AssetFile>> writeHeaders)
        {
            var file = _fileGraph.Find(asset);
            

            if (file == null)
            {
                return Enumerable.Empty<AssetFile>();
            }

            var files = new AssetFile[] { file };
            writeHeaders(files);

            _writer.WriteFile(file.MimeType, file.FullPath, null);
            
            return files;
        }
Ejemplo n.º 22
0
        public IEnumerable<AssetFile> FindByPath(AssetPath path)
        {
            if (path.Folder.HasValue)
            {
                return matchingType(path.Folder.Value, path.Name);
            }

            var scripts = matchingType(AssetFolder.scripts, path.Name);
            if (scripts.Any()) return scripts;

            var styles = matchingType(AssetFolder.styles, path.Name);
            if (styles.Any()) return styles;

            var images = matchingType(AssetFolder.images, path.Name);
            if (images.Any()) return images;

            return new AssetFile[0];
        }
Ejemplo n.º 23
0
 public void WriteContent(IEnumerable<string> routeParts)
 {
     var path = new AssetPath(routeParts);
     if (path.IsImage())
     {
         _images.WriteImageToOutput(path.ToFullName());
     }
     else
     {
         // TODO -- have to deal with the [package]:scripts/
         // think it'll just be testing
         _executor.Execute(path, (contents, files) =>
         {
             _caching.CacheRequestAgainstFileChanges(files.Select(x => x.FullPath));
             _writer.Write(files.First().MimeType, contents);
         });
     }
 }
Ejemplo n.º 24
0
        //key=type/name
        private void LoadAsset(string line)
        {
            if (line.Trim().IsEmpty()) return;

            var parts = line.Split('=');
            var key = parts.First();
            var stringPath = parts.Last();
            var @override = stringPath.EndsWith("!override");
            if (@override)
            {
                stringPath = stringPath.Replace("!override", "");
            }

            var path = new AssetPath(stringPath);

            var file = new AssetFile(path.Name){
                Override = @override
            };

            _files[key] = file;

            _callback(path, file);
        }
Ejemplo n.º 25
0
        public AssetFile FindByName(string name)
        {
            var path = new AssetPath(name);

            return(FindByPath(path).SingleOrDefault());
        }
Ejemplo n.º 26
0
 public AssetFile FindByName(string name)
 {
     var path = new AssetPath(name);
     return FindByPath(path).SingleOrDefault();
 }
Ejemplo n.º 27
0
 public bool Equals(AssetPath other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Name, Name) && Equals(other.Package, Package) && other.Folder.Equals(Folder);
 }
 public void AddFile(AssetPath path, AssetFile file)
 {
     _assetLogsCache.FindByName(file.Name).Add(path.Package,"Adding {0} to IAssetFileGraph".ToFormat(file.FullPath));
     _inner.AddFile(path, file);
 }
Ejemplo n.º 29
0
 public void path_with_package_but_no_type_specified()
 {
     var path = new AssetPath("pak1:jquery.js");
     path.Folder.ShouldBeNull();
     path.Name.ShouldEqual("jquery.js");
     path.Package.ShouldEqual("pak1"); 
 }
 public AssetFile Find(AssetPath path)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 31
0
 public void AddFile(AssetPath path, AssetFile file)
 {
     if (path.Folder != null) file.Folder = path.Folder;
     _packages[path.Package].AddFile(path, file);
 }