public void Build_ReturnsContext() { var ctx = new ChunkFileContextBuilder() .Build(); ctx.Should().NotBeNull(); ctx.Services.Should().NotBeNull(); // we did not call ForReading/Writing ctx.ChunkFile.Should().BeNull(); }
internal FileChunkWriter CreateWriter(string filePath) { var context = new ChunkFileContextBuilder() .Endianness(Endianness.LittleEndian) .ByteAllign(2) .ForWriting(filePath) .Discover(GetType().Assembly) .Build(); var writer = new FileChunkWriter(context); return(writer); }
/// <summary> /// Read event data of a Midi file stream. /// </summary> /// <param name="stream">Must not be null.</param> /// <returns>Never returns null.</returns> /// <remarks>Closes the file when done. May throw exceptions.</remarks> public static MidiFile Read(Stream stream) { Check.IfArgumentNull(stream, nameof(stream)); using (var context = new ChunkFileContextBuilder() .BigEndian() .ForReading(stream) .Discover(typeof(MTrkChunkHandler).Assembly) .Build()) { return(Read(context)); } }
/// <summary> /// Read event data of a Midi file. /// </summary> /// <param name="filePath">Must not be null or empty.</param> /// <returns>Never returns null.</returns> /// <remarks>Closes the file when done. May throw exceptions.</remarks> public static MidiFile Read(string filePath) { Check.IfArgumentNullOrEmpty(filePath, nameof(filePath)); using (var context = new ChunkFileContextBuilder() .BigEndian() .ForReading(filePath) .Discover(typeof(MTrkChunkHandler).Assembly) .Build()) { return(Read(context)); } }
public void Build_HasFile() { var filePath = Path.Combine(TestContext.DeploymentDirectory, TestMedia.WaveFileName); var ctx = new ChunkFileContextBuilder() .ForReading(filePath) .Build(); ctx.ChunkFile.Should().NotBeNull(); ctx.ChunkFile.FilePath.Should().NotBeNullOrEmpty(); ctx.ChunkFile.BaseStream.Should().NotBeNull(); ctx.ChunkFile.FileAccess.Should().Be(FileAccess.Read); }
public void Build_HasDefaultServices() { var ctx = new ChunkFileContextBuilder() .Build(); // default services ctx.Services.GetService <FileChunkHandlerManager>().Should().NotBeNull(); ctx.Services.GetService <IChunkTypeFactory>().Should().NotBeNull(); ctx.Services.GetService <INumberReader>().Should().NotBeNull(); ctx.Services.GetService <INumberWriter>().Should().NotBeNull(); ctx.Services.GetService <IStringReader>().Should().NotBeNull(); ctx.Services.GetService <IStringWriter>().Should().NotBeNull(); }
internal static FileChunkReader CreateReader(string filePath, Endianness endianness) { var context = new ChunkFileContextBuilder() .Endianness(endianness) .ByteAllign(2) .ForReading(filePath) .Discover(typeof(FileChunkReaderTests).Assembly) .Build(); var reader = new FileChunkReader(context); return(reader); }
/// <summary> /// Write event data to a Midi file stream. /// </summary> /// <param name="midiFile">The Midi file data to write. Must not be null.</param> /// <param name="stream">Must not be null or empty.</param> /// <remarks>May throw exceptions.</remarks> public static void Write(MidiFile midiFile, Stream stream) { Check.IfArgumentNull(midiFile, nameof(midiFile)); Check.IfArgumentNull(stream, nameof(stream)); using (var context = new ChunkFileContextBuilder() .BigEndian() .ForWriting(stream) .Discover(typeof(MTrkChunkHandler).Assembly) .Build()) { Write(midiFile, context); } }
/// <summary> /// Write event data to a Midi file. /// </summary> /// <param name="midiFile">The Midi file data to write. Must not be null.</param> /// <param name="filePath">Must not be null or empty.</param> /// <remarks>May throw exceptions.</remarks> public static void Write(MidiFile midiFile, string filePath) { Check.IfArgumentNull(midiFile, nameof(midiFile)); Check.IfArgumentNullOrEmpty(filePath, nameof(filePath)); using (var context = new ChunkFileContextBuilder() .BigEndian() .ForWriting(filePath) .Discover(typeof(MTrkChunkHandler).Assembly) .Build()) { Write(midiFile, context); } }