Esempio n. 1
0
File: Main.cs Progetto: ewcasas/DVTK
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog.FileName = string.Empty;

            // Display Open File Dialog and wait for OK.
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                // Start the processing of the selected file using the Background Worker.
                //this.backgroundWorker.DoWork += backgroundWorker_DoWork;
                //this.backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;
                //this.backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
                this.srFilename = Path.GetFileName(openFileDialog.FileName);
                initializeFolders();
                cleanFolders();
                //this.backgroundWorker.RunWorkerAsync(openFileDialog.FileName);

                MainBackgroundWorkerArgument argument = new MainBackgroundWorkerArgument();
                argument.structuredReportPath = srFilename;
                argument.xmlPath = this.xmlFolder;
                argument.htmlPath = this.htmlFolder;

                this.mainBackgroundWorker.RunWorkerAsync(argument);
            }
        }
Esempio n. 2
0
        private void HandleDoWork(object sender, DoWorkEventArgs e)
        {
            MainBackgroundWorkerArgument argument = (MainBackgroundWorkerArgument)e.Argument;

            lock (this.fieldLock)
            {
                this.validationCompleted = false;
                this.xmlToHtmlCompleted  = false;
                this.exception           = null;
            }


            //
            // Perform the validation in the background.
            //

            ValidatorBackgroundWorkerArgument validatorBackgroundWorkerArgument = new ValidatorBackgroundWorkerArgument();

            validatorBackgroundWorkerArgument.structuredReportPath = argument.structuredReportPath;
            validatorBackgroundWorkerArgument.xmlPath = argument.xmlPath;
            this.validatorBackgroundWorker.RunWorkerAsync(validatorBackgroundWorkerArgument);


            //
            // Wait until validation has been completed.
            //

            bool wait = true;

            while (wait)
            {
                lock (this.fieldLock)
                {
                    wait = !this.validationCompleted;
                }

                if (wait)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }


            //
            // If an exception has been thrown during validation, rethrow it again.
            //

            lock (this.fieldLock)
            {
                if (this.exception != null)
                {
                    throw (this.exception);
                }
            }


            //
            // Convert the .xml files to .html files.
            //

            // Iterate through all template files in the templates folder.
            foreach (string templatePath in Directory.GetFiles(this.templatesPath))
            {
                // Create for each template a Xslt Transformation Workitem and place it in the queue.
                string xmlFile  = Path.Combine(argument.xmlPath, "Output.xml");
                string htmlFile = Path.Combine(argument.htmlPath, Path.GetFileNameWithoutExtension(templatePath) + ".html");
                xsltProcessor.AddWorkItem(new WorkItem(xmlFile, templatePath, htmlFile));
            }

            string part3ValidationStyleSheetTransformationFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DVT_RESULTS.xslt");

            string part3ValidationSummaryXmlFile  = Path.Combine(argument.xmlPath, "Summary_Part 3 validation.xml");
            string part3ValidationSummaryHtmlFile = Path.Combine(argument.htmlPath, "Part 3 validation summary.html");

            xsltProcessor.AddWorkItem(new WorkItem(part3ValidationSummaryXmlFile, part3ValidationStyleSheetTransformationFile, part3ValidationSummaryHtmlFile));

            string part3ValidationDetailXmlFile  = Path.Combine(argument.xmlPath, "Detail_Part 3 validation.xml");
            string part3ValidationDetailHtmlFile = Path.Combine(argument.htmlPath, "Part 3 validation detail.html");

            xsltProcessor.AddWorkItem(new WorkItem(part3ValidationDetailXmlFile, part3ValidationStyleSheetTransformationFile, part3ValidationDetailHtmlFile));

            // Process the queue.
            xsltProcessor.StartAsync();


            //
            // Wait until .xml to .html conversion has been completed.
            //

            wait = true;

            while (wait)
            {
                lock (this.fieldLock)
                {
                    wait = !this.xmlToHtmlCompleted;
                }

                if (wait)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }


            //
            // If an exception has been thrown during the xml to html conversion, rethrow it again.
            //

            lock (this.fieldLock)
            {
                if (this.exception != null)
                {
                    throw (this.exception);
                }
            }
        }