Exemple #1
0
        private void CallbackSaveDataExtractorsCsvReport(
            object sender,
            EventArgs e,
            MacroscopeCsvDataExtractorReport.OutputWorksheet SelectedOutputWorksheet,
            string OutputFilename
            )
        {
            SaveFileDialog Dialog = new SaveFileDialog();

            Dialog.Filter           = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
            Dialog.FilterIndex      = 2;
            Dialog.RestoreDirectory = true;
            Dialog.DefaultExt       = "csv";
            Dialog.AddExtension     = true;
            Dialog.FileName         = OutputFilename;

            this.Enabled = false;

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                string Path = Dialog.FileName;
                MacroscopeCsvDataExtractorReport CsvReport;

                CsvReport = new MacroscopeCsvDataExtractorReport(
                    NewDataExtractorCssSelectors: this.DataExtractorCssSelectors,
                    NewDataExtractorRegexes: this.DataExtractorRegexes,
                    NewDataExtractorXpaths: this.DataExtractorXpaths
                    );

                try
                {
                    Cursor.Current = Cursors.WaitCursor;

                    CsvReport.WriteCsv(
                        JobMaster: this.JobMaster,
                        SelectedOutputWorksheet: SelectedOutputWorksheet,
                        OutputFilename: Path
                        );

                    Cursor.Current = Cursors.Default;
                }
                catch (MacroscopeSaveCsvFileException ex)
                {
                    this.DialogueBoxError("Error saving Page Metadata CSV Report", ex.Message);
                }
                catch (Exception ex)
                {
                    this.DialogueBoxError("Error saving Page Metadata CSV Report", ex.Message);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }

            Dialog.Dispose();

            this.Enabled = true;
        }
Exemple #2
0
        /**************************************************************************/

        public void WriteCsv(
            MacroscopeJobMaster JobMaster,
            MacroscopeCsvDataExtractorReport.OutputWorksheet SelectedOutputWorksheet,
            string OutputFilename
            )
        {
            try
            {
                using (StreamWriter writer = File.CreateText(OutputFilename))
                {
                    CsvWriter ws = new CsvWriter(writer);

                    switch (SelectedOutputWorksheet)
                    {
                    case MacroscopeCsvDataExtractorReport.OutputWorksheet.CSS_SELECTORS:
                        this.BuildWorksheetCssSelectors(JobMaster, ws);
                        break;

                    case MacroscopeCsvDataExtractorReport.OutputWorksheet.REGEXES:
                        this.BuildWorksheetRegularExpressions(JobMaster, ws);
                        break;

                    case MacroscopeCsvDataExtractorReport.OutputWorksheet.XPATHS:
                        this.BuildWorksheetXpaths(JobMaster, ws);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (CsvHelperException)
            {
                MacroscopeSaveCsvFileException CannotSaveCsvFileException;
                CannotSaveCsvFileException = new MacroscopeSaveCsvFileException(
                    string.Format("Cannot write to CSV file at {0}", OutputFilename)
                    );
                throw CannotSaveCsvFileException;
            }
            catch (IOException)
            {
                MacroscopeSaveCsvFileException CannotSaveCsvFileException;
                CannotSaveCsvFileException = new MacroscopeSaveCsvFileException(
                    string.Format("Cannot write to CSV file at {0}", OutputFilename)
                    );
                throw CannotSaveCsvFileException;
            }
        }