Esempio n. 1
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>
 /// Initializes a new instance of the <see cref="DextopCssResourcePackage"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 public DextopCssResourcePackage(DextopModule module)
 {
     package = new DextopResourcePackage(module);
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DextopJsResourcePackage"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="name">The name.</param>
 public DextopJsResourcePackage(DextopModule module, String name)
 {
     package     = new DextopResourcePackage(module);
     PackageName = name;
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DextopCssResourcePackage"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 public DextopCssResourcePackage(DextopModule module)
 {
     package = new DextopResourcePackage(module);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DextopJsResourcePackage"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="name">The name.</param>
 public DextopJsResourcePackage(DextopModule module, String name)
 {
     package = new DextopResourcePackage(module);
     PackageName = name;
 }
        /// <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);
        }
Esempio n. 7
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;
        }