Beispiel #1
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="cssFiles">The css files to be crushed.</param>
        /// <param name="appendHashToAssets"></param>
        public virtual CssCrushedOutput ProcessFiles(FileInfo outputFileInfo, Uri cssRootUri, IEnumerable <CssFile> cssFiles, bool appendHashToAssets)
        {
            var uncompressedContents                   = new StringBuilder();
            var yahooYuiToBeCompressedContents         = new StringBuilder();
            var microsoftAjaxMintoBeCompressedContents = new StringBuilder();
            var localCssAssetFilesThatExist            = new List <FileInfo>();

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

            foreach (var fileToProcess in filesToProcess)
            {
                switch (fileToProcess.CompressionType)
                {
                case CssCompressionType.None:
                    uncompressedContents.AppendLine(fileToProcess.GetContents());
                    break;

                case CssCompressionType.YahooYui:
                    yahooYuiToBeCompressedContents.AppendLine(fileToProcess.GetContents());
                    break;

                case CssCompressionType.MicrosoftAjaxMin:
                    microsoftAjaxMintoBeCompressedContents.AppendLine(fileToProcess.GetContents());
                    break;
                }

                var cssAssets = fileToProcess.GetLocalCssAssetFilesThatExist();
                localCssAssetFilesThatExist.AddRange(cssAssets);
            }

            if (yahooYuiToBeCompressedContents.Length > 0)
            {
                {
                    uncompressedContents.Append(YahooYuiCssCompressor.Value.Compress(yahooYuiToBeCompressedContents.ToString()));
                }
            }

            if (microsoftAjaxMintoBeCompressedContents.Length > 0)
            {
                {
                    uncompressedContents.Append(MicrosoftAjaxMinCssCompressor.Value.MinifyStyleSheet(microsoftAjaxMintoBeCompressedContents.ToString()));
                }
            }

            var crushedOutput = new CssCrushedOutput
            {
                Output            = uncompressedContents,
                CssAssetFilePaths = localCssAssetFilesThatExist
            };

            return(crushedOutput);
        }
Beispiel #2
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);
        }
        private StringBuilder CreateLogEntries(CssGroupToProcess cssGroupToProcess, Uri outputUri, CssCrushedOutput crushedOutput, Stopwatch stopwatch)
        {
            outputUri = new Uri(cssGroupToProcess.PathProvider.ToAbsolute(outputUri.ToString()), UriKind.Absolute);
            var rootPath = cssGroupToProcess.PathProvider.GetAbsoluteUriDirectory("~/");

            var output = new StringBuilder();
            output.AppendFormat("{0} ({1} - {2} ms)\r\n", rootPath.MakeRelativeUri(outputUri), cssGroupToProcess.Group.Name, stopwatch.ElapsedMilliseconds);
            output.AppendFormat("{0}   (Css)\r\n", rootPath.MakeRelativeUri(outputUri));
            foreach (var cssFile in crushedOutput.FilesToWatch)
            {
                outputUri = new Uri(cssGroupToProcess.PathProvider.ToAbsolute(cssFile.FilePath), UriKind.Absolute);
                output.AppendFormat("      {0}\r\n", rootPath.MakeRelativeUri(outputUri));
            }
            output.AppendFormat("{0}   (Css Assets)\r\n", rootPath.MakeRelativeUri(outputUri));
            foreach (var cssAssetFile in crushedOutput.CssAssetFilePaths)
            {
                outputUri = new Uri(cssGroupToProcess.PathProvider.ToAbsolute(cssAssetFile.FullName), UriKind.Absolute);
                output.AppendFormat("      {0}\r\n", rootPath.MakeRelativeUri(outputUri));
            }
            return output;
        }
