public static void Test_BookmarkBinaryReader_01(string file) { string traceFile = zpath.PathSetFileName(file, zPath.GetFileNameWithoutExtension(file) + "_out_bin_bookmark"); Trace.WriteLine("Test.Test_Unit.Test_Unit_PBBsonReader.Test_BookmarkBinaryReader_01()"); Trace.WriteLine("trace to file \"{0}\"", traceFile); Trace.WriteLine(); Trace.CurrentTrace.DisableBaseLog(); Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile); try { Trace.WriteLine("Test.Test_Unit.Test_Unit_PBBsonReader.Test_BookmarkBinaryReader_01()"); Trace.WriteLine(); Trace.WriteLine("read file \"{0}\"", file); Trace.WriteLine(); PBBsonReader.TraceLevel = 0; int i = 1; foreach (BsonValue bsonValue in zmongo.BsonReader <BsonValue>(file)) { Trace.WriteLine("read no {0} type {1}", i++, bsonValue.BsonType.ToString()); Trace.WriteLine(); byte[] bson = bsonValue.ToBson(); PBBsonReader reader = new PBBsonReader(BsonReader.Create(new MemoryStream(bson))); PBBsonReaderBookmark bookmark = null; int pos1 = 0; int pos = 1; while (reader.Read()) { TracePBBsonReader(reader, pos++); if (pos == 5) { Trace.WriteLine("**** create bookmark 1 at {0}", pos); bookmark = reader.GetBookmark(); pos1 = pos; } } Trace.WriteLine(); Trace.WriteLine("read bookmark 1"); reader.ReturnToBookmark(bookmark); pos = pos1; while (reader.Read()) { TracePBBsonReader(reader, pos++); } Trace.WriteLine(); } } finally { Trace.CurrentTrace.EnableBaseLog(); Trace.CurrentTrace.RemoveTraceFile(traceFile); } }
public static void Test_BookmarkTextReader_01(string file) { FileStream fileStream = null; string traceFile = zpath.PathSetFileName(file, zPath.GetFileNameWithoutExtension(file) + "_out_text_bookmark"); Trace.WriteLine("Test.Test_Unit.Test_Unit_PBBsonReader.Test_BookmarkTextReader_01()"); Trace.WriteLine("trace to file \"{0}\"", traceFile); Trace.WriteLine(); Trace.CurrentTrace.DisableBaseLog(); Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile); try { Trace.WriteLine("Test.Test_Unit.Test_Unit_PBBsonReader.Test_BookmarkTextReader_01()"); Trace.WriteLine(); Trace.WriteLine("read file \"{0}\"", file); Trace.WriteLine(); PBBsonReader.TraceLevel = 0; PBBsonReader reader = new PBBsonReader(BsonReader.Create(new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.UTF8))); PBBsonReaderBookmark bookmark = null; int pos1 = 0; int pos = 1; while (reader.Read()) { TracePBBsonReader(reader, pos++); if (pos == 5) { Trace.WriteLine("**** create bookmark 1 at {0}", pos); bookmark = reader.GetBookmark(); pos1 = pos; } } Trace.WriteLine(); Trace.WriteLine("read bookmark 1"); reader.ReturnToBookmark(bookmark); pos = pos1; while (reader.Read()) { TracePBBsonReader(reader, pos++); } } finally { if (fileStream != null) { fileStream.Close(); } Trace.CurrentTrace.EnableBaseLog(); Trace.CurrentTrace.RemoveTraceFile(traceFile); } }