예제 #1
0
        public FileAsset(IFile sourceFile, Bundle parentBundle)
        {
            this.parentBundle = parentBundle;
            this.sourceFile = sourceFile;

            hash = new Lazy<byte[]>(HashFileContents); // Avoid file IO until the hash is actually needed.
        }
 void IBundleVisitor.Visit(Bundle bundle)
 {
     if (IsMatch(bundle.Path))
     {
         isFound = true;
     }
 }
 Bundle CreateExternalBundle(string url, Bundle referencer)
 {
     var bundleFactory = GetBundleFactory(referencer.GetType());
     var externalBundle = bundleFactory.CreateExternalBundle(url);
     externalBundle.Process(settings);
     return externalBundle;
 }
예제 #4
0
 public ResourceAsset(string resourceName, Assembly assembly, Bundle parentBundle)
 {
     this.resourceName = ResolveResourceName(resourceName, assembly);
     resourceFile = new ResourceFile("~/" + this.resourceName);
     this.assembly = assembly;
     this.parentBundle = parentBundle;
     this.hash = new Lazy<byte[]>(ComputeHash);
 }
예제 #5
0
        public string CreateBundleUrl(Bundle bundle)
        {
            var url = bundle.Url;
            if (url.IsUrl()) return url;

            url = routePrefix + "/" + url;
            return urlModifier.Modify(url);
        }
        void IBundleVisitor.Visit(Bundle bundle)
        {
            normalizedPath = originalPath.IsUrl() ? originalPath : NormalizePath(originalPath, bundle);

            if (IsMatch(bundle.Path))
            {
                isFound = true;
            }
        }
예제 #7
0
 public string CreateBundleUrl(Bundle bundle)
 {
     var theme = string.Empty;
     if (bundle.HtmlAttributes.ContainsAttribute("data-theme"))
     {
         theme = bundle.HtmlAttributes["data-theme"];
     }
     return new Url( _inner.CreateBundleUrl(bundle)).AppendQuery("theme", theme);
 }
        void IBundleVisitor.Visit(Bundle bundle)
        {
            currentBundle = bundle;

            var urlReferencesNotYetSeen = bundle.References.Where(IsUrlReferenceNotYetSeen);
            foreach (var reference in urlReferencesNotYetSeen)
            {
                RecordUrlAsSeen(reference);
                AddNewExternalBundle(reference);
            }
        }
 string NormalizePath(string path, Bundle bundle)
 {
     path = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
     if (path.StartsWith("~"))
     {
         return path;
     }
     else
     {
         return PathUtilities.CombineWithForwardSlashes(bundle.Path, path);
     }
 }
예제 #10
0
        void AddBundlesReferencedBy(Bundle bundle, ISet<Bundle> all)
        {
            if (all.Contains(bundle)) return;
            all.Add(bundle);

            HashSet<Bundle> referencedBundles;
            if (!bundleImmediateReferences.TryGetValue(bundle, out referencedBundles)) return;
            foreach (var referencedBundle in referencedBundles)
            {
                AddBundlesReferencedBy(referencedBundle, all);
            }
        }
예제 #11
0
 public string CreateBundleUrl(Bundle bundle)
 {
     return urlModifier.Modify(
         String.Format(
             "{0}/{1}/{2}_{3}",
             routePrefix,
             ConventionalBundlePathName(bundle.GetType()),
             bundle.PathWithoutPrefix,
             bundle.Hash.ToHexString()
         )
     );
 }
예제 #12
0
파일: Asset.cs 프로젝트: jlopresti/cassette
        public Asset_Tests()
        {
            root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
            root.CreateSubdirectory("bundle");

            bundle = new TestableBundle("~/bundle");
            sourceFile = StubFile("asset content");
            asset = new FileAsset(sourceFile, bundle);
            bundle.Assets.Add(asset);

            var another = new FileAsset(StubFile(fullPath: "~/bundle/another.js"), bundle);
            bundle.Assets.Add(another);
        }
        public static bool TryGetAssetByPath(this IBundleContainer bundleContainer, string path, out IAsset asset, out Bundle bundle)
        {
            var results =
                from b in bundleContainer.FindBundlesContainingPath(path)
                let a = b.FindAssetByPath(path)
                where a != null
                select new { Bundle = b, Asset = a };

            var result = results.FirstOrDefault();
            if (result != null)
            {
                asset = result.Asset;
                bundle = result.Bundle;
                return true;
            }
            else
            {
                asset = null;
                bundle = null;
                return false;
            }
        }
