예제 #1
0
        /// <summary>
        /// Builds the javascript package file specified in <paramref name="configPath"/>.
        /// </summary>
        /// <remarks>
        /// If package file already exists it will be rebuilt according with files access time.
        /// </remarks>
        /// <param name="environment">The environment.</param>
        /// <param name="packageName">Name of the package.</param>
        /// <param name="javascriptPath">The javascript directory server path.</param>
        /// <param name="configPath">Assets config path.</param>
        /// <returns>Generated package file name.</returns>
        public static String BuildJavascriptPack(Environment environment, String packageName, String javascriptPath, String configPath)
        {
            var packageFileName = String.Format(JavascriptPackageNameTemplate, packageName);
            var packagePath = Path.Combine(javascriptPath, packageFileName);
            var files = GetJavascriptPackFiles(environment, packageName, configPath);

            if (!File.Exists(packagePath) || File.GetLastWriteTimeUtc(packagePath) < GetMaxLastModifyDate(javascriptPath, files))
            {
                var output = new StringBuilder();
                foreach (var file in files)
                {
                    using (var reader = new StreamReader(Path.Combine(javascriptPath, file)))
                    {
                        var temp = reader.ReadToEnd();
                        if (!String.IsNullOrEmpty(temp))
                        {
                            output.Append(JavaScriptCompressor.Compress(temp));
                        }
                    }
                }

                using (var writer = new StreamWriter(File.Create(packagePath)))
                {
                    writer.Write(output.ToString());
                }
            }

            return packageFileName;
        }
예제 #2
0
 /// <summary>
 /// Reads assets config from <paramref name="configPath"/>.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="configPath">The configuration path.</param>
 /// <returns>Assets configuration.</returns>
 /// <remarks>
 /// If <paramref name="environment"/> equals to <see cref="Environment.Development"/> configuration will be read on each call;
 /// otherwise configuration will be read only on first call.
 /// </remarks>
 public static dynamic GetAssetsConfig(Environment environment, String configPath)
 {
     if (Environment.Development.Equals(environment) || assetsConfig == null)
     {
         assetsConfig = YamlDocument.FromFile(configPath);
     }
     return assetsConfig;
 }
