public override bool Execute() { TaskReporter reporter = new TaskReporter(this); int rc = NXsltMain.RETURN_CODE_OK; try { try { NXsltMain nxslt = new NXsltMain(); nxslt.setReporter(reporter); if (xsltParameters != null) { if (nxsltOptions.XslArgList == null) { nxsltOptions.XslArgList = new XsltArgumentList(); } ParseParameters(); } if (xsltExtensions != null) { if (nxsltOptions.XslArgList == null) { nxsltOptions.XslArgList = new XsltArgumentList(); } ParseExtensions(); } nxslt.options = nxsltOptions; if (style != null) { nxslt.options.Stylesheet = style; } if (inFiles == null || inFiles.Length == 0) { throw new NxsltTaskException("No source files indicated; use 'in' or <infiles>."); } if (outFile == null && destDir == null) { throw new NxsltTaskException("'out' and 'destdir' cannot be both omitted."); } foreach (ITaskItem file in inFiles) { Log.LogMessage(MessageImportance.Normal, "Transforming " + file.ItemSpec); nxslt.options.Source = file.ItemSpec; if (outFile != null) { nxslt.options.OutFile = outFile; } else { string destFile = Path.GetFileNameWithoutExtension(file.ItemSpec) + "." + extension; nxslt.options.OutFile = Path.Combine(destDir, destFile); } rc = nxslt.Process(); if (rc != NXsltMain.RETURN_CODE_OK) { throw new NxsltTaskException( string.Format(CultureInfo.InvariantCulture, "nxslt task failed.", rc)); } } } catch (NXsltCommandLineParsingException clpe) { //There was an exception while parsing command line reporter.ReportCommandLineParsingError(Reporter.GetFullMessage(clpe)); throw new NxsltTaskException( "nxslt task failed to parse parameters.", clpe); } catch (NXsltException ne) { reporter.ReportError(Reporter.GetFullMessage(ne)); throw new NxsltTaskException( "nxslt task failed.", ne); } } catch (Exception e) { reporter.ReportError(NXsltStrings.Error, Reporter.GetFullMessage(e)); return false; } return true; }
public override bool Execute() { TaskReporter reporter = new TaskReporter(this); int rc = NXsltMain.RETURN_CODE_OK; try { try { NXsltMain nxslt = new NXsltMain(); nxslt.setReporter(reporter); if (xsltParameters != null) { if (nxsltOptions.XslArgList == null) { nxsltOptions.XslArgList = new XsltArgumentList(); } ParseParameters(); } if (xsltExtensions != null) { if (nxsltOptions.XslArgList == null) { nxsltOptions.XslArgList = new XsltArgumentList(); } ParseExtensions(); } nxslt.options = nxsltOptions; if (style != null) { nxslt.options.Stylesheet = style; } if (inFiles == null || inFiles.Length == 0) { throw new NxsltTaskException("No source files indicated; use 'in' or <infiles>."); } if (outFile == null && destDir == null) { throw new NxsltTaskException("'out' and 'destdir' cannot be both omitted."); } foreach (ITaskItem file in inFiles) { Log.LogMessage(MessageImportance.Normal, "Transforming " + file.ItemSpec); nxslt.options.Source = file.ItemSpec; if (outFile != null) { nxslt.options.OutFile = outFile; } else { string destFile = Path.GetFileNameWithoutExtension(file.ItemSpec) + "." + extension; nxslt.options.OutFile = Path.Combine(destDir, destFile); } rc = nxslt.Process(); if (rc != NXsltMain.RETURN_CODE_OK) { throw new NxsltTaskException( string.Format(CultureInfo.InvariantCulture, "nxslt task failed.", rc)); } } } catch (NXsltCommandLineParsingException clpe) { //There was an exception while parsing command line reporter.ReportCommandLineParsingError(Reporter.GetFullMessage(clpe)); throw new NxsltTaskException( "nxslt task failed to parse parameters.", clpe); } catch (NXsltException ne) { reporter.ReportError(Reporter.GetFullMessage(ne)); throw new NxsltTaskException( "nxslt task failed.", ne); } } catch (Exception e) { reporter.ReportError(NXsltStrings.Error, Reporter.GetFullMessage(e)); return(false); } return(true); }