public static XmlCoalesceAsset Load(string path)
        {
            if (path.IsNullOrEmpty())
            {
                throw new ArgumentNullException("path");
            }

            var sourcePath = Path.GetFullPath(path);

            if (!File.Exists(sourcePath))
            {
                Console.WriteLine(@"Warning: {0} not found!", path);
                return(null);
            }

            var doc = XDocument.Load(path);

            var root = doc.Root;

            if (root == null)
            {
                return(null);
            }

            var id     = (string)root.Attribute("id");
            var name   = (string)root.Attribute("name");
            var source = (string)root.Attribute("source");

            var result = new XmlCoalesceAsset(name)
            {
                BaseUri         = (doc.BaseUri != "") ? doc.BaseUri : new Uri(sourcePath).AbsoluteUri,
                Id              = id,
                Source          = source,
                SourcePath      = sourcePath,
                SourceDirectory = Path.GetDirectoryName(sourcePath)
            };

            // Read includes before the sections
            result.ReadIncludes(root);
            result.ReadSections(root);

            return(result);
        }
예제 #2
0
        public void ReadAssets(XElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            var assetsElement = element.Element("Assets");

            if (assetsElement == null)
            {
                return;
            }

            var assets   = from el in assetsElement.Elements("Asset") select el;
            var includes = new List <CoalesceInclude>();

            foreach (var asset in assets)
            {
                var source = (string)asset.Attribute("source");

                if (source.IsNullOrEmpty())
                {
                    continue;
                }

                var sourcePath = Path.Combine(SourceDirectory, source);
                sourcePath = Path.GetFullPath(sourcePath);

                includes.Add(new CoalesceInclude(sourcePath));
            }

            foreach (var include in includes)
            {
                var asset = XmlCoalesceAsset.Load(include.Source);

                if (asset != null && !asset.Source.IsNullOrEmpty())
                {
                    Assets.Add(asset);
                }
            }
        }