Inheritance: CoalesceAsset
コード例 #1
0
        public static XmlCoalesceAsset LoadFromMemory(string text)
        {
            var sourcePath = "virtualized";
            var doc        = XDocument.Parse(text);

            var root   = doc.Root;
            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 static XmlCoalesceAsset Load(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(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);
        }
コード例 #3
0
		public static XmlCoalesceAsset Load(string path)
		{
			if (path.IsNullOrEmpty())
			{
				throw new ArgumentNullException(nameof(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;
		}
コード例 #4
0
        public void ReadAssets(XElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(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 (string.IsNullOrEmpty(source))
                {
                    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 && !string.IsNullOrEmpty(asset.Source))
                {
                    Assets.Add(asset);
                }
            }
        }
コード例 #5
0
        public void ReadIncludes(XElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            var includesElement = element.Element("Includes");

            if (includesElement == null)
            {
                return;
            }

            var includes = from el in includesElement.Elements("Include") select el;

            foreach (var include in includes)
            {
                var source = (string)include.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.Source.IsNullOrEmpty())
                {
                    Assets.Add(asset);
                }
            }
        }