Example #1
0
        /// <summary>
        /// Creates a new instance that will connect to the database server (<paramref name="target"/>) and perform redactions using the <paramref name="updater"/>
        /// </summary>
        /// <param name="opts">CLI options for the process</param>
        /// <param name="target">DBMS to connect to for redacting</param>
        /// <param name="ignorer">Rules base for detecting false positives</param>
        /// <param name="updater">Rules base for redacting true positives</param>
        public UnattendedReviewer(IsIdentifiableReviewerOptions opts, Target target, IgnoreRuleGenerator ignorer, RowUpdater updater)
        {
            _log = LogManager.GetCurrentClassLogger();

            if (string.IsNullOrWhiteSpace(opts.FailuresCsv))
            {
                throw new Exception("Unattended requires a file of errors to process");
            }

            var fi = new FileInfo(opts.FailuresCsv);

            if (!fi.Exists)
            {
                throw new FileNotFoundException($"Could not find Failures file '{fi.FullName}'");
            }

            if (!opts.OnlyRules)
            {
                _target = target ?? throw new Exception("A single Target must be supplied for database updates");
            }

            _reportReader = new ReportReader(fi);

            if (string.IsNullOrWhiteSpace(opts.UnattendedOutputPath))
            {
                throw new Exception("An output path must be specified for Failures that could not be resolved");
            }

            _outputFile = new FileInfo(opts.UnattendedOutputPath);

            _ignorer = ignorer;
            _updater = updater;
        }
Example #2
0
        private void OpenReport(string path, Action <Exception> exceptionHandler)
        {
            if (path == null)
            {
                return;
            }

            var cts = new CancellationTokenSource();

            var    btn        = new Button("Cancel");
            Action cancelFunc = () => { cts.Cancel(); };
            Action closeFunc  = () => { Application.RequestStop(); };

            btn.Clicked += cancelFunc;

            var dlg  = new Dialog("Opening", MainWindow.DlgWidth, 5, btn);
            var rows = new Label($"Loaded: 0 rows")
            {
                Width = Dim.Fill()
            };

            dlg.Add(rows);

            Task.Run(() => {
                try
                {
                    CurrentReport = new ReportReader(new FileInfo(path), (s) =>
                                                     rows.Text = $"Loaded: {s:N0} rows", cts.Token);
                    SetupToShow(CurrentReport.Failures.FirstOrDefault());
                    Next();
                }
                catch (Exception e)
                {
                    exceptionHandler(e);
                }
            }
                     ).ContinueWith((t) => {
                btn.Clicked -= cancelFunc;
                btn.Text     = "Done";
                btn.Clicked += closeFunc;
                dlg.SetNeedsDisplay();

                cts.Dispose();
            });

            Application.Run(dlg);
        }