コード例 #1
0
        private IEnumerable<UnitOfWork> DiscoverWork(TemplateData templateData, XPathVariable[] parameters, Resource[] resources)
        {
            CustomXsltContext xpathContext = CreateCustomXsltContext(templateData.IgnoredVersionComponent);
            xpathContext.PushVariableScope(templateData.Document.Root, parameters);
            for (int i = 0; i < resources.Length; i++)
            {
                xpathContext.PushVariableScope(templateData.Document.Root, resources[i].Variables);

                if (EvalCondition(xpathContext, templateData.Document.Root, resources[i].ConditionExpression))
                {
                    string expandedSource = EvalValue(xpathContext, templateData.Document.Root, resources[i].Source);
                    string expandedOutput = EvalValue(xpathContext, templateData.Document.Root, resources[i].Output);

                    List<IResourceTransform> transforms = new List<IResourceTransform>();

                    foreach (var resourceTransform in resources[i].Transforms)
                    {
                        using (CompositionContainer localContainer = new CompositionContainer(this._container.Catalog))
                        {
                            string dirName = Path.GetDirectoryName(expandedSource);
                            CompositionBatch batch = new CompositionBatch();
                            var exportMetadata = new Dictionary<string, object>();

                            exportMetadata.Add(CompositionConstants.ExportTypeIdentityMetadataName,
                                               AttributedModelServices.GetTypeIdentity(typeof(IFileProvider)));

                            exportMetadata.Add(CompositionConstants.PartCreationPolicyMetadataName,
                                               CreationPolicy.Shared);

                            batch.AddExport(new Export(ContractNames.ResourceFileProvider,
                                                       exportMetadata,
                                                       () => new ScopedFileProvider(resources[i].FileProvider, dirName)));

                            // TODO export resourceTransform.Parameters into localContainer using CompositionBatch

                            localContainer.Compose(batch);

                            var requiredMetadata = new[]
                                                   {
                                                       new Tuple<string, object, IEqualityComparer>("Name",
                                                                                                    resourceTransform.Name,
                                                                                                    StringComparer.OrdinalIgnoreCase)
                                                   };

                            ImportDefinition importDefinition =
                                new MetadataContractBasedImportDefinition(
                                    typeof(IResourceTransform),
                                    null,
                                    requiredMetadata,
                                    ImportCardinality.ExactlyOne,
                                    false,
                                    true,
                                    CreationPolicy.NonShared);

                            Export transformExport = localContainer.GetExports(importDefinition).Single();

                            transforms.Add((IResourceTransform)transformExport.Value);
                        }
                    }

                    yield return
                        new ResourceDeployment(resources[i].FileProvider,
                                               expandedSource,
                                               expandedOutput, // TODO this needs a 'writable' file provider
                                               transforms.ToArray());
                }
                xpathContext.PopVariableScope();
            }
            xpathContext.PopVariableScope();

        }
コード例 #2
0
ファイル: Template.cs プロジェクト: ppittle/LBi.LostDoc
        private IEnumerable<UnitOfWork> DiscoverWork(TemplateData templateData, XPathVariable[] parameters, Resource[] resources)
        {
            CustomXsltContext xpathContext = CreateCustomXsltContext(templateData.IgnoredVersionComponent);
            xpathContext.PushVariableScope(templateData.Document.Root, parameters);
            for (int i = 0; i < resources.Length; i++)
            {
                xpathContext.PushVariableScope(templateData.Document.Root, resources[i].Variables);

                if (EvalCondition(xpathContext, templateData.Document.Root, resources[i].ConditionExpression))
                {
                    List<IResourceTransform> transforms = new List<IResourceTransform>();

                    foreach (var resourceTransform in resources[i].Transforms)
                    {
                        CompositionContainer paramContainer = new CompositionContainer(this._container);

                        // TODO export resourceTransform.Parameters into paramContainer
                        ImportDefinition importDefinition =
                            new MetadataContractBasedImportDefinition(
                                typeof(IResourceTransform),
                                null,
                                new[] {new Tuple<string, object, IEqualityComparer>("Name", resourceTransform.Name, StringComparer.OrdinalIgnoreCase) },
                                ImportCardinality.ExactlyOne,
                                false,
                                false,
                                CreationPolicy.NonShared);

                        Export transformExport = paramContainer.GetExports(importDefinition).Single();

                        transforms.Add((IResourceTransform)transformExport.Value);
                    }

                    yield return
                        new ResourceDeployment(resources[i].FileProvider,
                                               resources[i].Source,
                                               resources[i].Output, // TODO this needs a 'writable' file provider
                                               transforms.ToArray());
                }
                xpathContext.PopVariableScope();
            }
            xpathContext.PopVariableScope();

        }
コード例 #3
0
        private Resource ParseResouceDefinition(IFileProvider provider, XElement elem)
        {
            string source = this.GetAttributeValue(elem, "path");

            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(),
                                        provider,
                                        source,
                                        output,
                                        transforms.ToArray());
            return resource;
        }
コード例 #4
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;
        }