private string PerformRedaction(string originalReport)
        {
            var words       = new List <string>();
            var wordBuilder = new StringBuilder();

            var newReportBuilder    = new StringBuilder();
            var newReportProcessing = originalReport;

            foreach (var regex in RedactionDictionary.GetInstance().RegexCache)
            {
                newReportProcessing = regex.Replace(newReportProcessing, " [REDACTED]");
            }

            var characterGap = 0;

            foreach (var c in newReportProcessing)
            {
                if (char.IsLetter(c) || (c == '-' || c == '.') && wordBuilder.Length > 0)
                {
                    wordBuilder.Append(c);
                    if (c == '-' || c == '.')
                    {
                        characterGap++;
                    }
                    else
                    {
                        characterGap = 0;
                    }
                }
                else
                {
                    if (wordBuilder.Length > 0)
                    {
                        CompleteWord(wordBuilder, newReportBuilder, words, characterGap);
                    }

                    newReportBuilder.Append(c);
                }
            }

            if (wordBuilder.Length > 0)
            {
                CompleteWord(wordBuilder, newReportBuilder, words, characterGap);
            }

            var newReport = newReportBuilder.ToString();

            for (var i = 0; i < words.Count; i++)
            {
                if (!DictionaryContains(words[i]))
                {
                    words[i] = "[REDACTED]";
                }

                newReport = newReport.Replace($"{{{i}}}", words[i]);
            }

            // Proven init only happens the first time the code is called after its been reloaded from file
            return(newReport.Trim());
        }
        private bool DictionaryContains(string word)
        {
            var lower = word.ToLowerInvariant();

            if (BlacklistContains(lower))
            {
                return(false);
            }

            if (RedactionDictionary.GetInstance().BinarySearch(lower) > -1)
            {
                return(true);
            }

            if (!word.Contains('-'))
            {
                return(false);
            }

            var subwords = lower.Split('-');

            foreach (var subword in subwords)
            {
                if (BlacklistContains(lower))
                {
                    return(false);
                }
                if (RedactionDictionary.GetInstance().BinarySearch(subword) > -1)
                {
                    return(true);
                }
            }

            return(false);
        }
        public static string WipeoutReportsMatchingRemovalMarkers(string report)
        {
            var redactionTool = new Redaction();

            // Make sure the database report removal is loaded.
            // This will only run once per dictionary instance therefore use the ReloadReportRemovalCache method to refresh from the database
            var b = RedactionDictionary.GetInstance().AttemptToLoadReportRemovalRegexFromDatabase();

            return(b ?? redactionTool.PerformReportWipeout(report));
        }
        public static string CleanBoilerPlate(string report)
        {
            var redactionTool = new Redaction();

            // Make sure the database boilerplate is loaded.
            // This will only run once per dictionary instance therefore use the ReloadBoilerPlateCache method to refresh from the database
            var b = RedactionDictionary.GetInstance().AttemptToLoadBoilerPlateRegexFromDatabase();

            return(b ?? redactionTool.CleanOutAllBoilerPlate(report));
        }
        private string CleanOutAllBoilerPlate(string originalReport)
        {
            var cleanedReport = originalReport.Trim();

            foreach (var regex in RedactionDictionary.GetInstance().BoilerPlateRegexCache)
            {
                cleanedReport = regex.Replace(cleanedReport, "");
            }

            return(cleanedReport.Trim());
        }
        private string PerformReportWipeout(string report)
        {
            var trimmed = report.Trim();

            if (string.IsNullOrEmpty(trimmed))
            {
                return(null);
            }

            foreach (var regex in RedactionDictionary.GetInstance().ReportRemovalRegexCache)
            {
                if (regex.IsMatch(trimmed))
                {
                    return(null);
                }
            }

            return(trimmed);
        }
Beispiel #7
0
 public static void ResetInstance()
 {
     _instance = null;
 }
Beispiel #8
0
 public static RedactionDictionary GetInstance()
 {
     return(_instance ?? (_instance = new RedactionDictionary()));
 }
 public static string ReloadReportRemovalCache()
 {
     return(RedactionDictionary.GetInstance().ReloadReportRemovalCache());
 }
 public static string ReloadBoilerPlateCache()
 {
     return(RedactionDictionary.GetInstance().ReloadBoilerPlateCache());
 }