public TemplateOutput(WorkUnitResult[] result, TempFileCollection tempFiles) { this.Results = result; this.TemporaryFiles = tempFiles; }
private XElement ConvertToXml(WorkUnitResult wu) { return new XElement("result", new XAttribute("duration", XmlConvert.ToString(Math.Round(wu.Duration / 1000.0, 2))), wu.WorkUnit is ResourceDeployment ? ResourceToXml(wu) : StylesheetToXml(wu)); }
private static XElement StylesheetToXml(WorkUnitResult wu) { StylesheetApplication ssWu = (StylesheetApplication)wu.WorkUnit; return new XElement("document", new XAttribute("assetId", ssWu.Asset), new XAttribute("output", ssWu.SaveAs), ssWu.Aliases.Select( wual => new XElement("alias", new XAttribute("assetId", wual))), ssWu.Sections.Select( wuse => new XElement("section", new XAttribute("name", wuse.Name), new XAttribute("assetId", wuse.AssetIdentifier))), new XElement("template", new XAttribute("name", ssWu.StylesheetName))); }
private static XElement ResourceToXml(WorkUnitResult wu) { return new XElement("resource", new XAttribute("path", ((ResourceDeployment)wu.WorkUnit).ResourcePath)); }
public override WorkUnitResult Execute(ITemplatingContext context) { Stopwatch localTimer = Stopwatch.StartNew(); Uri newUri = new Uri(this.SaveAs, UriKind.RelativeOrAbsolute); FileMode mode = FileMode.CreateNew; bool exists; if (!(exists = context.TemplateData.OutputFileProvider.FileExists(this.SaveAs)) || context.TemplateData.OverwriteExistingFiles) { if (exists) mode = FileMode.Create; // register xslt params XsltArgumentList argList = new XsltArgumentList(); foreach (KeyValuePair<string, object> kvp in this.XsltParams) argList.AddParam(kvp.Key, string.Empty, kvp.Value); argList.XsltMessageEncountered += (s, e) => TraceSources.TemplateSource.TraceInformation("Message: {0}.", e.Message); // and custom extensions argList.AddExtensionObject(Namespaces.TemplateExtensions, new TemplateXsltExtensions(context, newUri)); using (Stream stream = context.TemplateData.OutputFileProvider.OpenFile(this.SaveAs, mode)) using (XmlWriter xmlWriter = XmlWriter.Create(stream, new XmlWriterSettings { CloseOutput = true, Indent = true })) { if (exists) { TraceSources.TemplateSource.TraceWarning("{0}, {1} => Replacing {2}", this.Asset.AssetId, this.Asset.Version, this.SaveAs); } else { TraceSources.TemplateSource.TraceInformation("{0}, {1} => {2}", this.Asset.AssetId, this.Asset.Version, this.SaveAs); } long tickStart = localTimer.ElapsedTicks; this.Transform.Transform(context.Document, argList, xmlWriter); TraceSources.TemplateSource.TraceVerbose("Transform applied in: {0:N0} ms", ((localTimer.ElapsedTicks - tickStart)/ (double) Stopwatch.Frequency)*1000); xmlWriter.Close(); } } else { TraceSources.TemplateSource.TraceWarning("{0}, {1} => Skipped, already generated ({2})", this.Asset.AssetId, this.Asset.Version, newUri); } localTimer.Stop(); WorkUnitResult result = new WorkUnitResult { WorkUnit = this, Duration = (long)Math.Round(localTimer.ElapsedTicks/(double)Stopwatch.Frequency*1000000) }; return result; }
public override WorkUnitResult Execute(ITemplatingContext context) { Stopwatch localTimer = Stopwatch.StartNew(); Uri newUri = new Uri(this.SaveAs, UriKind.RelativeOrAbsolute); FileMode mode = FileMode.CreateNew; bool exists; if (!(exists = context.TemplateData.OutputFileProvider.FileExists(this.SaveAs)) || context.TemplateData.OverwriteExistingFiles) { if (exists) { mode = FileMode.Create; } // register xslt params XsltArgumentList argList = new XsltArgumentList(); foreach (KeyValuePair <string, object> kvp in this.XsltParams) { argList.AddParam(kvp.Key, string.Empty, kvp.Value); } argList.XsltMessageEncountered += (s, e) => TraceSources.TemplateSource.TraceInformation("Message: {0}.", e.Message); // and custom extensions argList.AddExtensionObject(Namespaces.TemplateExtensions, new TemplateXsltExtensions(context, newUri)); using (Stream stream = context.TemplateData.OutputFileProvider.OpenFile(this.SaveAs, mode)) using (XmlWriter xmlWriter = XmlWriter.Create(stream, new XmlWriterSettings { CloseOutput = true, Indent = true })) { if (exists) { TraceSources.TemplateSource.TraceWarning("{0}, {1} => Replacing {2}", this.Asset.AssetId, this.Asset.Version, this.SaveAs); } else { TraceSources.TemplateSource.TraceInformation("{0}, {1} => {2}", this.Asset.AssetId, this.Asset.Version, this.SaveAs); } long tickStart = localTimer.ElapsedTicks; this.Transform.Transform(context.Document, argList, xmlWriter); TraceSources.TemplateSource.TraceVerbose("Transform applied in: {0:N0} ms", ((localTimer.ElapsedTicks - tickStart) / (double)Stopwatch.Frequency) * 1000); xmlWriter.Close(); } } else { TraceSources.TemplateSource.TraceWarning("{0}, {1} => Skipped, already generated ({2})", this.Asset.AssetId, this.Asset.Version, newUri); } localTimer.Stop(); WorkUnitResult result = new WorkUnitResult { WorkUnit = this, Duration = (long)Math.Round(localTimer.ElapsedTicks / (double)Stopwatch.Frequency * 1000000) }; return(result); }