示例#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
        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();

        }