Пример #1
0
        public IEnumerable<IResource> FindResources(ResourceType resourceType)
        {
            var combined = new List<IResource>();
            foreach (IResourceFinder finder in _finders)
            {
                var found = finder.FindResources(resourceType).Where(IsNotExcluded);
                combined.AddRange(found);
            }

            return combined;
        }
Пример #2
0
 /// <summary>
 /// Recursively finds resources in the given directory with the given extension.
 /// </summary>
 /// <param name="resourceType">The resource type to be found.</param>
 /// <returns></returns>
 public IEnumerable<IResource> FindResources(ResourceType resourceType)
 {
     foreach (var extension in resourceType.FileExtensions)
     {
         string[] files = Directory.GetFiles(_directory, "*" + extension, SearchOption.AllDirectories);
         foreach (string filePath in files)
         {
             yield return new FileResource(filePath, _directory);
         }
     }
 }
Пример #3
0
        public IEnumerable<IResource> FindResources(ResourceType resourceType)
        {
            var resources = _inner.FindResources(resourceType).ToArray();
            var externallyCompiledPairs = resources.ExternallyCompiled();

            foreach (var resource in resources)
            {
                var externallyCompiledPair = externallyCompiledPairs.SingleOrDefault(resource.VirtualPath);
                if(externallyCompiledPair == null)
                {
                    yield return resource;
                }
                else
                {
                    var resourceWithProperMode = externallyCompiledPair.WithMode(_resourceMode);
                    if(resourceWithProperMode.VirtualPath.EqualsVirtualPath(resource.VirtualPath))
                        yield return new ExternallyCompiledResource(externallyCompiledPair, resourceWithProperMode);
                }
            }
        }
 public void StoreResources(ResourceType resourceType, IEnumerable<IResource> resources)
 {
     _resources.Set(resourceType, resources);
 }
Пример #5
0
 public IEnumerable<IResource> FindResources(ResourceType resourceType)
 {
     return from resourceName in _assembly.GetManifestResourceNames()
             where resourceType.FileExtensions.Any(resourceName.EndsWith)
             select CreateEmbeddedResource(resourceName);
 }
Пример #6
0
 public ResourceGroup(string consolidatedUrl, IEnumerable<IResource> resources)
 {
     ConsolidatedUrl = consolidatedUrl;
     _resources = resources.ToList();
     _resourceType = ResourceType.FromPath(ConsolidatedUrl);
 }
Пример #7
0
        public static IEnumerable<IResource> GetOrAddResources(this IResourceCache resourceCache, ResourceType resourceType, Func<IEnumerable<IResource>> findResources)
        {
            IEnumerable<IResource> resources;
            if (resourceCache.TryGetResources(resourceType, out resources))
                return resources;

            resources = findResources();

            if(resources != null)
            {
                resourceCache.StoreResources(resourceType, resources);
            }

            return resources;
        }
Пример #8
0
 public bool TryGetResources(ResourceType resourceType, out IEnumerable<IResource> cachedResources)
 {
     cachedResources = null;
     return false;
 }
Пример #9
0
 public void StoreResources(ResourceType resourceType, IEnumerable<IResource> resources)
 {
 }
Пример #10
0
 private IResourceGroupManager GroupManagerFor(ResourceType resourceType)
 {
     if (resourceType == ResourceType.Stylesheet)
         return _styleGroups;
     else
         return _scriptGroups;
 }
Пример #11
0
        private IEnumerable<PreCompiledResourceGroup> ConsolidateGroupsInternal(ResourceType resourceType,
            IResourceGroupManager groupTemplates,
            Action<ICompiledResource> onCompiled)
        {
            if (!groupTemplates.Any())
                return Enumerable.Empty<PreCompiledResourceGroup>();

            var allResources = _finder.FindResources(resourceType).ToArray();

            var preConsolidatedGroups = new List<PreCompiledResourceGroup>();
            groupTemplates.EachGroup(allResources, group =>
            {
                var consolidatedResource = CompileGroup(group);
                onCompiled(consolidatedResource);
                var preConsolidatedGroup = new PreCompiledResourceGroup
                {
                    ConsolidatedUrl = group.ConsolidatedUrl,
                    Resources = consolidatedResource.Resources.Select(resource => resource.VirtualPath).ToList()
                };
                preConsolidatedGroups.Add(preConsolidatedGroup);
            });

            return preConsolidatedGroups;
        }
Пример #12
0
        private PreCompiledResourceReport CompileAllResourcesOfType(ResourceType resourceType,
            Action<ICompiledResource> onCompiled)
        {
            var groupManager = GroupManagerFor(resourceType);

            return new PreCompiledResourceReport
            {
                Groups = ConsolidateGroupsInternal(resourceType, groupManager, onCompiled).ToList(),
                SingleResources = CompileUnconsolidatedResources(resourceType, onCompiled)
                    .Select(r => new PreCompiledSingleResource
                    {
                        OriginalPath = r.Resources.Single().VirtualPath,
                        CompiledPath = r.CompiledPath
                    }).ToList()
            };
        }
Пример #13
0
 public IEnumerable<IResource> FindResources(ResourceType resourceType)
 {
     yield break;
 }
 public bool TryGetResources(ResourceType resourceType, out IEnumerable<IResource> cachedResources)
 {
     return GetInnerCache().TryGetResources(resourceType, out cachedResources);
 }
 public void StoreResources(ResourceType resourceType, IEnumerable<IResource> resources)
 {
     GetInnerCache().StoreResources(resourceType, resources);
 }
 public bool TryGetResources(ResourceType resourceType, out IEnumerable<IResource> cachedResources)
 {
     return _resources.TryGetValue(resourceType, out cachedResources);
 }
Пример #17
0
 public IEnumerable<IResource> FindResources(ResourceType resourceType)
 {
     return _cache.GetOrAddResources(resourceType, () => _inner.FindResources(resourceType));
 }
Пример #18
0
        public IEnumerable<ICompiledResource> CompileUnconsolidatedResources(ResourceType resourceType, Action<ICompiledResource> handleCompiledResource)
        {
            var resources = _finder.FindResources(resourceType).ToArray();

            var groupManager = GroupManagerFor(resourceType);

            var unconsolidatedResources = (from resource in resources
                                           where !resource.IsExternallyCompiled()
                                                 && !groupManager.IsPartOfGroup(resource.VirtualPath)
                                                 && CanCompileIndividually(resource)
                                           select resource).ToList();

            var compiledResources = new List<ICompiledResource>();
            foreach (var unconsolidatedResource in unconsolidatedResources)
            {
                var compiledResource = CompileResource(unconsolidatedResource);
                handleCompiledResource(compiledResource);
                compiledResources.Add(compiledResource);
            }

            return compiledResources;
        }