Esempio n. 1
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);
        }
Esempio n. 2
0
        private StringBuilder CreateLogEntries(JsGroupToProcess jsGroupToProcess, Uri outputUri, JsCrushedOutput crushedOutput, Stopwatch stopwatch)
        {
            outputUri = new Uri(jsGroupToProcess.PathProvider.ToAbsolute(outputUri.ToString()), UriKind.Absolute);
            var rootPath = jsGroupToProcess.PathProvider.GetAbsoluteUriDirectory("~/");

            var output = new StringBuilder();
            output.AppendFormat("{0} ({1} - {2} ms)\r\n", rootPath.MakeRelativeUri(outputUri), jsGroupToProcess.Group.Name, stopwatch.ElapsedMilliseconds);
            foreach (var jsFile in crushedOutput.FilesToWatch)
            {
                outputUri = new Uri(jsGroupToProcess.PathProvider.ToAbsolute(jsFile.FilePath), UriKind.Absolute);
                output.AppendFormat("    {0}\r\n", rootPath.MakeRelativeUri(outputUri));
            }

            return output;
        }
Esempio n. 3
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>
        public virtual JsCrushedOutput ProcessFiles(FileInfo outputFileInfo, IEnumerable <JsFile> files)
        {
            var uncompressedContents                   = new StringBuilder();
            var yahooYuiToBeCompressedContents         = new StringBuilder();
            var microsoftAjaxMinToBeCompressedContents = new StringBuilder();
            var filesToProcess = files.Select(jsFile => new JsFileProcessor(RetryableFileOpener, PathProvider, jsFile));

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

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

                case JsCompressionType.MicrosoftAjaxMin:
                    microsoftAjaxMinToBeCompressedContents.AppendLine(fileToProcess.GetContents());
                    break;
                }
            }

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

            if (microsoftAjaxMinToBeCompressedContents.Length > 0)
            {
                uncompressedContents.Append(MicrosoftAjaxMinJavaScriptCompressor.Value.MinifyJavaScript(microsoftAjaxMinToBeCompressedContents.ToString()));
            }

            var crushedOutput = new JsCrushedOutput {
                Output = uncompressedContents
            };

            return(crushedOutput);
        }
Esempio n. 4
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>
        public virtual JsCrushedOutput ProcessFiles(FileInfo outputFileInfo, IEnumerable<JsFile> files)
        {
            var uncompressedContents = new StringBuilder();
            var toBeCompressedContents = new StringBuilder();
            var filesToProcess = files.Select(jsFile => new JsFileProcessor(RetryableFileOpener, PathProvider, jsFile));
            foreach (var fileToProcess in filesToProcess)
            {
                switch (fileToProcess.CompressionType)
                {
                    case JsCompressionType.None:
                        uncompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                    case JsCompressionType.Min:
                        toBeCompressedContents.AppendLine(fileToProcess.GetContents());
                        break;
                }
            }

            if (toBeCompressedContents.Length > 0)
            {
                uncompressedContents.Append(JavaScriptCompressor.Compress(toBeCompressedContents.ToString()));
            }

            var crushedOutput = new JsCrushedOutput {Output = uncompressedContents};

            return crushedOutput;
        }
        private StringBuilder CreateLogEntries(JsGroupToProcess jsGroupToProcess, Uri outputUri, JsCrushedOutput crushedOutput, Stopwatch stopwatch)
        {
            outputUri = new Uri(jsGroupToProcess.PathProvider.ToAbsolute(outputUri.ToString()), UriKind.Absolute);
            var rootPath = jsGroupToProcess.PathProvider.GetAbsoluteUriDirectory("~/");

            var output = new StringBuilder();

            output.AppendFormat("{0} ({1} - {2} ms)\r\n", rootPath.MakeRelativeUri(outputUri), jsGroupToProcess.Group.Name, stopwatch.ElapsedMilliseconds);
            foreach (var jsFile in crushedOutput.FilesToWatch)
            {
                outputUri = new Uri(jsGroupToProcess.PathProvider.ToAbsolute(jsFile.FilePath), UriKind.Absolute);
                output.AppendFormat("    {0}\r\n", rootPath.MakeRelativeUri(outputUri));
            }

            return(output);
        }
Esempio n. 6
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;
        }
Esempio n. 7
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 uncompressedContents                   = new StringBuilder();
            var yahooYuiToBeCompressedContents         = new StringBuilder();
            var microsoftAjaxMinToBeCompressedContents = new StringBuilder();

            var filesToWatch   = GetFilesToWatch(files, directories);
            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 filesToProcess = filesToWatch.Select(jsFile => new JsFileProcessor(RetryableFileOpener, PathProvider, jsFile.FilePath, jsFile.CompressionType));

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

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

                case JsCompressionType.MicrosoftAjaxMin:
                    microsoftAjaxMinToBeCompressedContents.AppendLine(fileToProcess.GetContents());
                    break;
                }
            }

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

            if (microsoftAjaxMinToBeCompressedContents.Length > 0)
            {
                var microsoftAjaxMinJavaScriptCompressor = MicrosoftAjaxMinJavaScriptCompressorPool.Acquire();
                try
                {
                    uncompressedContents.Append(microsoftAjaxMinJavaScriptCompressor.MinifyJavaScript(microsoftAjaxMinToBeCompressedContents.ToString()));
                }
                finally
                {
                    MicrosoftAjaxMinJavaScriptCompressorPool.Release(microsoftAjaxMinJavaScriptCompressor);
                }
            }

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

            return(crushedOutput);
        }