示例#1
0
        public List <ImportDetail> GetCompletedImportDetailList(Enums.DataTypes dataType)
        {
            List <ImportDetail> ret = new List <ImportDetail>();

            try
            {
                MySqlConnection dbCon = new MySqlConnection(ConnectionString);
                dbCon.Open();

                string       sql   = "SELECT FILETYPE, LOCALFILE, LASTRECORDNUM, ID, URL FROM IMPORTDETAIL WHERE ISCOMPLETE = TRUE AND FILETYPE = '" + dataType.ToString("g") + "'";
                MySqlCommand dbCmd = new MySqlCommand(sql, dbCon);
                var          r     = dbCmd.ExecuteReader();
                while (r.Read())
                {
                    ImportDetail id = new ImportDetail();
                    id.FileType      = r.GetValue(0).ToString();
                    id.LocalFile     = r.GetValue(1).ToString();
                    id.LastRecordNum = Convert.ToInt32(r.GetValue(2));
                    id.ID            = Convert.ToInt32(r.GetValue(3));
                    id.URL           = r.GetValue(4).ToString();
                    ret.Add(id);
                }
                dbCon.Close();
            }
            catch
            {
                ret = null;
            }

            return(ret);
        }
示例#2
0
        private void PopulateProperty(T obj, string propertyName, Enums.DataTypes dataType, string value)
        {
            PropertyInfo prop;

            try
            {
                prop = obj.GetType().GetProperty(propertyName);
            }
            catch
            {
                throw new InvalidOperationException("Cannot populate property " + propertyName +
                                                    " of object type " + obj.GetType().Name + " because the type does not expose a property by that name.");
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                if ((prop.PropertyType.IsGenericType &&
                     prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) ||
                    !prop.PropertyType.IsValueType)
                {
                    prop.SetValue(obj, null);
                    return;
                }
                else
                {
                    throw new InvalidOperationException("Cannot populate non-nullable property with null value.");
                }
            }
            else
            {
                CastValueToType(obj, prop, value, dataType);
            }
        }
示例#3
0
        private void CastValueToType(string Key, string Value, Enums.DataTypes dataType, DataRow dr)
        {
            if (string.IsNullOrWhiteSpace(Value))
            {
                dr[Key] = DBNull.Value;
                return;
            }

            switch (dataType)
            {
            case Enums.DataTypes.BOOLEAN:
                dr[Key] = bool.Parse(Value);
                break;

            case Enums.DataTypes.BYTE:
                dr[Key] = byte.Parse(Value);
                break;

            case Enums.DataTypes.CHAR:
                dr[Key] = char.Parse(Value);
                break;

            case Enums.DataTypes.DATETIME:
                dr[Key] = DateTime.Parse(Value).ToUniversalTime();
                break;

            case Enums.DataTypes.DECIMAL:
                dr[Key] = Decimal.Parse(Value);
                break;

            case Enums.DataTypes.DOUBLE:
                dr[Key] = Double.Parse(Value);
                break;

            case Enums.DataTypes.GUID:
                dr[Key] = Guid.Parse(Value);
                break;

            case Enums.DataTypes.INT16:
                dr[Key] = Int16.Parse(Value);
                break;

            case Enums.DataTypes.INT32:
                dr[Key] = Int32.Parse(Value);
                break;

            case Enums.DataTypes.INT64:
                dr[Key] = Int64.Parse(Value);
                break;

            case Enums.DataTypes.STRING:
                dr[Key] = Value;
                break;

            default:
                throw new ArgumentException("Data type of " + dataType.ToString() + " is not mapped to a data type.");
            }
        }
