Example #1
0
        public virtual string GenerateFromLookup(string originalValue, ObfuscationFormatOption arg)
        {
            originalValue.ThrowArgumentNullExceptionIfNull(nameof(originalValue));
            arg.ThrowArgumentNullExceptionIfNull(nameof(arg));

            string fileName = string.Empty;

            if (arg.Arguments.ContainsKey("filename"))
            {
                fileName = arg.Arguments["filename"];
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            string columnName = string.Empty;

            if (arg.Arguments.ContainsKey("columnname"))
            {
                columnName = arg.Arguments["columnname"];
            }

            if (string.IsNullOrEmpty(columnName))
            {
                throw new ArgumentNullException(nameof(columnName));
            }
            ObfuscationLookup obfuscationLookup = formattingOptionLookup.GetObfuscationLookup(fileName);

            var newValue = (string)LookupRandomValue(columnName, obfuscationLookup);

            while (originalValue.Contains(newValue))
            {
                newValue = (string)LookupRandomValue(columnName, obfuscationLookup);
            }

            return(newValue);
        }
Example #2
0
        public int GenerateRandomNumber(string originalValue, ObfuscationFormatOption arg)
        {
            originalValue.ThrowArgumentNullExceptionIfNull(nameof(originalValue));
            arg.ThrowArgumentNullExceptionIfNull(nameof(arg));

            int min = 0;
            int max = 10;

            if (arg.Arguments.ContainsKey("min"))
            {
                if (int.TryParse(arg.Arguments["min"], out int result))
                {
                    min = result;
                }
            }

            if (arg.Arguments.ContainsKey("max"))
            {
                if (int.TryParse(arg.Arguments["max"], out int result))
                {
                    max = result;
                }
            }

            if (min >= max)
            {
                throw new ArgumentOutOfRangeException($"The min({min}) must be lower than the max({max}).");
            }

            int randomNumber = FormattingOptionProcessorStatics.RandomGenerator.Next(min, max);

            while (originalValue.Contains(randomNumber.ToString(CultureInfo.InvariantCulture)))
            {
                randomNumber = FormattingOptionProcessorStatics.RandomGenerator.Next(min, max);
            }

            return(randomNumber);
        }