コード例 #1
0
        protected void CheckSettingsAndFirstRow(DataTable dt, ResultSetComparisonSettings settings)
        {
            if (dt.Rows.Count == 0)
            {
                return;
            }

            var dr = dt.Rows[0];

            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                if (!dr.IsNull(i))
                {
                    if (settings.GetColumnType(i) == ColumnType.Numeric && IsNumericField(dr.Table.Columns[i]))
                    {
                        continue;
                    }

                    var numericConverter = new NumericConverter();
                    if (settings.GetColumnType(i) == ColumnType.Numeric && !(numericConverter.IsValid(dr[i]) || BaseComparer.IsValidInterval(dr[i])))
                    {
                        var exception = string.Format("The column with an index of {0} is expecting a numeric value but the first row of your result set contains a value '{1}' not recognized as a valid numeric value or a valid interval."
                                                      , i, dr[i].ToString());

                        if (numericConverter.IsValid(dr[i].ToString().Replace(",", ".")))
                        {
                            exception += " Aren't you trying to use a comma (',' ) as a decimal separator? NBi requires that the decimal separator must be a '.'.";
                        }

                        throw new ResultSetComparerException(exception);
                    }

                    if (settings.GetColumnType(i) == ColumnType.DateTime && IsDateTimeField(dr.Table.Columns[i]))
                    {
                        return;
                    }

                    if (settings.GetColumnType(i) == ColumnType.DateTime && !BaseComparer.IsValidDateTime(dr[i].ToString()))
                    {
                        throw new ResultSetComparerException(
                                  string.Format("The column with an index of {0} is expecting a date & time value but the first row of your result set contains a value '{1}' not recognized as a valid date & time value."
                                                , i, dr[i].ToString()));
                    }
                }
            }
        }