示例#4
0
        private void CastValueToType(T obj, PropertyInfo prop, string value, Enums.DataTypes dataType)
        {
            switch (dataType)
            {
            case Enums.DataTypes.BOOLEAN:
                prop.SetValue(obj, bool.Parse(value));
                break;

            case Enums.DataTypes.BYTE:
                prop.SetValue(obj, byte.Parse(value));
                break;

            case Enums.DataTypes.CHAR:
                prop.SetValue(obj, char.Parse(value));
                break;

            case Enums.DataTypes.DATETIME:
                prop.SetValue(obj, DateTime.Parse(value).ToUniversalTime());
                break;

            case Enums.DataTypes.DECIMAL:
                prop.SetValue(obj, Decimal.Parse(value));
                break;

            case Enums.DataTypes.DOUBLE:
                prop.SetValue(obj, Double.Parse(value));
                break;

            case Enums.DataTypes.GUID:
                prop.SetValue(obj, Guid.Parse(value));
                break;

            case Enums.DataTypes.INT16:
                prop.SetValue(obj, Int16.Parse(value));
                break;

            case Enums.DataTypes.INT32:
                prop.SetValue(obj, Int32.Parse(value));
                break;

            case Enums.DataTypes.INT64:
                prop.SetValue(obj, Int64.Parse(value));
                break;

            case Enums.DataTypes.STRING:
                prop.SetValue(obj, value);
                break;

            default:
                throw new ArgumentException("Data type of " + dataType.ToString() + " is not mapped to a valid data type.");
            }
        }
示例#5
0
        private bool IsDataType(Enums.DataTypes dataType, string value)
        {
            switch (dataType)
            {
            case Enums.DataTypes.BOOLEAN:
                bool b;
                return(bool.TryParse(value, out b));

            case Enums.DataTypes.BYTE:
                byte by;
                return(byte.TryParse(value, out by));

            case Enums.DataTypes.CHAR:
                char c;
                return(char.TryParse(value, out c));

            case Enums.DataTypes.DATETIME:
                DateTime d;
                return(DateTime.TryParse(value, out d));

            case Enums.DataTypes.DECIMAL:
                Decimal de;
                return(Decimal.TryParse(value, out de));

            case Enums.DataTypes.DOUBLE:
                Double dbl;
                return(Double.TryParse(value, out dbl));

            case Enums.DataTypes.GUID:
                Guid g;
                return(Guid.TryParse(value, out g));

            case Enums.DataTypes.INT16:
                Int16 i16;
                return(Int16.TryParse(value, out i16));

            case Enums.DataTypes.INT32:
                Int32 i32;
                return(Int32.TryParse(value, out i32));

            case Enums.DataTypes.INT64:
                Int64 i64;
                return(Int64.TryParse(value, out i64));

            case Enums.DataTypes.STRING:
                return(true);

            default:
                return(false);
            }
        }
        private void ColumnDefinitionParserCreatesColumn(Enums.DataTypes dataType)
        {
            // Arrange
            var id = new ImportDefinition();
            var s  = "COLUMN 1 ColumnName " + dataType.ToString();

            // Act
            ColumnDefinitionParser.Parse(s, id);

            // Assert
            Assert.AreEqual(1, id.Columns.Count);
            var c = id.Columns[0];

            Assert.AreEqual(dataType, c.DataType);
            Assert.AreEqual(1, c.ColumnNumber);
            Assert.AreEqual("ColumnName", c.PropertyName);
        }
        private void DestinationParserCreatesDestinationOfType(Enums.DataTypes dataType, string SetValue)
        {
            // Arrange
            var id = new ImportDefinition();
            var s  = "DESTINATION Name " + dataType.ToString() + " SET {" + SetValue + "}";

            // Act
            DestinationParser.Parse(s, id);

            // Assert
            Assert.AreEqual(1, id.DestinationProperties.Count);
            var d = id.DestinationProperties[0];

            Assert.AreEqual("Name", d.PropertyName);
            Assert.AreEqual(dataType, d.DataType);
            Assert.IsFalse(d.Generate);
            Assert.AreEqual(SetValue, d.SetValue);
            Assert.IsFalse(d.Substitute);
            Assert.IsNull(d.SubstitutionName);
        }
