/// <summary> /// Instantiate a strongly-typed Table Wrapper around the given generic Table. /// </summary> /// <param name="table">The table to build the wrapper for.</param> internal Table(Table table) { // Validate column count. if (table.ColumnCount != 17) { throw new VoltInvalidDataException(Resources.InvalidColumnCount, table.ColumnCount); } // Validate column data types. if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(0)) == (typeof(T1)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(0)).ToString() , typeof(T1).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(1)) == (typeof(T2)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(1)).ToString() , typeof(T2).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(2)) == (typeof(T3)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(2)).ToString() , typeof(T3).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(3)) == (typeof(T4)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(3)).ToString() , typeof(T4).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(4)) == (typeof(T5)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(4)).ToString() , typeof(T5).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(5)) == (typeof(T6)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(5)).ToString() , typeof(T6).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(6)) == (typeof(T7)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(6)).ToString() , typeof(T7).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(7)) == (typeof(T8)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(7)).ToString() , typeof(T8).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(8)) == (typeof(T9)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(8)).ToString() , typeof(T9).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(9)) == (typeof(T10)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(9)).ToString() , typeof(T10).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(10)) == (typeof(T11)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(10)).ToString() , typeof(T11).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(11)) == (typeof(T12)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(11)).ToString() , typeof(T12).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(12)) == (typeof(T13)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(12)).ToString() , typeof(T13).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(13)) == (typeof(T14)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(13)).ToString() , typeof(T14).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(14)) == (typeof(T15)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(14)).ToString() , typeof(T15).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(15)) == (typeof(T16)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(15)).ToString() , typeof(T16).ToString() ); } if (!(VoltType.ToDefaultNetType(table.GetColumnDBType(16)) == (typeof(T17)))) { throw new VoltInvalidCastException( Resources.InvalidCastException , VoltType.ToDefaultNetType(table.GetColumnDBType(16)).ToString() , typeof(T17).ToString() ); } // Validation complete, keep a reference to the raw table. this.RawTable = table; // Attach the enumerable row collection. this._Rows = new RowCollection <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(this); }
/// <summary> /// Reads an array of Tables (macro data type). /// </summary> /// <returns>Array of Tables as read from the underlying byte buffer.</returns> public Table[] ReadTableArray() { int count = Cnv.GetInt16(this.Input, this.Position); this.Position += 2; Table[] result = new Table[count]; for (int i = 0; i < count; i++) result[i] = new Table(this); return result; }
/// <summary> /// Parse the response header (deferred to the based class) and the result Payload. /// </summary> /// <param name="message">The byte buffer of the binary response data from the server.</param> internal override void ParseResponse(byte[] message) { var input = new Deserializer(message); // Parse header information first, deferring to base class this.ParseHeader(input); // Return immediately if header parsing failed if (this.ServerStatus != ResponseServerStatus.Success) { return; } // Parse the result try { // Unfortunately this is ugly: have to dynamically check the type to figure out which path to take // - no generic implementation can seamlessly deal with T, T[] and T[][] Type type = typeof(TResult); // Array type - either of: // - Table[] an array of generic Tables // - SingleRowTable[] an array of generic single-row Tables // - T[][] an array of generic single-column Tables // - T[] a single single-column Table if (type.IsArray) { // Get sub-type within the array Type elementType = type.GetElementType(); // We have a Table Array if (elementType == typeof(Table)) { this._Result = (TResult)(object)input.ReadTableArray(); } // We have a SingleRowTable aArray else if (elementType == typeof(SingleRowTable)) { this._Result = (TResult)(object)input.ReadSingleRowTableArray(); } // We have an array of single-column tables else if (elementType.IsArray) { short count = input.ReadInt16(); Array result = Array.CreateInstance(elementType, count); for (short i = 0; i < count; i++) { result.SetValue(Table.FromSingleColumn(input, elementType.GetElementType()), i); } this._Result = (TResult)(object)result; } // We have a single single-column table else { short count = input.ReadInt16(); if (count != 1) { throw new VoltInvalidDataException(Resources.InvalidResultsetSize, count); } if (elementType == typeof(byte)) { elementType = typeof(byte[]); } this._Result = (TResult)Table.FromSingleColumn(input, elementType); } } // Base type - either of: // - Table // - SingleRowTable // - T else { if (type == typeof(Null)) { this._Result = (TResult)(object)new Null(); } else { // Read count: there should be only 1 data set for those calls short count = input.ReadInt16(); if (count != 1) { throw new VoltInvalidDataException(Resources.InvalidResultsetSize, count); } // A single Table if (type == typeof(Table)) { this._Result = (TResult)(object)new Table(input); } // A single single-row Table else if (type == typeof(SingleRowTable)) { this._Result = (TResult)(object)new SingleRowTable(input); } // A single value else { this._Result = (TResult)Table.FromSingleValue <TResult>(input); } } } } catch (Exception x) { this.Exception = new VoltSerializationException(Resources.ResponseDeserializationFailure, x); } }