コード例 #1
0
ファイル: Template.cs プロジェクト: ppittle/LBi.LostDoc
        private Resource ParseResouceDefinition(Stack<IFileProvider> providers, XElement elem)
        {
            var source = this.GetAttributeValue(elem, "path");

            IFileProvider resourceProvider;
            Uri sourceUri;
            if (Uri.TryCreate(source, UriKind.Absolute, out sourceUri) && sourceUri.Scheme.StartsWith("http"))
            {
                resourceProvider = new HttpFileProvider();
            }
            else
            {
                resourceProvider = providers.FirstOrDefault(p => p.FileExists(source));
                if (resourceProvider == null)
                    throw new FileNotFoundException("Resource not found: " + source);
            }
        
            XAttribute outputAttr = elem.Attribute("output");

            string output;
            if (outputAttr != null)
                output = outputAttr.Value;
            else
                output = '\'' + Path.GetFileName(source) + '\'';

            List<ResourceTransform> transforms = new List<ResourceTransform>();
            foreach (XElement transform in elem.Elements("transform"))
            {
                string transformName = this.GetAttributeValue(transform, "name");

                var transformParams = transform.Elements("with-param")
                                               .Select(p => new ExpressionXPathVariable(this.GetAttributeValue(p, "name"),
                                                                                        this.GetAttributeValue(p, "select")));

                transforms.Add(new ResourceTransform(transformName, transformParams));
            }

            var resource = new Resource(this.GetAttributeValueOrDefault(elem, "condition"),
                                        this.ParseVariables(elem).ToArray(),
                                        resourceProvider,
                                        source,
                                        output,
                                        transforms.ToArray());
            return resource;
        }