private static AvrPivotGridData GetTestData() { var table = new AvrDataTable(); for (int i = 0; i < 10; i++) { var rowDTO = new AvrDataRowDTO(1, 2, 2); rowDTO.SetInt(0, i); rowDTO.SetInt(1, 2 * i); rowDTO.SetObject(2, "xx_" + i); rowDTO.SetObject(3, true); rowDTO.SetDateTime(4, new DateTime(2000, 1, i + 1)); AvrDataRowEx row = table.NewRow(rowDTO); table.ThreadSafeAdd(row); } table.AcceptChanges(); return(new AvrPivotGridData(table)); }
public static void DeserializeBodyPacket(int rowsCount, Type[] types, AvrDataTable table, Func <Stream> streamCreator) { Utils.CheckNotNull(types, "types"); Utils.CheckNotNull(streamCreator, "streamCreator"); Stream stream = streamCreator(); if (stream == null) { throw new AvrException("Could not deserialize avr table packet: stream creator is null"); } int colsCount = types.Length; var internIndexes = new int[colsCount]; var internStrings = new string[colsCount][]; for (int i = 0; i < internStrings.Length; i++) { internStrings[i] = new string[sbyte.MaxValue]; } ExpressionEvaluator filter = null; if (!string.IsNullOrEmpty(table.RowFilterExpression)) { var descriptor = new AvrRowEvaluatorContextDescriptor(table); var criteriaOperator = CriteriaOperator.Parse(table.RowFilterExpression); filter = new ExpressionEvaluator(descriptor, criteriaOperator); } var rowDTO = CreateAvrDataRowDTO(types); using (var reader = new BinaryReader(stream)) { for (int i = 0; i < rowsCount; i++) { for (int j = 0; j < colsCount; j++) { sbyte status = reader.ReadSByte(); if (status > 0) { Type type = types[j]; if (type == m_TypeOfString) { string val; var internIndex = internIndexes[j]; if (internIndex < sbyte.MaxValue) { if (status == 1) { val = reader.ReadString(); internStrings[j][internIndex] = val; internIndexes[j] = internIndex + 1; } else { val = internStrings[j][status - 2]; } } else { val = reader.ReadString(); } rowDTO.SetObject(j, val); } else if (type == m_TypeOfDateTime) { var value = new DateTime(reader.ReadInt64()); rowDTO.SetDateTime(j, value); } else if (type == m_TypeOfInt32) { rowDTO.SetInt(j, reader.ReadInt32()); } else if (type == m_TypeOfInt64) { rowDTO.SetObject(j, reader.ReadInt64()); } else if (type == m_TypeOfInt16) { rowDTO.SetObject(j, reader.ReadInt16()); } else if (type == m_TypeOfDouble) { rowDTO.SetObject(j, reader.ReadDouble()); } else if (type == m_TypeOfDecimal) { rowDTO.SetObject(j, reader.ReadDecimal()); } else if (type == m_TypeOfSingle) { rowDTO.SetObject(j, reader.ReadSingle()); } else if (type == m_TypeOfBoolean) { rowDTO.SetObject(j, reader.ReadBoolean()); } else if (type == m_TypeOfByte) { rowDTO.SetObject(j, reader.ReadByte()); } } } AvrDataRowBase newRow = table.NewRow(rowDTO); if (filter == null || filter.Fit(newRow)) { table.ThreadSafeAdd(newRow); } rowDTO.Reset(); } } stream.Dispose(); }