Beispiel #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;
        }
        public void TestWriteCsv()
        {
            MacroscopeJobMaster JobMaster = new MacroscopeJobMaster(MacroscopeConstants.RunTimeMode.LIVE);
            MacroscopeDataExtractorCssSelectors DataExtractorCssSelectors = new MacroscopeDataExtractorCssSelectors(1);
            MacroscopeDataExtractorRegexes      DataExtractorRegexes      = new MacroscopeDataExtractorRegexes(1);
            MacroscopeDataExtractorXpaths       DataExtractorXpaths       = new MacroscopeDataExtractorXpaths(1);
            MacroscopeCsvDataExtractorReport    ReportFile = new MacroscopeCsvDataExtractorReport(NewDataExtractorCssSelectors: DataExtractorCssSelectors, NewDataExtractorRegexes: DataExtractorRegexes, NewDataExtractorXpaths: DataExtractorXpaths);
            List <MacroscopeCsvDataExtractorReport.OutputWorksheet> SelectedOutputWorksheets = new List <MacroscopeCsvDataExtractorReport.OutputWorksheet>();

            SelectedOutputWorksheets.Add(MacroscopeCsvDataExtractorReport.OutputWorksheet.CSS_SELECTORS);
            SelectedOutputWorksheets.Add(MacroscopeCsvDataExtractorReport.OutputWorksheet.REGEXES);
            SelectedOutputWorksheets.Add(MacroscopeCsvDataExtractorReport.OutputWorksheet.XPATHS);
            foreach (MacroscopeCsvDataExtractorReport.OutputWorksheet SelectedOutputWorksheet in SelectedOutputWorksheets)
            {
                string Filename = string.Join(".", Path.GetTempFileName(), ".csv");
                ReportFile.WriteCsv(JobMaster: JobMaster, SelectedOutputWorksheet: SelectedOutputWorksheet, OutputFilename: Filename);
                Assert.IsTrue(File.Exists(Filename));
                File.Delete(Filename);
            }
        }