internal void DeserializeTableData(SerializationInfo info, StreamingContext context, int serIndex)
{
bool enforceConstraintsOrg = _enforceConstraints;
bool inDataLoadOrg = _inDataLoad;
try
{
_enforceConstraints = false;
_inDataLoad = true;
IFormatProvider formatProvider = CultureInfo.InvariantCulture;
int rowCount = info.GetInt32(string.Format(formatProvider, "DataTable_{0}.Rows.Count", serIndex));
int recordCount = info.GetInt32(string.Format(formatProvider, "DataTable_{0}.Records.Count", serIndex));
BitArray rowStates = (BitArray)info.GetValue(string.Format(formatProvider, "DataTable_{0}.RowStates", serIndex), typeof(BitArray));
ArrayList storeList = (ArrayList)info.GetValue(string.Format(formatProvider, "DataTable_{0}.Records", serIndex), typeof(ArrayList));
ArrayList nullbitList = (ArrayList)info.GetValue(string.Format(formatProvider, "DataTable_{0}.NullBits", serIndex), typeof(ArrayList));
Hashtable rowErrors = (Hashtable)info.GetValue(string.Format(formatProvider, "DataTable_{0}.RowErrors", serIndex), typeof(Hashtable));
rowErrors.OnDeserialization(this);//OnDeSerialization must be called since the hashtable gets deserialized after the whole graph gets deserialized
Hashtable colErrors = (Hashtable)info.GetValue(string.Format(formatProvider, "DataTable_{0}.ColumnErrors", serIndex), typeof(Hashtable));
colErrors.OnDeserialization(this);//OnDeSerialization must be called since the hashtable gets deserialized after the whole graph gets deserialized
if (recordCount <= 0)
{
//No need for deserialization of the storage and errors if there are no records.
return;
}
//Point the record manager storage to the deserialized values.
for (int i = 0; i < Columns.Count; i++)
{
Columns[i].SetStorage(storeList[i], (BitArray)nullbitList[i]);
}
//Create rows and set the records appropriately.
int recordIndex = 0;
DataRow[] rowArr = new DataRow[recordCount];
for (int i = 0; i < rowCount; i++)
{
//Create a new row which sets old and new records to -1.
DataRow row = NewEmptyRow();
rowArr[recordIndex] = row;
int bitIndex = i * 3;
switch (ConvertToRowState(rowStates, bitIndex))
{
case DataRowState.Unchanged:
row._oldRecord = recordIndex;
row._newRecord = recordIndex;
recordIndex += 1;
break;
case DataRowState.Added:
row._oldRecord = -1;
row._newRecord = recordIndex;
recordIndex += 1;
break;
case DataRowState.Modified:
row._oldRecord = recordIndex;
row._newRecord = recordIndex + 1;
rowArr[recordIndex + 1] = row;
recordIndex += 2;
break;
case DataRowState.Deleted:
row._oldRecord = recordIndex;
row._newRecord = -1;
recordIndex += 1;
break;
}
if (rowStates[bitIndex + 2])
{
row._tempRecord = recordIndex;
rowArr[recordIndex] = row;
recordIndex += 1;
}
else
{
row._tempRecord = -1;
}
Rows.ArrayAdd(row);
row.rowID = _nextRowID;
_nextRowID++;
ConvertToRowError(i, rowErrors, colErrors);
}
_recordManager.SetRowCache(rowArr);
ResetIndexes();
}
finally
{
_enforceConstraints = enforceConstraintsOrg;
_inDataLoad = inDataLoadOrg;
}
}