public void Test1ChunkPlus1() { var stream = new MemoryStream(); using (var bsonWriter = new BsonBinaryWriter(stream)) { bsonWriter.WriteStartDocument(); bsonWriter.WriteBytes("Data", new byte[16 * 1024 - 15]); bsonWriter.WriteEndDocument(); bsonWriter.Close(); } }
public void TestFlushAndClose() { var stream = new MemoryStream(); using (var bsonWriter = new BsonBinaryWriter(stream)) { bsonWriter.WriteStartDocument(); bsonWriter.WriteEndDocument(); bsonWriter.Flush(); bsonWriter.Close(); } }
public static byte[] SerializeToBytes(object objectToSerialize) { new { objectToSerialize }.Must().NotBeNull(); using (var memoryStream = new MemoryStream()) { using (var writer = new BsonBinaryWriter(memoryStream)) { BsonSerializer.Serialize(writer, objectToSerialize.GetType(), objectToSerialize); writer.Close(); memoryStream.Close(); return(memoryStream.ToArray()); } } }
public static byte[] SerializeToBytes( this object objectToSerialize) { if (objectToSerialize == null) { throw new ArgumentNullException(nameof(objectToSerialize)); } using (var memoryStream = new MemoryStream()) { using (var writer = new BsonBinaryWriter(memoryStream)) { BsonSerializer.Serialize(writer, objectToSerialize.GetType(), objectToSerialize); writer.Close(); memoryStream.Close(); var result = memoryStream.ToArray(); return(result); } } }
static void Main(string[] args) { FileInfo assemblyFileInfo = new FileInfo(args[0]); string savePath = args[1]; DirectoryInfo fireMLDirInfo = assemblyFileInfo.Directory; DirectoryInfo contentDirInfo = fireMLDirInfo.Parent; List <string> plotFileList = new List <string>(); List <string> assetFileList = new List <string>(); foreach (FileInfo fileInfo in fireMLDirInfo.GetFiles("*.*", SearchOption.AllDirectories)) { string ext = fileInfo.Extension; if (ext == ".fmlplot") { plotFileList.Add(fileInfo.FullName); } else if (ext == ".fmlasset") { assetFileList.Add(fileInfo.FullName); } } string xsdDirPath = fireMLDirInfo.FullName + "\\" + "XSD"; //FireEngine.XNAContent.ContentManager contentManager = new FireEngine.XNAContent.ContentManager(contentDirInfo.FullName); CompilerKernel kernel = new CompilerKernel(plotFileList.ToArray(), assetFileList.ToArray(), xsdDirPath, null /*contentManager*/); FireMLRoot result = kernel.CompileFireML(); Error[] errors = kernel.CheckPoint(); foreach (Error e in errors) { Console.WriteLine("{0}\n{1},{2}\n{3}", e.Location.FileName, e.Location.Line, e.Location.Column, e.Message); Console.WriteLine(); } if (errors.Length > 0) { Environment.Exit(-1); return; } Stream bsonStream = new FileStream(savePath, FileMode.Create); BsonBuffer bsonBuffer = new BsonBuffer(); BsonBinaryWriterSettings bsonSettings = new BsonBinaryWriterSettings(); BsonBinaryWriter bsonWriter = new BsonBinaryWriter(bsonStream, bsonBuffer, bsonSettings); BsonSerializer.Serialize <FireMLRoot>(bsonWriter, result); bsonWriter.Close(); JsonWriterSettings jsonSettings = new JsonWriterSettings(); jsonSettings.NewLineChars = "\r\n"; jsonSettings.OutputMode = JsonOutputMode.JavaScript; jsonSettings.Indent = true; jsonSettings.IndentChars = " "; StreamWriter streamWriter = new StreamWriter(new FileStream(savePath + ".json", FileMode.Create)); JsonWriter jsonWriter = new JsonWriter(streamWriter, jsonSettings); BsonSerializer.Serialize <FireMLRoot>(jsonWriter, result); jsonWriter.Close(); }