예제 #1
0
 private static XElement ResourceToXml(WorkUnitResult wu)
 {
     return new XElement("resource",
                         new XAttribute("path", ((ResourceDeployment)wu.WorkUnit).ResourcePath));
 }
예제 #2
0
 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("alias",
                                                  new XAttribute("name",wuse.Name),
                                                  new XAttribute("assetId",wuse.AssetIdentifier))),
                         new XElement("template",
                                      new XAttribute("name", ssWu.StylesheetName)));
 }
예제 #3
0
        public override WorkUnitResult Execute(ITemplatingContext context)
        {
            Stopwatch localTimer = Stopwatch.StartNew();

            string targetPath = Path.Combine(context.TemplateData.TargetDirectory, this.SaveAs);

            string targetDir = Path.GetDirectoryName(targetPath);
            if (targetDir != null && !Directory.Exists(targetDir))
            {
                TraceSources.TemplateSource.TraceVerbose("Creating directory: {0}", targetDir);

                // noop if exists
                Directory.CreateDirectory(targetDir);
            }

            Uri newUri = new Uri(this.SaveAs, UriKind.RelativeOrAbsolute);

            bool exists;
            if (!(exists = File.Exists(targetPath)) || context.TemplateData.OverwriteExistingFiles)
            {
                if (exists)
                    File.Delete(targetPath);

                // 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("urn:lostdoc-core", new TemplateXsltExtensions(context, newUri));

                using (FileStream stream = File.Create(targetPath))
                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;
        }
예제 #4
0
 private XElement ConvertToXml(WorkUnitResult wu)
 {
     return new XElement("result",
                         new XAttribute("duration", XmlConvert.ToString(Math.Round((double)wu.Duration/1000.0, 2))),
                         wu.WorkUnit is ResourceDeployment ? ResourceToXml(wu) : StylesheetToXml(wu));
 }
예제 #5
0
 public TemplateOutput(WorkUnitResult[] result)
 {
     this.Results = result;
 }