private DataColumn CreateColumn(DestinationPropertyDefinition dp)
 {
     return(new DataColumn()
     {
         ColumnName = dp.PropertyName,
         AllowDBNull = true,
         DataType = GetColumnType(dp.DataType)
     });
 }
Exemple #2
0
        public static void Parse(string Line, ImportDefinition ID)
        {
            Helpers.ParametersValid(Line, ID, "DESTINATION");

            var tokens = Line.Split(' ');

            if (tokens.Length < 4)
            {
                throw new ArgumentException("Destination definition line must contain at least 4 tokens.");
            }

#pragma warning disable IDE0017 // Simplify object initialization
            var dp = new DestinationPropertyDefinition();
#pragma warning restore IDE0017 // Simplify object initialization

            dp.PropertyName = tokens[1];
            if (Helpers.IsDestinationPropertyAlreadyDefined(tokens[1], ID))
            {
                throw new InvalidOperationException("A destination property named " + tokens[1] + " is defined more than once.");
            }

            if (Enum.IsDefined(typeof(Enums.DataTypes), tokens[2]))
            {
                try
                {
                    dp.DataType = (Enums.DataTypes)Enum.Parse(typeof(Enums.DataTypes), tokens[2]);
                }
                catch (ArgumentException ex)
                {
                    throw new ArgumentException("Invalid data type value: " + tokens[2], ex);
                }
            }
            else
            {
                throw new InvalidCastException("Cannot convert the token " + tokens[2] + " to a valid DataType.");
            }

            if (tokens[3] == "SET")
            {
                ParseDestinationSetToken(Line, dp);
            }
            else if (tokens[3] == "GENERATE")
            {
                ParseDestinationGenerateToken(tokens, dp);
            }
            else if (tokens[3] == "SUBSTITUTE")
            {
                ParseDestinationSubstitution(tokens, dp);
            }
            else
            {
                throw new ArgumentException("Invalid token for Destination declaration: " + tokens[3]);
            }

            ID.DestinationProperties.Add(dp);
        }
Exemple #3
0
        private static void ParseDestinationSubstitution(string[] tokens, DestinationPropertyDefinition dp)
        {
            if (tokens.Length < 5)
            {
                throw new IndexOutOfRangeException("SUBSTITUTE called with no parameter name specified.");
            }

            var placeholderName = tokens[4].ExtractDelimitedSection('{', '}', 0).Item1;

            dp.Substitute       = true;
            dp.SubstitutionName = placeholderName;
        }
        public void GetValueToSetReturnsGeneratedGuid()
        {
            // Arrange
            var dp = new DestinationPropertyDefinition()
            {
                PropertyName = "APropertyName",
                DataType     = Enums.DataTypes.GUID,
                Generate     = true
            };

            // Act
            var guidValueAsString = dp.GetValueToSet();

            // Assert
            Assert.IsTrue(Guid.TryParse(guidValueAsString, out Guid result));
        }
        public void GetValueToSetReturnsValue()
        {
            // Arrange
            var value = "This is a value";
            var dp    = new DestinationPropertyDefinition()
            {
                PropertyName = "APropertyName",
                DataType     = Enums.DataTypes.STRING,
                SetValue     = value
            };

            // Act
            var returnedValue = dp.GetValueToSet();

            // Assert
            Assert.AreEqual(value, returnedValue);
        }
        public void GetValueToSetReturnsSetGuid()
        {
            // Arrange
            var gValue = Guid.NewGuid();
            var dp     = new DestinationPropertyDefinition()
            {
                PropertyName = "APropertyName",
                DataType     = Enums.DataTypes.GUID,
                SetValue     = gValue.ToString()
            };

            // Act
            var gValueAsString = dp.GetValueToSet();

            //Assert
            Assert.AreEqual(gValue.ToString(), gValueAsString);
        }
        public void GetValuetoSetReturnsGeneratedDateTime()
        {
            // Arrange
            var dp = new DestinationPropertyDefinition()
            {
                PropertyName = "APropertyName",
                DataType     = Enums.DataTypes.DATETIME,
                Generate     = true
            };

            // Act
            var dateTimeAsString = dp.GetValueToSet();

            // Assert
            Assert.IsTrue(dateTimeAsString.EndsWith("Z"));
            Assert.IsTrue(DateTime.TryParse(dateTimeAsString, out DateTime result));
        }
Exemple #8
0
        private static void ParseDestinationSetToken(string line, DestinationPropertyDefinition dp)
        {
            var index = line.IndexOf(" SET ") + 5;

            if (index == -1 || index >= line.Length)
            {
                throw new InvalidOperationException("Destination Property " + dp.PropertyName + " contains a SET without a value.");
            }

            dp.SetValue = line.Substring(index).ExtractDelimitedSection('{', '}', 0).Item1;
            if (!Helpers.CanSetValueBeParsedAsType(dp.SetValue, dp.DataType))
            {
                throw new InvalidCastException("Destination Property " + dp.PropertyName +
                                               " attempted to declare a Set Value of " + dp.SetValue +
                                               " which cannot be cast to the declared data type of " +
                                               dp.DataType.ToString());
            }
        }
Exemple #9
0
 private static void ParseDestinationGenerateToken(string[] tokens, DestinationPropertyDefinition dp)
 {
     if (dp.DataType == Enums.DataTypes.GUID)
     {
         dp.Generate = true;
     }
     else if (dp.DataType == Enums.DataTypes.DATETIME)
     {
         dp.Generate = true;
         if (tokens.Length > 4 && tokens[4] == "DATEONLY")
         {
             dp.GenerateDateOnly = true;
         }
     }
     else
     {
         throw new ArgumentException("Cannot set GENERATE on a data type other than GUID and DATETIME.");
     }
 }