Exemplo n.º 1
0
 /// <summary>
 /// Prints timing info.
 /// </summary>   
 public override void ReportTimings(ref NXsltTimings timings)
 {            
     Version ver = Assembly.GetExecutingAssembly().GetName().Version;
     task.Log.LogMessage(MessageImportance.Normal, string.Format(NXsltStrings.UsageHeader,
       ver.Major, ver.Minor, ver.Build,
       System.Environment.Version.Major, System.Environment.Version.Minor,
       System.Environment.Version.Build, System.Environment.Version.Revision));
     task.Log.LogMessage(MessageImportance.Normal, string.Format(NXsltStrings.Timings, timings.XsltCompileTime,
       timings.XsltExecutionTime, timings.TotalRunTime));
 }        
Exemplo n.º 2
0
        /// <summary>
        /// Prints timing info.
        /// </summary>
        public static void ReportTimings(ref NXsltTimings timings)
        {
            stderr.WriteLine();
            stderr.WriteLine();
            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            stderr.WriteLine(NXsltStrings.UsageHeader,
                             ver.Major, ver.Minor, ver.Build,
                             System.Environment.Version.Major, System.Environment.Version.Minor,
                             System.Environment.Version.Build, System.Environment.Version.Revision);
            stderr.WriteLine();
            stderr.WriteLine(NXsltStrings.Timings, timings.XsltCompileTime,
                             timings.XsltExecutionTime, timings.TotalRunTime);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Process command line arguments and applies the specified stylesheet
        /// to the specified source document.
        /// </summary>
        internal int Process()
        {
            //Start timing if needed
            Stopwatch totalTimer = null;

            if (options.ShowTiming)
            {
                timings    = new NXsltTimings();
                totalTimer = new Stopwatch();
                totalTimer.Start();
            }

            //Just show help
            if (options.ShowHelp)
            {
                reporter.ReportUsage();
                return(RETURN_CODE_OK);
            }

            //Check that everything is in place
            if (options.Source == null && !options.LoadSourceFromStdin && !options.NoSourceXml)
            {
                reporter.ReportCommandLineParsingError(NXsltStrings.ErrorMissingSource);
                return(RETURN_CODE_ERROR);
            }
            if (options.Stylesheet == null && !options.LoadStylesheetFromStdin &&
                !options.GetStylesheetFromPI && !options.PrettyPrintMode)
            {
                //No stylesheet - run identity transform
                options.IdentityTransformMode = true;
            }
            if (options.PrettyPrintMode &&
                (options.Stylesheet != null || options.LoadStylesheetFromStdin || options.GetStylesheetFromPI))
            {
                reporter.ReportCommandLineParsingError(NXsltStrings.ErrorStylesheetAndPrettyPrintMode);
                return(RETURN_CODE_ERROR);
            }

            //Prepare source XML reader
            XmlResolver srcResolver = null;

            if (options.ResolveExternals)
            {
                srcResolver = Utils.GetXmlResolver(options.SourceCredential, options, false);
            }
            XmlReader srcReader = PrepareSourceReader(srcResolver);

            if (options.PrettyPrintMode)
            {
                //Process in pretty-print mode
                Utils.PrettyPrint(srcReader, options);
            }
            else
            {
                //Process transformation
                XmlResolver stylesheetResolver = Utils.GetXmlResolver(options.XSLTCredential, options, true);

                if (options.GetStylesheetFromPI)
                {
                    //To get stylesheet from the PI we load source XML into
                    //XPathDocument (consider embedded stylesheet)
                    XPathDocument  srcDoc = new XPathDocument(srcReader, XmlSpace.Preserve);
                    XPathNavigator srcNav = srcDoc.CreateNavigator();
                    //Now srcReader reads in-memory cache instead
                    srcReader = srcNav.ReadSubtree();
                    MvpXslTransform xslt = PrepareStylesheetFromPI(srcNav, stylesheetResolver);
                    Transform(srcReader, xslt, srcResolver);
                }
                else
                {
                    MvpXslTransform xslt = PrepareStylesheet(stylesheetResolver);
                    Transform(srcReader, xslt, srcResolver);
                }
            }

            if (options.ShowTiming)
            {
                totalTimer.Stop();
                timings.TotalRunTime = totalTimer.ElapsedMilliseconds;
                reporter.ReportTimings(ref timings);
            }
            return(RETURN_CODE_OK);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Process command line arguments and applies the specified stylesheet
        /// to the specified source document.
        /// </summary>
        internal int Process()
        {
            //Start timing if needed
            Stopwatch totalTimer = null;
            if (options.ShowTiming)
            {
                timings = new NXsltTimings();
                totalTimer = new Stopwatch();
                totalTimer.Start();
            }

            //Just show help
            if (options.ShowHelp)
            {
                reporter.ReportUsage();
                return RETURN_CODE_OK;
            }

            //Check that everything is in place
            if (options.Source == null && !options.LoadSourceFromStdin && !options.NoSourceXml)
            {
                reporter.ReportCommandLineParsingError(NXsltStrings.ErrorMissingSource);
                return RETURN_CODE_ERROR;
            }
            if (options.Stylesheet == null && !options.LoadStylesheetFromStdin
              && !options.GetStylesheetFromPI && !options.PrettyPrintMode)
            {
                //No stylesheet - run identity transform
                options.IdentityTransformMode = true;
            }
            if (options.PrettyPrintMode &&
              (options.Stylesheet != null || options.LoadStylesheetFromStdin || options.GetStylesheetFromPI))
            {
                reporter.ReportCommandLineParsingError(NXsltStrings.ErrorStylesheetAndPrettyPrintMode);
                return RETURN_CODE_ERROR;
            }

            //Prepare source XML reader
            XmlResolver srcResolver = null;
            if (options.ResolveExternals)
            {
                srcResolver = Utils.GetXmlResolver(options.SourceCredential, options, false);
            }
            XmlReader srcReader = PrepareSourceReader(srcResolver);
            if (options.PrettyPrintMode)
            {
                //Process in pretty-print mode
                Utils.PrettyPrint(srcReader, options);
            }
            else
            {
                //Process transformation         
                XmlResolver stylesheetResolver = Utils.GetXmlResolver(options.XSLTCredential, options, true);

                if (options.GetStylesheetFromPI)
                {
                    //To get stylesheet from the PI we load source XML into
                    //XPathDocument (consider embedded stylesheet)
                    XPathDocument srcDoc = new XPathDocument(srcReader, XmlSpace.Preserve);
                    XPathNavigator srcNav = srcDoc.CreateNavigator();
                    //Now srcReader reads in-memory cache instead
                    srcReader = srcNav.ReadSubtree();
                    MvpXslTransform xslt = PrepareStylesheetFromPI(srcNav, stylesheetResolver);
                    Transform(srcReader, xslt, srcResolver);
                }
                else
                {
                    MvpXslTransform xslt = PrepareStylesheet(stylesheetResolver);
                    Transform(srcReader, xslt, srcResolver);
                }
            }

            if (options.ShowTiming)
            {
                totalTimer.Stop();
                timings.TotalRunTime = totalTimer.ElapsedMilliseconds;
                reporter.ReportTimings(ref timings);
            }
            return RETURN_CODE_OK;
        }