public virtual void Load(TemplateResolver resolver, string name) { this._templateSourcePath = null; string path; if (resolver.Resolve(name, out this._fileProvider, out path)) { using (Stream str = this._fileProvider.OpenFile(path, FileMode.Open)) _templateDefinition = XDocument.Load(str, LoadOptions.SetLineInfo); this._basePath = Path.GetDirectoryName(path); this._templateResolver = resolver; } else { throw new FileNotFoundException("Template not found, search paths: {0}", resolver.ToString()); } }
public override void Invoke(CompositionContainer container) { var traceListener = new ConsolidatedConsoleTraceListener { { TraceSources.TemplateSource, "Template" }, { TraceSources.BundleSource, "Bundle" }, { TraceSources.AssetResolverSource, "Resolve" } }; using (traceListener) { this.ConfigureTraceLevels(traceListener); LinkedList<FileInfo> includedFiles = new LinkedList<FileInfo>(); if (File.Exists(this.Path)) includedFiles.AddLast(new FileInfo(this.Path)); else if (Directory.Exists(this.Path)) { Directory.GetFiles(this.Path, "*.ldoc", SearchOption.AllDirectories) .Aggregate(includedFiles, (l, f) => l.AddLast(new FileInfo(f)).List); } else throw new FileNotFoundException(System.IO.Path.GetFullPath(this.Path)); Bundle bundle = new Bundle(this.IgnoreVersionComponent); TraceSources.TemplateSource.TraceInformation("Merging LostDoc files into bundle."); foreach (FileInfo file in includedFiles) { TraceSources.TemplateSource.TraceEvent(TraceEventType.Information, 0, "Source: {0}", file.Name); XDocument fileDoc = XDocument.Load(file.FullName); bundle.Add(fileDoc); } var lazyProviders = container.GetExports<IFileProvider>(ContractNames.TemplateProvider); var realProviders = lazyProviders.Select(lazy => lazy.Value); TemplateResolver templateResolver = new TemplateResolver(realProviders.ToArray()); TemplateInfo templateInfo = templateResolver.Resolve(this.Template); Template template = templateInfo.Load(container); string outputDir = this.Output ?? (Directory.Exists(this.Path) ? this.Path : System.IO.Path.GetDirectoryName(this.Path)); AssetRedirectCollection assetRedirects; XDocument mergedDoc = bundle.Merge(out assetRedirects); var templateData = new TemplateData(mergedDoc) { AssetRedirects = assetRedirects, OverwriteExistingFiles = this.Force.IsPresent, IgnoredVersionComponent = this.IgnoreVersionComponent, Arguments = this.Arguments, OutputFileProvider = new ScopedFileProvider(new DirectoryFileProvider(), outputDir) }; template.Generate(templateData); } }