private void CallbackSaveRedirectsCsvReport(
            object sender,
            EventArgs e,
            MacroscopeCsvRedirectsReport.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;
                MacroscopeCsvRedirectsReport CsvReport = new MacroscopeCsvRedirectsReport();

                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    CsvReport.WriteCsv(this.JobMaster, SelectedOutputWorksheet, Path);
                    Cursor.Current = Cursors.Default;
                }
                catch (MacroscopeSaveCsvFileException ex)
                {
                    this.DialogueBoxError("Error saving Redirects CSV Report", ex.Message);
                }
                catch (Exception ex)
                {
                    this.DialogueBoxError("Error saving Redirects CSV Report", ex.Message);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }

            if (Dialog != null)
            {
                Dialog.Dispose();
            }

            this.Enabled = true;
        }
        public void TestWriteCsv()
        {
            MacroscopeJobMaster          JobMaster  = new MacroscopeJobMaster(MacroscopeConstants.RunTimeMode.LIVE);
            MacroscopeCsvRedirectsReport ReportFile = new MacroscopeCsvRedirectsReport();
            List <MacroscopeCsvRedirectsReport.OutputWorksheet> SelectedOutputWorksheets = new List <MacroscopeCsvRedirectsReport.OutputWorksheet>();

            SelectedOutputWorksheets.Add(MacroscopeCsvRedirectsReport.OutputWorksheet.REDIRECTS_AUDIT);
            SelectedOutputWorksheets.Add(MacroscopeCsvRedirectsReport.OutputWorksheet.REDIRECT_CHAINS);
            foreach (MacroscopeCsvRedirectsReport.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);
            }
        }
        /** -------------------------------------------------------------------- **/

        private void CallbackSaveRedirectsCsvReport(object sender, EventArgs e)
        {
            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         = "Macroscope-Redirects.csv";

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

                try
                {
                    if (Macroscope.MemoryGuard(RequiredMegabytes: CsvReportMegabytesRamRequired))
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        CsvReport.WriteCsv(this.JobMaster, Path);
                        Cursor.Current = Cursors.Default;
                    }
                }
                catch (MacroscopeInsufficientMemoryException ex)
                {
                    this.DialogueBoxError("Error saving Redirects CSV Report", ex.Message);
                }
                catch (MacroscopeSaveCsvFileException ex)
                {
                    this.DialogueBoxError("Error saving Redirects CSV Report", ex.Message);
                }
                catch (Exception ex)
                {
                    this.DialogueBoxError("Error saving Redirects CSV Report", ex.Message);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }

            Dialog.Dispose();
        }