Beispiel #4
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="cssFiles">The css files to be crushed.</param>
        /// <param name="appendHashToAssets"></param>
        public virtual CssCrushedOutput ProcessFiles(FileInfo outputFileInfo, Uri cssRootUri, IEnumerable<CssFile> cssFiles, bool appendHashToAssets)
        {
            var uncompressedContents = new StringBuilder();
            var toBeStockYuiCompressedContents = new StringBuilder();
            var toBeMichaelAshRegexCompressedContents = new StringBuilder();
            var toBeHybridCompressedContents = new StringBuilder();
            var localCssAssetFilesThatExist = new List<FileInfo>();

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

            foreach (var fileToProcess in filesToProcess)
            {
                switch (fileToProcess.CompressionType)
                {
                    case CssCompressionType.None:
                        uncompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                    case CssCompressionType.StockYuiCompressor:
                        toBeStockYuiCompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                    case CssCompressionType.MichaelAshRegexEnhancements:
                        toBeMichaelAshRegexCompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                    case CssCompressionType.Hybrid:
                        toBeHybridCompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                }

                var cssAssets = fileToProcess.GetLocalCssAssetFilesThatExist();
                localCssAssetFilesThatExist.AddRange(cssAssets);
            }

            if (toBeStockYuiCompressedContents.Length > 0)
            {
                uncompressedContents.Append(CssCompressor.Compress(toBeStockYuiCompressedContents.ToString(), 0, Yahoo.Yui.Compressor.CssCompressionType.StockYuiCompressor));
            }

            if (toBeMichaelAshRegexCompressedContents.Length > 0)
            {
                uncompressedContents.Append(CssCompressor.Compress(toBeMichaelAshRegexCompressedContents.ToString(), 0, Yahoo.Yui.Compressor.CssCompressionType.MichaelAshRegexEnhancements));
            }

            if (toBeHybridCompressedContents.Length > 0)
            {
                uncompressedContents.Append(CssCompressor.Compress(toBeHybridCompressedContents.ToString(), 0, Yahoo.Yui.Compressor.CssCompressionType.Hybrid));
            }

            var crushedOutput = new CssCrushedOutput
                                    {
                                        Output = uncompressedContents,
                                        CssAssetFilePaths = localCssAssetFilesThatExist
                                    };

            return crushedOutput;
        }
Beispiel #5
0
        private StringBuilder CreateLogEntries(CssGroupToProcess cssGroupToProcess, Uri outputUri, CssCrushedOutput crushedOutput, Stopwatch stopwatch)
        {
            outputUri = new Uri(cssGroupToProcess.PathProvider.ToAbsolute(outputUri.ToString()), UriKind.Absolute);
            var rootPath = cssGroupToProcess.PathProvider.GetAbsoluteUriDirectory("~/");

            var output = new StringBuilder();

            output.AppendFormat("{0} ({1} - {2} ms)\r\n", rootPath.MakeRelativeUri(outputUri), cssGroupToProcess.Group.Name, stopwatch.ElapsedMilliseconds);
            output.AppendFormat("{0}   (Css)\r\n", rootPath.MakeRelativeUri(outputUri));
            foreach (var cssFile in crushedOutput.FilesToWatch)
            {
                outputUri = new Uri(cssGroupToProcess.PathProvider.ToAbsolute(cssFile.FilePath), UriKind.Absolute);
                output.AppendFormat("      {0}\r\n", rootPath.MakeRelativeUri(outputUri));
            }
            output.AppendFormat("{0}   (Css Assets)\r\n", rootPath.MakeRelativeUri(outputUri));
            foreach (var cssAssetFile in crushedOutput.CssAssetFilePaths)
            {
                outputUri = new Uri(cssGroupToProcess.PathProvider.ToAbsolute(cssAssetFile.FullName), UriKind.Absolute);
                output.AppendFormat("      {0}\r\n", rootPath.MakeRelativeUri(outputUri));
            }
            return(output);
        }
