Ejemplo n.º 1
0
        public static void ProcessBundle(string baseFolder, Bundle bundle)
        {
            StringBuilder sb         = new StringBuilder();
            List <string> inputFiles = bundle.GetAbsoluteInputFiles();

            foreach (string input in inputFiles)
            {
                string file = Path.Combine(baseFolder, input);

                if (File.Exists(file))
                {
                    string content;

                    if (input.EndsWith(".css", StringComparison.OrdinalIgnoreCase) && AdjustRelativePaths(bundle))
                    {
                        content = CssRelativePath.Adjust(file, bundle.GetAbsoluteOutputFile());
                    }
                    else
                    {
                        content = BundleMinifier.ReadAllText(file);
                    }

                    sb.AppendLine(content);
                }
            }

            bundle.Output = sb.ToString().Trim();
        }
Ejemplo n.º 2
0
        public static void ProcessBundle(string baseFolder, Bundle bundle)
        {
            DateTime      mostRecentWrite = default(DateTime);
            StringBuilder sb         = new StringBuilder();
            List <string> inputFiles = bundle.GetAbsoluteInputFiles();

            for (int i = 0; i < inputFiles.Count; i++)
            {
                var input = inputFiles[i];

                string file = Path.Combine(baseFolder, input);

                if (File.Exists(file))
                {
                    string content;

                    if (input.EndsWith(".css", StringComparison.OrdinalIgnoreCase) && AdjustRelativePaths(bundle))
                    {
                        content = CssRelativePath.Adjust(file, bundle.GetAbsoluteOutputFile());
                    }
                    else
                    {
                        content = FileHelpers.ReadAllText(file);
                    }
                    var lastWriteFile = System.IO.File.GetLastWriteTimeUtc(file);
                    if (mostRecentWrite < lastWriteFile)
                    {
                        mostRecentWrite = lastWriteFile;
                    }

                    // adding new line only if there are more than 1 files
                    // otherwise we are preserving file integrity
                    if (sb.Length > 0)
                    {
                        sb.AppendLine();
                    }

                    sb.Append(content);
                }
            }

            bundle.MostRecentWrite = mostRecentWrite;
            bundle.Output          = sb.ToString();
        }
Ejemplo n.º 3
0
        public static void ProcessBundle(string baseFolder, Bundle bundle)
        {
            StringBuilder sb         = new StringBuilder();
            List <string> inputFiles = bundle.GetAbsoluteInputFiles();

            //string ext = Path.GetExtension(bundle.OutputFileName);

            // Support both directories and specific files
            //foreach (string input in bundle.InputFiles)
            //{
            //    string fullPath = Path.Combine(baseFolder, input);

            //    if (Directory.Exists(fullPath))
            //    {
            //        DirectoryInfo dir = new DirectoryInfo(fullPath);
            //        SearchOption search = bundle.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
            //        var files = dir.GetFiles("*" + ext, search);
            //        inputFiles.AddRange(files.Select(f => f.FullName));
            //    }
            //}

            foreach (string input in inputFiles)
            {
                string file = Path.Combine(baseFolder, input);
                string content;

                if (input.EndsWith(".css", System.StringComparison.OrdinalIgnoreCase) && AdjustRelativePaths(bundle))
                {
                    content = CssRelativePath.Adjust(file, bundle.GetAbsoluteOutputFile());
                }
                else
                {
                    content = BundleMinifier.ReadAllText(file);
                }

                sb.AppendLine(content);
            }

            bundle.Output = sb.ToString().Trim();
        }