Example #1
0
/*
 *  Checks whether the datatable schema matches with the surrogate schema.
 */

        private bool IsSchemaIdentical(DataTable dt)
        {
            Debug.Assert(dt != null);

            if (dt.TableName != _tableName || dt.Namespace != _namespace)
            {
                return(false);
            }

            Debug.Assert(_dataColumnSurrogates != null);
            if (dt.Columns.Count != _dataColumnSurrogates.Length)
            {
                return(false);
            }
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                DataColumn          dc = dt.Columns[i];
                DataColumnSurrogate dataColumnSurrogate = _dataColumnSurrogates[i];
                if (!dataColumnSurrogate.IsSchemaIdentical(dc))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
/*
 *  Sets  expression on the columns.
 */

        internal void SetColumnExpressions(DataTable dt)
        {
            Debug.Assert(dt != null);

            Debug.Assert(_dataColumnSurrogates != null);
            Debug.Assert(dt.Columns.Count == _dataColumnSurrogates.Length);
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                DataColumn          dc = dt.Columns[i];
                DataColumnSurrogate dataColumnSurrogate = _dataColumnSurrogates[i];
                dataColumnSurrogate.SetColumnExpression(dc);
            }
        }
Example #3
0
        //Keep a map between the row index and the Arraylist of columns that are in error and the error strings.

/*
 *  Constructs a DataTableSurrogate from a DataTable.
 */

        public DataTableSurrogate(DataTable dt)
        {
            if (dt == null)
            {
                throw new ArgumentNullException("The parameter dt is null");
            }

            _tableName         = dt.TableName;
            _namespace         = dt.Namespace;
            _prefix            = dt.Prefix;
            _caseSensitive     = dt.CaseSensitive;
            _locale            = dt.Locale;
            _displayExpression = dt.DisplayExpression;
            _minimumCapacity   = dt.MinimumCapacity;

            //Columns
            _dataColumnSurrogates = new DataColumnSurrogate[dt.Columns.Count];
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                _dataColumnSurrogates[i] = new DataColumnSurrogate(dt.Columns[i]);
            }

            //Constraints
            _uniqueConstraints = GetUniqueConstraints(dt);

            //ExtendedProperties
            _extendedProperties = new Hashtable();
            if (dt.ExtendedProperties.Keys.Count > 0)
            {
                foreach (object propertyKey in dt.ExtendedProperties.Keys)
                {
                    _extendedProperties.Add(propertyKey, dt.ExtendedProperties[propertyKey]);
                }
            }

            //Rows
            if (dt.Rows.Count > 0)
            {
                _rowStates = new BitArray(dt.Rows.Count << 1);
                _records   = new object[dt.Columns.Count][];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    _records[i] = new object[dt.Rows.Count << 1];
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GetRecords(dt.Rows[i], i << 1);
                }
            }
        }
Example #4
0
/*
 *  Reads the schema into the datatable from DataTableSurrogate.
 */

        public void ReadSchemaIntoDataTable(DataTable dt)
        {
            if (dt == null)
            {
                throw new ArgumentNullException("The datatable parameter cannot be null");
            }

            dt.TableName         = _tableName;
            dt.Namespace         = _namespace;
            dt.Prefix            = _prefix;
            dt.CaseSensitive     = _caseSensitive;
            dt.Locale            = _locale;
            dt.DisplayExpression = _displayExpression;
            dt.MinimumCapacity   = _minimumCapacity;

            Debug.Assert(_dataColumnSurrogates != null);
            for (int i = 0; i < _dataColumnSurrogates.Length; i++)
            {
                DataColumnSurrogate dataColumnSurrogate = _dataColumnSurrogates[i];
                DataColumn          dc = dataColumnSurrogate.ConvertToDataColumn();
                dt.Columns.Add(dc);
            }

            //UniqueConstraints
            SetUniqueConstraints(dt, _uniqueConstraints);

            //Extended properties
            Debug.Assert(_extendedProperties != null);
            if (_extendedProperties.Keys.Count > 0)
            {
                foreach (object propertyKey in _extendedProperties.Keys)
                {
                    dt.ExtendedProperties.Add(propertyKey, _extendedProperties[propertyKey]);
                }
            }
        }