コード例 #2
0
        protected void WriteSettingsToDataTableProperties(DataTable dt, ResultSetComparisonSettings settings)
        {
            foreach (DataColumn column in dt.Columns)
            {
                if (column.ExtendedProperties.ContainsKey("NBi::Role"))
                {
                    column.ExtendedProperties["NBi::Role"] = settings.GetColumnRole(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Role", settings.GetColumnRole(column.Ordinal));
                }

                if (column.ExtendedProperties.ContainsKey("NBi::Type"))
                {
                    column.ExtendedProperties["NBi::Type"] = settings.GetColumnType(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Type", settings.GetColumnType(column.Ordinal));
                }

                if (column.ExtendedProperties.ContainsKey("NBi::Tolerance"))
                {
                    column.ExtendedProperties["NBi::Tolerance"] = settings.GetTolerance(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Tolerance", settings.GetTolerance(column.Ordinal));
                }

                if (column.ExtendedProperties.ContainsKey("NBi::Rounding"))
                {
                    column.ExtendedProperties["NBi::Rounding"] = settings.GetRounding(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Rounding", settings.GetRounding(column.Ordinal));
                }
            }
        }
コード例 #3
0
        //public void GetHashCode64_KeysValues(DataRow row, out Int64 keysHashed, out Int64 valuesHashed)
        public void GetHashCode64_KeysValues(DataRow row, out Int64 keysHashed)
        {
            keysHashed = 0;
            //valuesHashed = 0;

            for (int i = 0; i < row.Table.Columns.Count; i++)
            {
                if (settings.IsKey(i))
                {
                    try
                    {
                        var value = FormatValue(i, row[i]);
                        keysHashed = (keysHashed * 397) ^ value.GetHashCode();
                    }
                    catch (FormatException)
                    {
                        var txt = "In the column with index '{0}', NBi can't convert the value '{0}' to the type '{1}'. Key columns must match with their respective types and don't support null, generic or interval values.";
                        var msg = string.Format(txt, i, row[i], settings.GetColumnType(i));
                        throw new NBiException(msg);
                    }
                    catch (InvalidCastException ex)
                    {
                        if (ex.Message.Contains("Object cannot be cast from DBNull to other types"))
                        {
                            var txt = "In the column with index '{0}', NBi can't convert the value 'DBNull' to the type '{1}'. Key columns must match with their respective types and don't support null, generic or interval values.";
                            var msg = string.Format(txt, i, row[i], settings.GetColumnType(i));
                            throw new NBiException(msg);
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }

                //else
                //    valuesHashed = (valuesHashed * 397) ^ value.GetHashCode();
            }
        }
コード例 #4
0
        public KeyCollection GetKeys(DataRow row)
        {
            var keys = new List <object>();

            for (int i = 0; i < row.Table.Columns.Count; i++)
            {
                if (settings.GetColumnRole(i) == ColumnRole.Key)
                {
                    try
                    {
                        var value = FormatValue(i, row[i]);
                        keys.Add(value);
                    }
                    catch (FormatException)
                    {
                        var txt = "In the column with index '{0}', NBi can't convert the value '{0}' to the type '{1}'. Key columns must match with their respective types and don't support null, generic or interval values.";
                        var msg = string.Format(txt, i, row[i], settings.GetColumnType(i));
                        throw new NBiException(msg);
                    }
                    catch (InvalidCastException ex)
                    {
                        if (ex.Message.Contains("Object cannot be cast from DBNull to other types"))
                        {
                            var txt = "In the column with index '{0}', NBi can't convert the value 'DBNull' to the type '{1}'. Key columns must match with their respective types and don't support null, generic or interval values.";
                            var msg = string.Format(txt, i, row[i], settings.GetColumnType(i));
                            throw new NBiException(msg);
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
            }
            return(new KeyCollection(keys.ToArray()));
        }
コード例 #5
0
        protected void WriteSettingsToDataTableProperties(DataTable dt, ResultSetComparisonSettings settings)
        {
            foreach (DataColumn column in dt.Columns)
            {
                if (column.ExtendedProperties.ContainsKey("NBi::Role"))
                    column.ExtendedProperties["NBi::Role"] = settings.GetColumnRole(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Role", settings.GetColumnRole(column.Ordinal));

                if (column.ExtendedProperties.ContainsKey("NBi::Type"))
                    column.ExtendedProperties["NBi::Type"] = settings.GetColumnType(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Type", settings.GetColumnType(column.Ordinal));

                if (column.ExtendedProperties.ContainsKey("NBi::Tolerance"))
                    column.ExtendedProperties["NBi::Tolerance"] = settings.GetTolerance(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Tolerance", settings.GetTolerance(column.Ordinal));

                if (column.ExtendedProperties.ContainsKey("NBi::Rounding"))
                    column.ExtendedProperties["NBi::Rounding"] = settings.GetRounding(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Rounding", settings.GetRounding(column.Ordinal));
            }
        }
コード例 #6
0
        protected void CheckSettingsAndFirstRow(DataTable dt, ResultSetComparisonSettings settings)
        {
            if (dt.Rows.Count == 0)
                return;

            var dr = dt.Rows[0];
            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                if (!dr.IsNull(i))
                {
                    if (settings.GetColumnType(i) == ColumnType.Numeric && IsNumericField(dr.Table.Columns[i]))
                        continue;

                    var numericConverter = new NumericConverter();
                    if (settings.GetColumnType(i) == ColumnType.Numeric && !(numericConverter.IsValid(dr[i]) || BaseComparer.IsValidInterval(dr[i])))
                    {
                        var exception = string.Format("The column with an index of {0} is expecting a numeric value but the first row of your result set contains a value '{1}' not recognized as a valid numeric value or a valid interval."
                            , i, dr[i].ToString());

                        if (numericConverter.IsValid(dr[i].ToString().Replace(",", ".")))
                            exception += " Aren't you trying to use a comma (',' ) as a decimal separator? NBi requires that the decimal separator must be a '.'.";

                        throw new ResultSetComparerException(exception);
                    }

                    if (settings.GetColumnType(i) == ColumnType.DateTime && IsDateTimeField(dr.Table.Columns[i]))
                        return;

                    if (settings.GetColumnType(i) == ColumnType.DateTime && !BaseComparer.IsValidDateTime(dr[i].ToString()))
                    {
                        throw new ResultSetComparerException(
                            string.Format("The column with an index of {0} is expecting a date & time value but the first row of your result set contains a value '{1}' not recognized as a valid date & time value."
                                , i, dr[i].ToString()));
                    }
                }
            }
        }