예제 #14
0
 public void Visit(Bundle bundle)
 {
     if (FoundAsset != null) return;
 }
        public void WhenInterdependenciesBetweenBundlesOfDifferentType_DoesNotDuplicateBundles()
        {
            var bundleA = new ScriptBundle("~/a");
            var bundleB = new StylesheetBundle("~/b");
            var bundleC = new TestableBundle("~/c");
            bundleC.AddReference("~/a");

            var bundles = new Bundle[] { bundleA, bundleB, bundleC };
            var collection = CreateBundleCollection(bundles);
            collection.BuildReferences();
            var sorted = collection.SortBundles(bundles).ToArray();

            sorted.ShouldEqual(new Bundle[]
            {
                bundleB,
                bundleA,
                bundleC
            });
        }
예제 #16
0
 public void Visit(Bundle bundle)
 {
 }
예제 #17
0
        static bool AllAssetsEqual(Bundle x, Bundle y)
        {
            var collectorX = new CollectLeafAssets();
            x.Accept(collectorX);
            var collectorY = new CollectLeafAssets();
            y.Accept(collectorY);

            var assetsX = collectorX.Assets.OrderBy(a => a.Path);
            var assetsY = collectorY.Assets.OrderBy(a => a.Path);
            return assetsX.SequenceEqual(assetsY, new AssetPathComparer());
        }
예제 #18
0
 IEnumerable<AssetReference> GetNonSameBundleAssetReferences(Bundle bundle)
 {
     var collector = new BundleReferenceCollector(AssetReferenceType.DifferentBundle, AssetReferenceType.Url);
     bundle.Accept(collector);
     return collector.CollectedReferences.Select(r => r.AssetReference);
 }
예제 #19
0
 static bool PathsEqual(Bundle x, Bundle y)
 {
     return string.Equals(x.Path, y.Path, StringComparison.OrdinalIgnoreCase);
 }
예제 #20
0
 void IBundleVisitor.Visit(Bundle bundle)
 {
 }
        public void WhenSortDifferentTypesOfBundle_ThenSortsArePartitioned()
        {
            var bundleA = new ScriptBundle("~/a");
            var bundleB = new StylesheetBundle("~/b");
            var bundleC = new ScriptBundle("~/c");

            var bundles = new Bundle[] { bundleA, bundleB, bundleC };
            var collection = CreateBundleCollection(bundles);
            collection.BuildReferences();
            var sorted = collection.SortBundles(bundles);

            sorted.ShouldEqual(new Bundle[]
            {
                bundleA,
                bundleC,
                bundleB
            });
        }
예제 #22
0
 public string CreateBundleUrl(Bundle bundle)
 {
     var path = urlModifier.GetPath(bundle.Url, bundle.CacheFilename);
     var url = cassetteHandlerPrefix + path;
     return urlModifier.Modify(url);
 }
 public bool BundleContainsPath(string path, Bundle bundle)
 {
     pathToFind = path.IsUrl() ? path : NormalizePath(path, bundle);
     bundle.Accept(this);
     return isFound;
 }
 public void Visit(Bundle bundle)
 {
     currentBundle = bundle;
 }
예제 #25
0
 static bool TypesEqual(Bundle x, Bundle y)
 {
     return x.GetType() == y.GetType();
 }
예제 #26
0
 public string CreateBundleUrl(Bundle bundle)
 {
     var url = cassetteHandlerPrefix + bundle.Url;
     return urlModifier.Modify(url);
 }
 public void Visit(Bundle bundle)
 {
     VisitBundle(bundle);
 }