internal DataSetCompressedStream(DataSet ds) { this.dataSet = ds; FileStream fs = new FileStream(@"c:\DataFile.dat", FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); try { DataSet tmpDs = new DataSet(); foreach (DataTable dt in ds.Tables) { DataTable newTable = tmpDs.Tables.Add(dt.TableName); foreach (DataColumn dc in dt.Columns) { newTable.Columns.Add(dc.ColumnName, dc.DataType); } foreach (DataRow r in dt.Rows) { newTable.ImportRow(r); } } tmpDs.RemotingFormat = SerializationFormat.Binary; formatter.Serialize(fs, tmpDs); } catch (SerializationException ex) { Console.WriteLine("Failed to serialize. Reason: " + ex.Message); throw; } finally { fs.Close(); } this.tableList = new List <DataTable>(); foreach (DataTable table in ds.Tables) { tableList.Add(table); } this.innerMemoryStream = new MemoryStream(); DBConverter.ToMemoryStreamNoHeader(this.innerMemoryStream, VERSION); DBConverter.ToMemoryStream(this.innerMemoryStream, this.dataSet.DataSetName); DBConverter.ToMemoryStreamNoHeader(this.innerMemoryStream, this.tableList.Count); this.innerMemoryStreamLength = this.innerMemoryStream.Position; this.innerMemoryStream.Position = 0; this.tableMemoryStream = new MemoryStream(); }
public DataTableBinarySerializer(DataTable table, MemoryStream outputStream) { this.table = table; this.colDbTypeAr = DBConverter.GetDataColumnTypeCodes(table); this.rowList = new List <DataRow>(); foreach (DataRow r in table.Rows) { if (r.RowState == DataRowState.Deleted) { continue; } rowList.Add(r); } this.outputStream = outputStream; DBConverter.ToMemoryStreamNoHeader(this.outputStream, VERSION); DBConverter.ToMemoryStream(this.outputStream, table.TableName); DBConverter.ToMemoryStreamNoHeader(this.outputStream, this.rowList.Count); this.innerMemoryStreamLength = this.outputStream.Position; }