Beispiel #1
0
        /// <summary>
        /// Add images to be generated into sprite image.
        /// </summary>
        /// <param name="imageOutputPath">Sprite image output path.</param>
        /// <param name="spriteImageUrl">Sprite image url.</param>
        /// <param name="cssOutputPath">Sprite css output path.</param>
        /// <param name="files">The component images for the sprite.</param>
        /// <param name="directories">The component images via convention for the sprite </param>
        public virtual IEnumerable <ImageFile> AddFiles(FileInfo imageOutputPath, Uri spriteImageUrl, FileInfo cssOutputPath, IEnumerable <ImageFile> files, IEnumerable <ImageDirectory> directories)
        {
            var filesToWatch  = GetFilesToWatch(files, directories);
            var metaDataFiles = filesToWatch.Select(x => new FileInfo(x.FilePath)).Distinct().OrderBy(x => x.FullName);

            var isMetaDataFresh = FileMetaData.IsMetaDataFresh(cssOutputPath, metaDataFiles);

            if (!isMetaDataFresh)
            {
                var spriteElements = ProcessFiles(filesToWatch);
                spriteElements = CalculatePositions(spriteElements);
                var etag = SaveSpritesImage(spriteElements, imageOutputPath);
                var css  = GetCssSpriteCss(spriteElements, etag, spriteImageUrl);
                RetryableFileWriter.SaveContentsToFile(css, cssOutputPath);

                FileMetaData.CreateMetaData(cssOutputPath, metaDataFiles);
            }

            var foldersToWatch = directories
                                 .Select(x => Talifun.FileWatcher.EnhancedFileSystemWatcherFactory.Instance
                                         .CreateEnhancedFileSystemWatcher(new Uri(PathProvider.MapPath(x.DirectoryPath)).LocalPath, x.IncludeFilter, x.ExcludeFilter, x.PollTime, x.IncludeSubDirectories));

            AddFilesToCache(imageOutputPath, spriteImageUrl, cssOutputPath, filesToWatch, files, foldersToWatch, directories);

            return(filesToWatch);
        }
Beispiel #2
0
        /// <summary>
        /// Compress the js files and store them in the specified js file.
        /// </summary>
        /// <param name="outputFileInfo">The output path for the crushed js file.</param>
        /// <param name="files">The js files to be crushed.</param>
        /// <param name="directories"> </param>
        public virtual JsCrushedOutput ProcessGroup(FileInfo outputFileInfo, IEnumerable <JsFile> files, IEnumerable <JsDirectory> directories)
        {
            var filesToWatch = GetFilesToWatch(files, directories);

            var metaDataFiles = filesToWatch.Select(x => new FileInfo(x.FilePath)).Distinct().OrderBy(x => x.FullName);

            var isMetaDataFresh = FileMetaData.IsMetaDataFresh(outputFileInfo, metaDataFiles);

            if (!isMetaDataFresh)
            {
                var content = GetGroupContent(filesToWatch);

                RetryableFileWriter.SaveContentsToFile(content, outputFileInfo);

                FileMetaData.CreateMetaData(outputFileInfo, metaDataFiles);
            }

            var foldersToWatch = directories
                                 .Select(x => Talifun.FileWatcher.EnhancedFileSystemWatcherFactory.Instance
                                         .CreateEnhancedFileSystemWatcher(new Uri(PathProvider.MapPath(x.DirectoryPath)).LocalPath, x.IncludeFilter, x.ExcludeFilter, x.PollTime, x.IncludeSubDirectories));

            var crushedOutput = new JsCrushedOutput
            {
                FoldersToWatch = foldersToWatch,
                FilesToWatch   = filesToWatch
            };

            return(crushedOutput);
        }
Beispiel #3
0
        /// <summary>
        /// Compress the css files and store them in the specified css file.
        /// </summary>
        /// <param name="outputFileInfo">The virtual path for the crushed js file.</param>
        /// <param name="cssRootUri">The path for the crushed css file.</param>
        /// <param name="files">The css files to be crushed.</param>
        /// <param name="directories">The css directories to be crushed.</param>
        /// <param name="appendHashToAssets"></param>
        public virtual CssCrushedOutput ProcessGroup(FileInfo outputFileInfo, Uri cssRootUri, IEnumerable <CssFile> files, IEnumerable <CssDirectory> directories, bool appendHashToAssets)
        {
            var filesToWatch = GetFilesToWatch(files, directories);

            var filesToProcess = filesToWatch
                                 .Select(cssFile => new CssFileProcessor(RetryableFileOpener, PathProvider, CssPathRewriter, cssFile.FilePath, cssFile.CompressionType, cssRootUri, appendHashToAssets));

            var localCssAssetFilesThatExist = new List <FileInfo>();

            if (WatchAssets)
            {
                localCssAssetFilesThatExist = filesToProcess
                                              .SelectMany(x => x.GetLocalCssAssetFilesThatExist().Select(y => y.File))
                                              .ToList();
            }

            var metaDataFiles = filesToWatch
                                .Select(x => new FileInfo(x.FilePath)).Concat(localCssAssetFilesThatExist)
                                .Distinct()
                                .OrderBy(x => x.FullName);

            var isMetaDataFresh = FileMetaData.IsMetaDataFresh(outputFileInfo, metaDataFiles);

            if (!isMetaDataFresh)
            {
                var content = GetGroupContent(filesToProcess);

                RetryableFileWriter.SaveContentsToFile(content, outputFileInfo);

                FileMetaData.CreateMetaData(outputFileInfo, metaDataFiles);
            }

            var foldersToWatch = directories
                                 .Select(x => Talifun.FileWatcher.EnhancedFileSystemWatcherFactory.Instance
                                         .CreateEnhancedFileSystemWatcher(new Uri(PathProvider.MapPath(x.DirectoryPath)).LocalPath, x.IncludeFilter, x.ExcludeFilter, x.PollTime, x.IncludeSubDirectories));

            var crushedOutput = new CssCrushedOutput
            {
                FilesToWatch      = filesToWatch,
                FoldersToWatch    = foldersToWatch,
                CssAssetFilePaths = localCssAssetFilesThatExist
            };

            return(crushedOutput);
        }