Exemplo n.º 1
0
        void OptimizeFileList(DextopResourceOptimizationContext context, List <string> files)
        {
            if (External)
            {
                return;
            }

            for (var i = 0; i < files.Count; i++)
            {
                var      filePath = package.Module.MapPath(files[i]);
                DateTime lastWrite;
                var      cb = DextopFileUtil.CalculateCacheBuster(new[] { filePath }, out lastWrite);
                if (Minify)
                {
                    files[i] = files[i].Substring(0, files[i].Length - 4) + "-min.css";
                    var outputPath = new FileInfo(filePath.Substring(0, filePath.Length - 4) + "-min.css");
                    if (!context.FakeOptimization && (!SmartOverwrite || !outputPath.Exists || outputPath.LastAccessTime <= lastWrite))
                    {
                        var css = File.ReadAllText(filePath);
                        css = DextopFileUtil.MinifyCss(css);
                        File.WriteAllText(outputPath.FullName, css);
                    }
                }
                files[i] = files[i] + "?cb=" + cb;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Optimizes the JS files inside the package.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Optimize(DextopResourceOptimizationContext context)
        {
            if (!Concate)
            {
                AppendCacheBusters(package.Files);
                if (package.Localizations != null)
                {
                    foreach (var pl in package.Localizations)
                    {
                        AppendCacheBusters(pl.Value);
                    }
                }
                return;
            }

            var pkg = new DextopResourcePackage(context.OptimizationOutputModule);

            var      fileName  = package.Module.ModuleName + "-" + PackageName + ".js";
            var      filePaths = package.Files.Select(a => package.Module.MapPath(a)).ToArray();
            DateTime lastWrite;
            int      cacheBuster = DextopFileUtil.CalculateCacheBuster(filePaths, out lastWrite);
            var      outputFile  = new FileInfo(context.OptimizationOutputModule.MapPath(fileName));

            if (!SmartOverwrite || !outputFile.Exists || outputFile.LastWriteTime <= lastWrite)
            {
                var js = DextopFileUtil.ConcateFiles(filePaths);
                if (Minify)
                {
                    js = DextopFileUtil.MinifyJs(js, Obfuscate);
                }
                DextopFileUtil.WriteTextFile(outputFile.FullName, js);
            }

            pkg.AddFiles(new[] { fileName + "?cb=" + cacheBuster });

            if (package.Localizations != null)
            {
                foreach (var loc in package.Localizations)
                {
                    fileName    = package.Module.ModuleName + "-" + PackageName + String.Format(".locale-{0}.js", loc.Key);
                    filePaths   = loc.Value.Select(a => package.Module.MapPath(a)).ToArray();
                    cacheBuster = DextopFileUtil.CalculateCacheBuster(filePaths, out lastWrite);
                    outputFile  = new FileInfo(context.OptimizationOutputModule.MapPath(fileName));
                    if (!SmartOverwrite || !outputFile.Exists || outputFile.LastWriteTime <= lastWrite)
                    {
                        var js = DextopFileUtil.ConcateFiles(filePaths);
                        js = DextopFileUtil.ConcateFiles(filePaths);
                        if (Minify)
                        {
                            js = DextopFileUtil.MinifyJs(js, Obfuscate);
                        }
                        DextopFileUtil.WriteTextFile(outputFile.FullName, js);
                    }
                    pkg.AddLocalization(loc.Key, new[] { fileName + "?cb=" + cacheBuster });
                }
            }

            package = pkg;
        }
        /// <summary>
        /// Optimizes the content of the package.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Optimize(DextopResourceOptimizationContext context)
        {
            OptimizeFileList(package.Files);

            if (package.Localizations != null)
                foreach (var loc in package.Localizations)
                    OptimizeFileList(loc.Value);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Optimizes the content of the package.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Optimize(DextopResourceOptimizationContext context)
        {
            OptimizeFileList(context, package.Files);

            if (package.Localizations != null)
            {
                foreach (var loc in package.Localizations)
                {
                    OptimizeFileList(context, loc.Value);
                }
            }
        }
        /// <summary>
        /// Optimizes the modules.
        /// </summary>
        /// <param name="outputVirtualPath">The output virtual path.</param>
        protected void OptimizeModules(String outputVirtualPath)
        {
            var outputModule = new DextopResourceOptimizationModule()
            {
                PhysicalPath = DextopUtil.MapPath(outputVirtualPath),
                VirtualPath = outputVirtualPath
            };

            var context = new DextopResourceOptimizationContext
            {
                OptimizationOutputModule = outputModule
            };

            foreach (var m in Modules)
                m.OptimizeResources(context);
        }
        /// <summary>
        /// Optimizes the modules.
        /// </summary>
        /// <param name="outputVirtualPath">The output virtual path.</param>
        protected void OptimizeModules(String outputVirtualPath)
        {
            var outputModule = new DextopResourceOptimizationModule()
            {
                PhysicalPath = DextopUtil.MapPath(outputVirtualPath),
                VirtualPath  = outputVirtualPath
            };

            var context = new DextopResourceOptimizationContext
            {
                OptimizationOutputModule = outputModule
            };

            foreach (var m in Modules)
            {
                m.OptimizeResources(context);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Optimizes the module resources by using concatenation, minifying and compressing techniques.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void OptimizeResources(DextopResourceOptimizationContext context)
        {
            if (JsPackages != null)
            {
                foreach (var pkg in JsPackages)
                {
                    pkg.Optimize(context);
                }
            }

            if (CssPackages != null)
            {
                foreach (var pkg in CssPackages)
                {
                    pkg.Optimize(context);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Optimizes the module resources by using concatenation, minifying and compressing techniques.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void OptimizeResources(DextopResourceOptimizationContext context)
        {
            if (JsPackages != null)
                foreach (var pkg in JsPackages)
                    pkg.Optimize(context);

            if (CssPackages != null)
                foreach (var pkg in CssPackages)
                    pkg.Optimize(context);
        }
Exemplo n.º 9
0
        void OptimizeFileList(DextopResourceOptimizationContext context, List<string> files)
        {
            if (External)
                return;

            for (var i = 0; i < files.Count; i++)
            {
				var filePath = package.Module.MapPath(files[i]);			
				DateTime lastWrite;
                var cb = DextopFileUtil.CalculateCacheBuster(new[] { filePath }, out lastWrite);
                if (Minify)
                {
                    files[i] = files[i].Substring(0, files[i].Length - 4) + "-min.css";
					var outputPath = new FileInfo(filePath.Substring(0, filePath.Length - 4) + "-min.css");                    
                    if (!context.FakeOptimization && (!SmartOverwrite || !outputPath.Exists || outputPath.LastAccessTime <= lastWrite))
                    {
                        var css = File.ReadAllText(filePath);
                        css = DextopFileUtil.MinifyCss(css);
                        File.WriteAllText(outputPath.FullName, css);
                    }
                }
                files[i] = files[i] + "?cb=" + cb;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Optimizes the JS files inside the package.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Optimize(DextopResourceOptimizationContext context)
        {
            if (External)
                return;

            if (Concate)
            {
                var pkg = new DextopResourcePackage(context.OptimizationOutputModule);

                var fileName = package.Module.ModuleName + "-" + PackageName + ".js";

                if (!context.FakeOptimization)
                {
                    var filePaths = package.Files.Select(a => package.Module.MapPath(a)).ToArray();
                    DateTime lastWrite;
                    int cacheBuster = DextopFileUtil.CalculateCacheBuster(filePaths, out lastWrite);
                    var outputFile = new FileInfo(context.OptimizationOutputModule.MapPath(fileName));
                    if (!SmartOverwrite || !outputFile.Exists || outputFile.LastWriteTime <= lastWrite)
                    {
                        var js = DextopFileUtil.ConcateFiles(filePaths);
                        if (Minify)
                            js = DextopFileUtil.MinifyJs(js, Obfuscate);
                        DextopFileUtil.WriteTextFile(outputFile.FullName, js);
                    }
                }

                pkg.AddFiles(new[] { fileName });

                if (package.Localizations != null)
                    foreach (var loc in package.Localizations)
                    {
                        fileName = package.Module.ModuleName + "-" + PackageName + String.Format(".locale-{0}.js", loc.Key);

                        if (!context.FakeOptimization)
                        {
                            var filePaths = loc.Value.Select(a => package.Module.MapPath(a)).ToArray();
                            DateTime lastWrite;
                            var cacheBuster = DextopFileUtil.CalculateCacheBuster(filePaths, out lastWrite);
                            var outputFile = new FileInfo(context.OptimizationOutputModule.MapPath(fileName));
                            if (!SmartOverwrite || !outputFile.Exists || outputFile.LastWriteTime <= lastWrite)
                            {
                                var js = DextopFileUtil.ConcateFiles(filePaths);
                                js = DextopFileUtil.ConcateFiles(filePaths);
                                if (Minify)
                                    js = DextopFileUtil.MinifyJs(js, Obfuscate);
                                DextopFileUtil.WriteTextFile(outputFile.FullName, js);
                            }
                            fileName += "?cb=" + cacheBuster;
                        }
                        pkg.AddLocalization(loc.Key, new[] { fileName });
                    }

                package = pkg;
            }

            AppendCacheBusters(package.Files);
            if (package.Localizations != null)
                foreach (var pl in package.Localizations)
                    AppendCacheBusters(pl.Value);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Optimizes the JS files inside the package.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Optimize(DextopResourceOptimizationContext context)
        {
            if (!Concate)
            {
                AppendCacheBusters(package.Files);
                if (package.Localizations != null)
                    foreach (var pl in package.Localizations)
                        AppendCacheBusters(pl.Value);
                return;
            }

            var pkg = new DextopResourcePackage(context.OptimizationOutputModule);

            var fileName = package.Module.ModuleName + "-" + PackageName + ".js";
            var filePaths = package.Files.Select(a => package.Module.MapPath(a)).ToArray();
            int cacheBuster = DextopFileUtil.CalculateCacheBuster(filePaths);
            var js = DextopFileUtil.ConcateFiles(filePaths);
            if (Minify)
                js = DextopFileUtil.MinifyJs(js, Obfuscate);

            DextopFileUtil.WriteTextFile(context.OptimizationOutputModule.MapPath(fileName), js);
            pkg.AddFiles(new[] { fileName + "?cb=" + cacheBuster });

            if (package.Localizations!=null)
                foreach (var loc in package.Localizations)
                {
                    fileName = package.Module.ModuleName + "-" + PackageName + String.Format(".locale-{0}.js", loc.Key);
                    filePaths = loc.Value.Select(a => package.Module.MapPath(a)).ToArray();
                    cacheBuster = DextopFileUtil.CalculateCacheBuster(filePaths);
                    js = DextopFileUtil.ConcateFiles(filePaths);
                    if (Minify)
                        js = DextopFileUtil.MinifyJs(js, Obfuscate);
                    DextopFileUtil.WriteTextFile(context.OptimizationOutputModule.MapPath(fileName), js);
                    pkg.AddLocalization(loc.Key, new[] { fileName + "?cb=" + cacheBuster });
                }

            package = pkg;
        }