예제 #3
0
 /// <summary>
 /// Gets list of files included in javascript package specified in <paramref name="configPath"/>.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="packageName">Name of the package.</param>
 /// <param name="configPath">The configuration path.</param>
 /// <returns>
 /// List of files relative to javascript directory.
 /// </returns>
 public static IEnumerable<String> GetJavascriptPackFiles(Environment environment, String packageName, String configPath)
 {
     dynamic config = GetAssetsConfig(environment, configPath);
     var files = new List<String>();
     foreach (var file in config.javascripts[packageName])
     {
         files.Add(file);
     }
     return files;
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlResourceCache"/> class.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="resourcesPath">The resources path.</param>
        public YamlResourceCache(Environment environment, String resourcesPath)
        {
            this.resourcesPath = resourcesPath;

            ReadResources();

            if (Environment.Development.Equals(environment))
            {
                fileMonitor = new FileSystemWatcher(resourcesPath, YamlFilesPattern);
                fileMonitor.IncludeSubdirectories = true;
                fileMonitor.Changed            += ResourcesChangedHandler;
                fileMonitor.EnableRaisingEvents = true;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlResourceCache"/> class.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="resourcesPath">The resources path.</param>
        public YamlResourceCache(Environment environment, String resourcesPath)
        {
            this.resourcesPath = resourcesPath;

            ReadResources();

            if (Environment.Development.Equals(environment))
            {
                fileMonitor = new FileSystemWatcher(resourcesPath, YamlFilesPattern);
                fileMonitor.IncludeSubdirectories = true;
                fileMonitor.Changed += ResourcesChangedHandler;
                fileMonitor.EnableRaisingEvents = true;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="YamlResourceCacheHolder"/> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="defaultResourcesPath">The default resources path.</param>
 public YamlResourceCacheHolder(Environment environment, String defaultResourcesPath)
 {
     caches = new Dictionary<String, YamlResourceCache>();
     caches.Add(String.Empty, new YamlResourceCache(environment, defaultResourcesPath));
     foreach (var plugin in Application.Plugins)
     {
         if (!String.IsNullOrEmpty(plugin.ResourcesDirectory))
         {
             var chains = (IEnumerable<String>)plugin.PluginLocation.ToLower().Split(PathSeparator.ToCharArray());
             chains = chains.Reverse();
             chains = chains.Skip(1);
             String pluginDirectory = chains.First();
             chains = chains.Reverse();
             chains = chains.Concat(new[] { plugin.ResourcesDirectory });
             caches.Add(pluginDirectory, new YamlResourceCache(environment, String.Join(PathSeparator, chains)));
         }
     }
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="YamlResourceCacheHolder"/> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="defaultResourcesPath">The default resources path.</param>
 public YamlResourceCacheHolder(Environment environment, String defaultResourcesPath)
 {
     caches = new Dictionary <String, YamlResourceCache>();
     caches.Add(String.Empty, new YamlResourceCache(environment, defaultResourcesPath));
     foreach (var plugin in Application.Plugins)
     {
         if (!String.IsNullOrEmpty(plugin.ResourcesDirectory))
         {
             var chains = (IEnumerable <String>)plugin.PluginLocation.ToLower().Split(PathSeparator.ToCharArray());
             chains = chains.Reverse();
             chains = chains.Skip(1);
             String pluginDirectory = chains.First();
             chains = chains.Reverse();
             chains = chains.Concat(new[] { plugin.ResourcesDirectory });
             caches.Add(pluginDirectory, new YamlResourceCache(environment, String.Join(PathSeparator, chains)));
         }
     }
 }
예제 #8
0
 /// <summary>
 /// Gets list of files included in css package specified in <see name="DefaultConfigPath"/>.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="packageName">Name of the package.</param>
 /// <returns>List of files relative to css directory.</returns>
 public static IEnumerable<String> GetCssPackFiles(Environment environment, String packageName)
 {
     return GetCssPackFiles(environment, packageName, DefaultConfigPath);
 }
예제 #9
0
 /// <summary>
 /// Reads assets config from <see name="DefaultConfigPath"/>.
 /// </summary>
 /// <remarks>
 /// If <paramref name="environment"/> equals to <see cref="Environment.Development"/> configuration will be read on each call;
 /// otherwise configuration will be read only on first call.
 /// </remarks>
 /// <param name="environment">The environment.</param>
 /// <returns>Assets configuration.</returns>
 public static dynamic GetAssetsConfig(Environment environment)
 {
     return GetAssetsConfig(environment, DefaultConfigPath);
 }
예제 #10
0
 /// <summary>
 /// Builds the javascript package file specified in <see name="DefaultConfigPath"/>.
 /// </summary>
 /// <remarks>
 /// If package file already exists it will be rebuilt according with files access time.
 /// </remarks>
 /// <param name="environment">The environment.</param>
 /// <param name="packageName">Name of the package.</param>
 /// <param name="javascriptPath">The javascript directory server path.</param>
 /// <returns>Generated package file name.</returns>
 public static String BuildJavascriptPack(Environment environment, String packageName, String javascriptPath)
 {
     return BuildJavascriptPack(environment, packageName, javascriptPath, DefaultConfigPath);
 }
예제 #11
0
 /// <summary>
 /// Builds the css package file specified in <see name="DefaultConfigPath"/>.
 /// </summary>
 /// <remarks>
 /// If package file already exists it will be rebuilt according with files access time.
 /// </remarks>
 /// <param name="environment">The environment.</param>
 /// <param name="packageName">Name of the package.</param>
 /// <param name="cssPath">The css directory server path.</param>
 /// <returns>Generated package file name.</returns>
 public static String BuildCssPack(Environment environment, String packageName, String cssPath)
 {
     return BuildCssPack(environment, packageName, cssPath, DefaultConfigPath);
 }