public void WriteToStream(StreamWriter sw, bool saveOnlyDiffs = false, List <DMSTable> selectedTables = null) { /* Write out the header */ sw.WriteLine($"SET VERSION_DAM {Version}"); sw.WriteLine(BlankLine); /* Right now we only write out LE version, though we can read BE version */ sw.WriteLine($"SET ENDIAN LE"); // sw.WriteLine($"SET ENDIAN {Endian}"); sw.WriteLine($"SET BASE_LANGUAGE {BaseLanguage}"); sw.WriteLine($"REM Database: {Database}"); sw.WriteLine($"REM Started: {Started}"); /* Write out the namespaces */ sw.WriteLine("EXPORT RECORD/SPACE.x"); foreach (var space in Namespaces) { sw.WriteLine(space); } sw.WriteLine("/"); var metadataLines = DMSEncoder.EncodeDataToLines(DDLs.GetBytes()); foreach (var line in metadataLines) { sw.WriteLine(line); } sw.WriteLine("/"); /* default to all tables */ List <DMSTable> tablesToSave = Tables; if (selectedTables != null) { tablesToSave = selectedTables; } foreach (var table in tablesToSave) { if (saveOnlyDiffs) { if (table.CompareResult == DMSCompareResult.NONE || table.CompareResult == DMSCompareResult.SAME) { /* skip */ continue; } } table.WriteToStream(sw, saveOnlyDiffs); } sw.WriteLine($"REM Ended: {Ended}"); }
internal void WriteToStream(StreamWriter sw) { StringBuilder sb = new StringBuilder(); for (var x = 0; x < Indexes.Length - 1; x++) { var start = Indexes[x]; var end = Indexes[x + 1]; var data = new byte[end - start]; Array.Copy(Values, start, data, 0, end - start); var strEnc = DMSEncoder.EncodeData(data); sb.Append(strEnc).Append(","); } var encodedLines = DMSEncoder.FormatEncodedData(sb.ToString()); foreach (var line in encodedLines) { sw.WriteLine(line); } sw.WriteLine("//"); }
internal void WriteToStream(StreamWriter sw) { var lines = DMSEncoder.EncodeDataToLines(GetBytes()); foreach (var line in lines) { sw.WriteLine(line); } MemoryStream ms = new MemoryStream(); foreach (DMSRecordFieldMetadata fieldmeta in FieldMetadata) { byte[] data = fieldmeta.GetBytes(); ms.Write(data, 0, data.Length); } lines = DMSEncoder.EncodeDataToLines(ms.ToArray()); foreach (var line in lines) { sw.WriteLine(line); } ms = new MemoryStream(); foreach (DMSRecordIndexMetadata idx in Indexes) { byte[] headerBytes = idx.GetHeaderBytes(); ms.Write(headerBytes, 0, headerBytes.Length); } lines = DMSEncoder.EncodeDataToLines(ms.ToArray()); foreach (var line in lines) { sw.WriteLine(line); } foreach (DMSRecordIndexMetadata idx in Indexes) { byte[] fieldsBytes = idx.GetFieldsBytes(); lines = DMSEncoder.EncodeDataToLines(fieldsBytes); foreach (var line in lines) { sw.WriteLine(line); } if (idx.ParameterGroups.Count > 0) { MemoryStream ms2 = new MemoryStream(); foreach (var group in idx.ParameterGroups) { byte[] headerBytes = group.GetHeaderBytes(); ms2.Write(headerBytes, 0, headerBytes.Length); } lines = DMSEncoder.EncodeDataToLines(ms2.ToArray()); foreach (var line in lines) { sw.WriteLine(line); } } foreach (var group in idx.ParameterGroups) { byte[] paramBytes = group.GetParameterBytes(); lines = DMSEncoder.EncodeDataToLines(paramBytes); foreach (var line in lines) { sw.WriteLine(line); } } } /* Write out any DDL parameter groups */ if (ParameterGroups.Count > 0) { MemoryStream ms2 = new MemoryStream(); foreach (var group in ParameterGroups) { byte[] headerBytes = group.GetHeaderBytes(); ms2.Write(headerBytes, 0, headerBytes.Length); } lines = DMSEncoder.EncodeDataToLines(ms2.ToArray()); foreach (var line in lines) { sw.WriteLine(line); } } /* Write out each param group parameter bytes (each parameter entry in the group) */ foreach (var group in ParameterGroups) { byte[] paramBytes = group.GetParameterBytes(); lines = DMSEncoder.EncodeDataToLines(paramBytes); foreach (var line in lines) { sw.WriteLine(line); } } ms = new MemoryStream(); byte[] dbType = new byte[2]; byte[] tableSpaceName = new byte[62]; byte[] dbName = new byte[18]; foreach (var tablespace in Tablespaces) { Array.Clear(dbType, 0, 2); Array.Clear(tableSpaceName, 0, 62); Array.Clear(dbName, 0, 18); var TableSpaceName = tablespace.TablespaceName; var DBName = tablespace.DatabaseName; var DBType = tablespace.DatabaseType; Encoding.Unicode.GetBytes(DBType, 0, DBType.Length, dbType, 0); Encoding.Unicode.GetBytes(TableSpaceName, 0, TableSpaceName.Length, tableSpaceName, 0); Encoding.Unicode.GetBytes(DBName, 0, DBName.Length, dbName, 0); ms.Write(dbType, 0, dbType.Length); ms.Write(tableSpaceName, 0, tableSpaceName.Length); ms.Write(dbName, 0, dbName.Length); } lines = DMSEncoder.EncodeDataToLines(ms.ToArray()); foreach (var line in lines) { sw.WriteLine(line); } }