コード例 #1
0
        public DataTable ProcessPipelineData(DataTable toProcess, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken)
        {
            if (_commonNames == null)
            {
                //discover the table
                var tableDiscovered = NamesTable.Discover(DataAccessContext.DataLoad);

                //make sure it exists
                if (!tableDiscovered.Exists())
                {
                    throw new NotSupportedException("TableInfo '" + tableDiscovered + "' does not exist!");
                }

                //Download all the data
                var dataTable = tableDiscovered.GetDataTable();

                //Make sure it has the correct expected schema (i.e. 1 column)
                if (dataTable.Columns.Count != 1)
                {
                    throw new NotSupportedException("Expected a single column in DataTable '" + tableDiscovered + "'");
                }

                //turn it into an array (throwing out any nulls)
                _commonNames = dataTable.Rows.Cast <DataRow>().Select(r => r[0] as string).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
            }

            //Go through each row in the table
            foreach (DataRow row in toProcess.Rows)
            {
                //for each cell in current row
                foreach (DataColumn col in toProcess.Columns)
                {
                    //if it's not a column we are skipping
                    if (ColumnsNotToEvaluate != null && ColumnsNotToEvaluate.IsMatch(col.ColumnName))
                    {
                        continue;
                    }

                    //if it is a string
                    var stringValue = row[col] as string;

                    if (stringValue != null)
                    {
                        //replace any common names with REDACTED
                        foreach (var name in _commonNames)
                        {
                            stringValue = Regex.Replace(stringValue, name, "REDACTED", RegexOptions.IgnoreCase);
                        }

                        row[col] = stringValue;
                    }
                }
            }

            return(toProcess);
        }