示例#1
0
        public virtual T CreateBundle(string path, IEnumerable <IFile> allFiles, BundleDescriptor bundleDescriptor)
        {
            var bundle     = CreateBundleCore(path, bundleDescriptor);
            var filesArray = allFiles.ToArray();

            AddAssets(bundle, filesArray, bundleDescriptor.AssetFilenames);
            AddReferences(bundle, bundleDescriptor.References);
            SetIsSortedIfExplicitFilenames(bundle, bundleDescriptor.AssetFilenames);
            return(bundle);
        }
示例#2
0
 T CreateSingleFileBundle <T>(
     string applicationRelativePath,
     IFile file,
     IBundleFactory <T> bundleFactory,
     BundleDescriptor descriptor = null) where T : Bundle
 {
     descriptor = descriptor ?? new BundleDescriptor
     {
         AssetFilenames = { applicationRelativePath }
     };
     return(bundleFactory.CreateBundle(applicationRelativePath, new[] { file }, descriptor));
 }
示例#3
0
        public void AddUrlWithLocalAssets <T>(string url, LocalAssetSettings localAssetSettings, Action <Bundle> customizeBundle = null)
            where T : Bundle
        {
            var existingBundle = bundles.FirstOrDefault(
                b => b.ContainsPath(PathUtilities.AppRelative(localAssetSettings.Path))
                );

            if (existingBundle != null)
            {
                Remove(existingBundle);
            }

            var bundleFactory   = bundleFactoryProvider.GetBundleFactory <T>();
            var sourceDirectory = settings.SourceDirectory;
            IEnumerable <IFile> files;
            BundleDescriptor    bundleDescriptor;

            if (sourceDirectory.DirectoryExists(localAssetSettings.Path))
            {
                var fileSearch = localAssetSettings.FileSearch ?? fileSearchProvider.GetFileSearch(typeof(T));
                var directory  = sourceDirectory.GetDirectory(localAssetSettings.Path);
                files = fileSearch.FindFiles(directory);

                var descriptorFile = TryGetDescriptorFile <T>(directory);
                bundleDescriptor = ReadOrCreateBundleDescriptor(descriptorFile);
            }
            else
            {
                var singleFile = sourceDirectory.GetFile(localAssetSettings.Path);
                if (singleFile.Exists)
                {
                    files            = new[] { singleFile };
                    bundleDescriptor = new BundleDescriptor {
                        AssetFilenames = { "*" }
                    };
                }
                else
                {
                    throw new DirectoryNotFoundException(string.Format("File or directory not found: \"{0}\"", localAssetSettings.Path));
                }
            }

            bundleDescriptor.FallbackCondition = localAssetSettings.FallbackCondition;
            bundleDescriptor.ExternalUrl       = url;
            var bundle = bundleFactory.CreateBundle(localAssetSettings.Path, files, bundleDescriptor);

            if (customizeBundle != null)
            {
                customizeBundle(bundle);
            }
            Add(bundle);
        }
示例#4
0
 T CreateDirectoryBundle <T>(
     string applicationRelativePath,
     IBundleFactory <T> bundleFactory,
     IEnumerable <IFile> allFiles,
     IDirectory directory,
     BundleDescriptor descriptor = null) where T : Bundle
 {
     if (descriptor == null)
     {
         var descriptorFile = TryGetDescriptorFile <T>(directory);
         descriptor = ReadOrCreateBundleDescriptor(descriptorFile);
     }
     return(bundleFactory.CreateBundle(applicationRelativePath, allFiles, descriptor));
 }
 public BundleDescriptor Read()
 {
     using (var stream = sourceFile.OpenRead())
     using (var reader = new StreamReader(stream))
     {
         string line;
         while ((line = reader.ReadLine()) != null)
         {
             ProcessLine(line);
         }
     }
     var descriptor = new BundleDescriptor();
     descriptor.AssetFilenames.AddRange(assetFilenames);
     descriptor.References.AddRange(references);
     descriptor.ExternalUrl = externalUrl;
     descriptor.FallbackCondition = fallbackCondition;
     return descriptor;
 }
        public BundleDescriptor Read()
        {
            using (var stream = sourceFile.OpenRead())
                using (var reader = new StreamReader(stream))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        ProcessLine(line);
                    }
                }
            var descriptor = new BundleDescriptor();

            descriptor.AssetFilenames.AddRange(assetFilenames);
            descriptor.References.AddRange(references);
            descriptor.ExternalUrl       = externalUrl;
            descriptor.FallbackCondition = fallbackCondition;
            return(descriptor);
        }
示例#7
0
 protected abstract T CreateBundleCore(string path, BundleDescriptor bundleDescriptor);