Example #1
0
        /// <summary>
        /// reads from a standard Web Essentials stlye bundle file
        /// </summary>
        /// <param name="bundleBaseDirPath">the base directory, in which to look for the files that the bundle will contain.</param>
        /// <param name="bundlePath">The path to the .custombundle file.</param>
        /// <returns></returns>
        internal static BundleInfo LoadFromXmlFile(string bundleBaseDirPath, string bundlePath)
        {
            BundleInfo bundle = new BundleInfo(PathParser.GetFileType(bundlePath));

            XmlDocument doc = new XmlDocument();

            doc.Load(bundlePath);

            XmlNode node        = doc.SelectSingleNode("/bundle");
            string  outFilename = GenerateOutFilename(bundlePath);

            foreach (XmlAttribute attr in node.Attributes)
            {
                if (attr.Name == "minify")
                {
                    bundle.isMinimising = attr.Value == "true";
                }
                if (attr.Name == "output")
                {
                    outFilename = attr.Value;
                }
            }

            bundle.outFilepath = Path.Combine(Path.GetDirectoryName(bundlePath), outFilename);

            XmlNodeList fileNodes = doc.SelectNodes("/bundle/file");

            foreach (XmlNode fileNode in fileNodes)
            {
                string relPath = fileNode.InnerText;
                if (relPath.StartsWith("/"))
                {
                    relPath = relPath.Substring(1);
                }
                relPath = relPath.Replace("/", "\\");

                //get the absolute path to the file:
                string absPath = Path.Combine(bundleBaseDirPath, relPath);
                bundle.filePaths.Add(absPath);

                //check that type of the file, matches the type of the bundle:
                FileType typeOfFile = PathParser.GetFileType(absPath);
                FileTypeValidator.ValidateBundleMatches(bundle.Type, typeOfFile);
            }

            return(bundle);
        }
Example #2
0
        private BundleInfo(FileType type)
        {
            this.type = type;

            this.containedType = FileTypeValidator.GetFileTypeForBundle(type);
        }