Beispiel #6
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="cssFiles">The css files to be crushed.</param>
        /// <param name="appendHashToAssets"></param>
        public virtual CssCrushedOutput ProcessFiles(FileInfo outputFileInfo, Uri cssRootUri, IEnumerable<CssFile> cssFiles, bool appendHashToAssets)
        {
            var uncompressedContents = new StringBuilder();
            var yahooYuiToBeCompressedContents = new StringBuilder();
            var microsoftAjaxMintoBeCompressedContents = new StringBuilder();
            var localCssAssetFilesThatExist = new List<FileInfo>();

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

            foreach (var fileToProcess in filesToProcess)
            {
                switch (fileToProcess.CompressionType)
                {
                    case CssCompressionType.None:
                        uncompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                    case CssCompressionType.YahooYui:
                        yahooYuiToBeCompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                    case CssCompressionType.MicrosoftAjaxMin:
                        microsoftAjaxMintoBeCompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                }

                var cssAssets = fileToProcess.GetLocalCssAssetFilesThatExist();
                localCssAssetFilesThatExist.AddRange(cssAssets);
            }

            if (yahooYuiToBeCompressedContents.Length > 0)
            {
                {
                    uncompressedContents.Append(YahooYuiCssCompressor.Value.Compress(yahooYuiToBeCompressedContents.ToString()));
                }
            }

            if (microsoftAjaxMintoBeCompressedContents.Length > 0)
            {
                {
                    uncompressedContents.Append(MicrosoftAjaxMinCssCompressor.Value.MinifyStyleSheet(microsoftAjaxMintoBeCompressedContents.ToString()));
                }
            }

            var crushedOutput = new CssCrushedOutput
            {
                Output = uncompressedContents,
                CssAssetFilePaths = localCssAssetFilesThatExist
            };

            return crushedOutput;
        }
Beispiel #7
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;
        }
Beispiel #8
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 uncompressedContents                   = new StringBuilder();
            var yahooYuiToBeCompressedContents         = new StringBuilder();
            var microsoftAjaxMintoBeCompressedContents = new StringBuilder();
            var localCssAssetFilesThatExist            = new List <FileInfo>();

            var filesToWatch = GetFilesToWatch(files, directories);

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

            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));

            foreach (var fileToProcess in filesToProcess)
            {
                switch (fileToProcess.CompressionType)
                {
                case CssCompressionType.None:
                    uncompressedContents.AppendLine(fileToProcess.GetContents());
                    break;

                case CssCompressionType.YahooYui:
                    yahooYuiToBeCompressedContents.AppendLine(fileToProcess.GetContents());
                    break;

                case CssCompressionType.MicrosoftAjaxMin:
                    microsoftAjaxMintoBeCompressedContents.AppendLine(fileToProcess.GetContents());
                    break;
                }

                var cssAssets = fileToProcess.GetLocalCssAssetFilesThatExist().Select(x => x.File);
                localCssAssetFilesThatExist.AddRange(cssAssets);
            }

            if (yahooYuiToBeCompressedContents.Length > 0)
            {
                var yahooYuiCssCompressor = YahooYuiCssCompressorPool.Acquire();
                try
                {
                    uncompressedContents.Append(yahooYuiCssCompressor.Compress(yahooYuiToBeCompressedContents.ToString()));
                }
                finally
                {
                    YahooYuiCssCompressorPool.Release(yahooYuiCssCompressor);
                }
            }

            if (microsoftAjaxMintoBeCompressedContents.Length > 0)
            {
                var microsoftAjaxMinCssCompressor = MicrosoftAjaxMinCssCompressorPool.Acquire();
                try
                {
                    uncompressedContents.Append(microsoftAjaxMinCssCompressor.MinifyStyleSheet(microsoftAjaxMintoBeCompressedContents.ToString()));
                }
                finally
                {
                    MicrosoftAjaxMinCssCompressorPool.Release(microsoftAjaxMinCssCompressor);
                }
            }

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

            return(crushedOutput);
        }