예제 #1
0
        /// <summary>
        /// Masks the specified object with new data
        /// </summary>
        /// <param name="obj">The object to mask</param>
        /// <param name="tableConfig">The table configuration.</param>
        /// <returns></returns>
        public IDictionary <string, object> Mask(
            IDictionary <string, object> obj,
            TableConfig tableConfig)
        {
            foreach (ColumnConfig columnConfig in tableConfig.Columns.Where(x => !x.Ignore))
            {
                object existingValue = obj[columnConfig.Name];

                Name.Gender?gender = null;
                if (!string.IsNullOrEmpty(columnConfig.UseGenderColumn))
                {
                    object g = obj[columnConfig.UseGenderColumn];
                    gender = Utils.Utils.TryParseGender(g?.ToString());
                }

                if (columnConfig.Unique)
                {
                    existingValue = GetUniqueValue(tableConfig.Name, columnConfig, existingValue, gender);
                }
                else
                {
                    existingValue = _dataGenerator.GetValue(columnConfig, existingValue, gender);
                }



                //replace the original value
                obj[columnConfig.Name] = existingValue;
            }

            return(obj);
        }
예제 #2
0
        /// <summary>
        /// Masks the specified object with new data
        /// </summary>
        /// <param name="obj">The object to mask</param>
        /// <param name="tableConfig">The table configuration.</param>
        /// <returns></returns>
        public IDictionary <string, object> Mask(
            IDictionary <string, object> obj,
            TableConfig tableConfig)
        {
            foreach (ColumnConfig columnConfig in tableConfig.Columns.Where(x => !x.Ignore && x.Type != DataType.Computed))
            {
                object existingValue = obj[columnConfig.Name];

                Name.Gender?gender = null;
                if (!string.IsNullOrEmpty(columnConfig.UseGenderColumn))
                {
                    object g = obj[columnConfig.UseGenderColumn];
                    gender = Utils.Utils.TryParseGender(g?.ToString());
                }

                if (columnConfig.Unique)
                {
                    existingValue = GetUniqueValue(tableConfig.Name, columnConfig, existingValue, gender);
                }
                else
                {
                    existingValue = _dataGenerator.GetValue(columnConfig, existingValue, gender);
                }
                //replace the original value
                obj[columnConfig.Name] = existingValue;
            }

            foreach (ColumnConfig columnConfig in tableConfig.Columns.Where(x => !x.Ignore && x.Type == DataType.Computed))
            {
                var           separator = columnConfig.Separator ?? " ";
                StringBuilder colValue  = new StringBuilder();
                bool          first     = true;
                foreach (var sourceColumn in columnConfig.SourceColumns)
                {
                    if (!obj.ContainsKey(sourceColumn))
                    {
                        throw new Exception($"Source column {sourceColumn} could not be found.");
                    }

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        colValue.Append(separator);
                    }
                    colValue.Append(obj[sourceColumn] ?? String.Empty);
                }
                obj[columnConfig.Name] = colValue.ToString();
            }
            return(obj);
        }