示例#8
0
        public static bool CanSetValueBeParsedAsType(string value, Enums.DataTypes dataType)
        {
            switch (dataType)
            {
            case Enums.DataTypes.BOOLEAN:
                return(bool.TryParse(value, out bool boolResult));

            case Enums.DataTypes.BYTE:
                return(byte.TryParse(value, out byte byteResult));

            case Enums.DataTypes.CHAR:
                return(char.TryParse(value, out char charResult));

            case Enums.DataTypes.DATETIME:
                return(DateTime.TryParse(value, out DateTime dtResult));

            case Enums.DataTypes.DECIMAL:
                return(Decimal.TryParse(value, out Decimal decimalResult));

            case Enums.DataTypes.DOUBLE:
                return(Double.TryParse(value, out Double doubleResult));

            case Enums.DataTypes.GUID:
                return(Guid.TryParse(value, out Guid guidResult));

            case Enums.DataTypes.INT16:
                return(Int16.TryParse(value, out Int16 int16Result));

            case Enums.DataTypes.INT32:
                return(Int32.TryParse(value, out Int32 int32Result));

            case Enums.DataTypes.INT64:
                return(Int64.TryParse(value, out Int64 int64Result));

            case Enums.DataTypes.STRING:
                return(true);

            default:
                throw new ArgumentException("Data type of " + dataType.ToString() + " is not mapped to a data type.");
            }
        }
示例#9
0
        private Type GetColumnType(Enums.DataTypes dt)
        {
            switch (dt)
            {
            case Enums.DataTypes.BOOLEAN:
                return(typeof(bool));

            case Enums.DataTypes.BYTE:
                return(typeof(byte));

            case Enums.DataTypes.CHAR:
                return(typeof(char));

            case Enums.DataTypes.DATETIME:
                return(typeof(DateTime));

            case Enums.DataTypes.DECIMAL:
                return(typeof(Decimal));

            case Enums.DataTypes.DOUBLE:
                return(typeof(Double));

            case Enums.DataTypes.GUID:
                return(typeof(Guid));

            case Enums.DataTypes.INT16:
                return(typeof(Int16));

            case Enums.DataTypes.INT32:
                return(typeof(Int32));

            case Enums.DataTypes.INT64:
                return(typeof(Int64));

            case Enums.DataTypes.STRING:
                return(typeof(string));

            default:
                throw new ArgumentException("Data type of " + dt.ToString() + " is not mapped to a data type.");
            }
        }
        private void DestinationParserThrowsExceptionWhenSettingGenerateOnInvalidDataType(Enums.DataTypes dataType)
        {
            // Arrange
            var id = new ImportDefinition();
            var s  = "DESTINATION ColumnName " + dataType.ToString() + " GENERATE";

            // Act
            try
            {
                DestinationParser.Parse(s, id);
                Assert.Fail("Expected ArgumentException, not thrown.");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Cannot set GENERATE on a data type other than GUID and DATETIME.",
                                ex.Message);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected ArgumentException, " +
                            ex.GetType().Name +
                            " thrown instead.");
            }
        }
        private void DestinationParserThrowsExceptionWhenSetValueDoesNotMatchDataType(Enums.DataTypes dataType, string SetValue)
        {
            // Arrange
            var id = new ImportDefinition();
            var s  = "DESTINATION Name " + dataType.ToString() + " SET {" + SetValue + "}";
            var expectedException = "Destination Property Name " +
                                    "attempted to declare a Set Value of " + SetValue +
                                    " which cannot be cast to the declared data type of " +
                                    dataType.ToString();

            // Act
            try
            {
                DestinationParser.Parse(s, id);
                Assert.Fail("InvalidCastException expected, not thrown.");
            }
            catch (InvalidCastException ex)
            {
                Assert.AreEqual(expectedException, ex.Message);
            }
            catch (Exception ex)
            {
                Assert.Fail("InvalidCastException expected, " +
                            ex.GetType().Name +
                            " thrown instead.");
            }
        }
        private void ColumnDefinitionParserThrowsExceptionOnPRECISIONDeclaredOnNonString(Enums.DataTypes dataType)
        {
            // Arrange
            var id = new ImportDefinition();
            var s  = "COLUMN 0 ColumnName " + dataType.ToString() + " PRECISION 6 3";

            // Act
            try
            {
                ColumnDefinitionParser.Parse(s, id);
                Assert.Fail("ArgumentException expected, not thrown.");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("PRECISION validation token can only be specified for data type DECIMAL.",
                                ex.Message);
            }
            catch (Exception ex)
            {
                Assert.Fail("Argument Exception expected, " +
                            ex.GetType().Name +
                            " thrown instead.");
            }
        }