Beispiel #1
0
        //
        // Algorithm: export the data as XML, then transform it into HTML
        // using a stylesheet
        //
        public void Export(CoverageModel model)
        {
            if (model.hit + model.missed == 0)
                return;

            // Why doesn't NET has a Path.GetTempDirectoryName () method ?
            int index = 0;
            string tempDir;
            // Of course this is not safe but it doesn't matter
            while (true) {
                tempDir = Path.Combine (Path.Combine (Path.GetTempPath (), "monocov"), "" + index);
                if (!Directory.Exists (tempDir))
                    break;
                index++;
            }
            Directory.CreateDirectory (tempDir);

            XmlExporter exporter = new XmlExporter ();
            exporter.StyleSheet = StyleSheet;
            exporter.DestinationDir = tempDir;
            exporter.Progress += new XmlExporter.ProgressEventHandler (progressListener);

            exporter.Export (model);

            Directory.Delete (tempDir, true);
        }
Beispiel #2
0
        //
        // Algorithm: export the data as XML, then transform it into HTML
        // using a stylesheet
        //

        public void Export(CoverageModel model)
        {
            if (model.hit + model.missed == 0)
            {
                return;
            }

            // Why doesn't NET has a Path.GetTempDirectoryName () method ?
            int    index = 0;
            string tempDir;

            // Of course this is not safe but it doesn't matter
            while (true)
            {
                tempDir = Path.Combine(Path.Combine(Path.GetTempPath(), "monocov"), "" + index);
                if (!Directory.Exists(tempDir))
                {
                    break;
                }
                index++;
            }
            Directory.CreateDirectory(tempDir);

            XmlExporter exporter = new XmlExporter();

            exporter.StyleSheet     = StyleSheet;
            exporter.DestinationDir = tempDir;
            exporter.Progress      += new XmlExporter.ProgressEventHandler(progressListener);

            exporter.Export(model);

            Directory.Delete(tempDir, true);
        }
Beispiel #3
0
        private static int handleExportXml(MonoCovOptions opts, string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error: Datafile name is required when using --export-xml");
                return(1);
            }

            if (!File.Exists(args [0]))
            {
                Console.WriteLine(string.Format("Error: Datafile '{0}' not found.", args [0]));
                return(1);
            }

            if (!Directory.Exists(opts.exportXmlDir))
            {
                try {
                    Directory.CreateDirectory(opts.exportXmlDir);
                }
                catch (Exception ex) {
                    Console.WriteLine("Error: Destination directory '" + opts.exportXmlDir + "' does not exist and could not be created: " + ex);
                    return(1);
                }
            }

            try {
                CoverageModel model = new CoverageModel();
                model.ReadFromFile(args [0]);
                XmlExporter exporter = new XmlExporter();
                exporter.DestinationDir = opts.exportXmlDir;
                exporter.StyleSheet     = opts.styleSheet;
                if (!opts.quiet)
                {
                    exporter.Progress += new XmlExporter.ProgressEventHandler(progressListener);
                }
                exporter.Export(model);
            }
            catch (Exception e) {
                Console.WriteLine("Error: " + e.Message);
                return(1);
            }

            if (!opts.quiet)
            {
                Console.WriteLine();
                Console.WriteLine("Done.");
            }
            return(0);
        }
Beispiel #4
0
        private void progressListener(object sender, XmlExporter.ProgressEventArgs e)
        {
            if (e.fileName != null) {
                string name = Path.GetFileName (e.fileName);

                if (transform == null) {
                    transform = new XslTransform ();
                    transform.Load (Path.Combine (Path.GetDirectoryName (e.fileName), "Style.xsl"));
                }

                try {
                    XsltArgumentList args = new XsltArgumentList ();
                    args.AddParam ("link-suffix", "", ".html");
                    transform.Transform (new XPathDocument (new StreamReader (e.fileName)), args, new StreamWriter (Path.Combine (DestinationDir, name.Replace (".xml", ".html"))), null);
                } catch (Exception ex) {
                    Console.WriteLine ("Error: Unable to transform '" + e.fileName + "': " + ex);
                }
            }

            if (Progress != null)
                Progress (this, new ProgressEventArgs (e.item, e.fileName, e.pos, e.itemCount));
        }
Beispiel #5
0
 private static void progressListener(object sender, XmlExporter.ProgressEventArgs e)
 {
     Console.Write ("\rExporting Data: " + (e.pos * 100 / e.itemCount) + "%");
 }
Beispiel #6
0
        private static int handleExportXml(MonoCovOptions opts, string[] args)
        {
            if (args.Length == 0) {
            Console.WriteLine ("Error: Datafile name is required when using --export-xml");
            return 1;
            }

            if (!File.Exists(args [0]))
            {
            Console.WriteLine(string.Format("Error: Datafile '{0}' not found.", args [0]));
            return 1;
            }

            if (!Directory.Exists (opts.exportXmlDir)) {
            try {
                Directory.CreateDirectory (opts.exportXmlDir);
            }
            catch (Exception ex) {
                Console.WriteLine ("Error: Destination directory '" + opts.exportXmlDir + "' does not exist and could not be created: " + ex);
                return 1;
            }
            }

            try {
            CoverageModel model = new CoverageModel ();
            model.ReadFromFile (args [0]);
            XmlExporter exporter = new XmlExporter ();
            exporter.DestinationDir = opts.exportXmlDir;
            exporter.StyleSheet = opts.styleSheet;
            if (!opts.quiet)
                exporter.Progress += new XmlExporter.ProgressEventHandler (progressListener);
            exporter.Export (model);
            }
            catch (Exception e) {
            Console.WriteLine("Error: "+e.Message);
            return 1;
            }

            if (!opts.quiet) {
            Console.WriteLine ();
            Console.WriteLine ("Done.");
            }
            return 0;
        }