Ejemplo n.º 1
0
        private RequirePaths GetPaths(JObject document)
        {
            var paths = new RequirePaths();
            paths.PathList = new List<RequirePath>();
            if (document != null && document["paths"] != null)
            {
                paths.PathList = document["paths"].Select(
                r =>
                {
                    var result = new RequirePath();
                    var prop = (JProperty)r;
                    result.Key = prop.Name;
                    if (prop.Value.Type == JTokenType.String)
                    {
                        result.Value = prop.Value.ToString();
                    }
                    else
                    {
                        var pathObj = (JObject)prop.Value;
                        result.Value = pathObj["path"].ToString();
                        result.DefaultBundle = pathObj["defaultBundle"].ToString();
                    }

                    return result;
                }).ToList();    
            }
            
            return paths;
        }
Ejemplo n.º 2
0
        public XElement GetPaths(RequirePaths paths)
        {
            if (paths == null || !paths.PathList.Any())
            {
                return null;
            }

            var pathsEl = new XElement("paths", paths.PathList.Select(r => new XElement("path", new XAttribute("key", r.Key), new XAttribute("value", r.Value))));

            return pathsEl;
        }
Ejemplo n.º 3
0
 private RequirePaths GetPaths(XElement root)
 {
     var paths = new RequirePaths();
     paths.PathList = new List<RequirePath>();
     var pathEl = root.Descendants("paths").FirstOrDefault();
     if (pathEl != null)
     {
         paths.PathList = pathEl.Descendants("path").Select(r => new RequirePath
                                                                 {
                                                                     Key = r.Attribute("key").Value,
                                                                     Value = r.Attribute("value").Value
                                                                 }).ToList();
     }
     return paths;
 }
Ejemplo n.º 4
0
        private RequirePaths GetPaths(XElement root)
        {
            var paths = new RequirePaths();
            paths.PathList = new List<RequirePath>();
            var pathEl = root.Element("paths");
            if (pathEl != null)
            {
                paths.PathList = pathEl.Descendants("path")
                                        .Select(r => new RequirePath
                                                    {
                                                        Key = r.ReadStringAttribute("key"),
                                                        Value = r.ReadStringAttribute("value"),
                                                        DefaultBundle = r.ReadStringAttribute("bundle", AttributeReadType.Optional)
                                                    }).ToList();
            }

            return paths;
        }
Ejemplo n.º 5
0
        private void ApplyPathsOverride(RequirePaths originalPaths, RequirePaths overridePaths)
        {
            foreach (var pathEl in overridePaths.PathList)
            {
                var existing = originalPaths.PathList.Where(r => r.Key.ToLower() == pathEl.Key.ToLower()).FirstOrDefault();
                if (existing != null)
                {
                    existing.Value = pathEl.Value;
                }
                else
                {
                    originalPaths.PathList.Add(pathEl);
                }

                var existingValue = originalPaths.PathList.Where(r => r.Value.ToLower() == pathEl.Key.ToLower()).FirstOrDefault();
                if (existingValue != null)
                {
                    existingValue.Value = pathEl.Value;
                }
            }
        }
        private ConfigurationCollection ComposeCollection(List<Bundle> bundles)
        {
            var conf = new ConfigurationCollection();
            conf.Overrides = new List<CollectionOverride>();
            foreach (var bundle in bundles)
            {
                var scripts = bundle.Files.Select(r => PathHelpers.GetRequireRelativePath(EntryPoint, r.FileName)).ToList();
                var paths = new RequirePaths
                                {
                                    PathList = new List<RequirePath>()
                                };
                foreach (var script in scripts)
                {
                    paths.PathList.Add(new RequirePath
                                           {
                                               Key = script,
                                               Value = PathHelpers.GetRequireRelativePath(EntryPoint, bundle.Output)
                                           });
                }

                var over = new CollectionOverride
                               {
                                   BundleId = bundle.BundleId,
                                   BundledScripts = scripts,
                                   Paths = paths
                               };
                conf.Overrides.Add(over);
            }

            return conf;
        }
Ejemplo n.º 7
0
        private RequirePaths GetPaths(JObject document)
        {
            var paths = new RequirePaths();
            paths.PathList = new List<RequirePath>();
            if (document != null && document["paths"] != null)
            {
                paths.PathList = document["paths"].Select(
                r =>
                {
                    var result = new RequirePath();
                    var prop = (JProperty)r;
                    result.Key = prop.Name;
                    if (prop.Value.Type == JTokenType.String)
                    {
                        result.Value = prop.Value.ToString();
                    }
                    else
                    {
                        var pathObj = (JObject)prop.Value;
                        if (pathObj["path"] == null || pathObj["defaultBundle"] == null)
                            throw new ArgumentException("Expected an object with 'path' and 'defaultBundle' but got " + pathObj.ToString());
                        result.Value = pathObj["path"].ToString();
                        result.DefaultBundle = pathObj["defaultBundle"].ToString();
                    }

                    return result;
                }).ToList();
            }

            return paths;
        }