private async ValueTask <byte[]> FormatAsync(RequestContent requestContent, bool async) { using var memoryStream = new MaxLengthStream(_maxLength); if (async) { await requestContent.WriteToAsync(memoryStream, _cancellationToken).ConfigureAwait(false); } else { requestContent.WriteTo(memoryStream, _cancellationToken); } return(memoryStream.ToArray()); }
public void MaxLengthStreamTests() { string[] lines = new string[] { "G1 X0 Y0 Z0 E0 F500", "M105", "G1 X18 Y0 Z0 F2500", "G28", "G1 X0 Y0 Z0 E0 F500", null, }; // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream. // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence). string[] expected = new string[] { "G1 X0 Y0 Z0 E0 F500", "M105", "G1 X6 F2500", "G1 X12", "G1 X18", "G28", "G1 X12 F500", "G1 X6", "G1 X0", null, }; AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); MaxLengthStream maxLengthStream = new MaxLengthStream(new TestGCodeStream(lines), 6); int expectedIndex = 0; string actualLine = maxLengthStream.ReadLine(); string expectedLine = expected[expectedIndex++]; Assert.AreEqual(expectedLine, actualLine, "Unexpected response from MaxLengthStream"); while (actualLine != null) { actualLine = maxLengthStream.ReadLine(); expectedLine = expected[expectedIndex++]; Assert.AreEqual(expectedLine, actualLine, "Unexpected response from MaxLengthStream"); } }
private async ValueTask <byte[]> FormatAsync(Stream content, bool async) { using var memoryStream = new MaxLengthStream(_maxLength); if (async) { await content.CopyToAsync(memoryStream, CopyBufferSize, _cancellationToken).ConfigureAwait(false); } else { content.CopyTo(memoryStream); } content.Seek(0, SeekOrigin.Begin); return(memoryStream.ToArray()); }
public void MaxLengthStreamTests() { string[] lines = new string[] { "G1 X0 Y0 Z0 E0 F500", "M105", "G1 X18 Y0 Z0 F2500", "G28", "G1 X0 Y0 Z0 E0 F500", null, }; // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream. // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence). string[] expected = new string[] { "G1 X0 Y0 Z0 E0 F500", "M105", "G1 X6 F2500", "G1 X12", "G1 X18", "G28", "G1 X12 F500", "G1 X6", "G1 X0", null, }; MaxLengthStream maxLengthStream = new MaxLengthStream(new TestGCodeStream(lines), 6); int expectedIndex = 0; string actualLine = maxLengthStream.ReadLine(); string expectedLine = expected[expectedIndex++]; Assert.AreEqual(expectedLine, actualLine, "Unexpected response from MaxLengthStream"); while (actualLine != null) { actualLine = maxLengthStream.ReadLine(); expectedLine = expected[expectedIndex++]; Assert.AreEqual(expectedLine, actualLine, "Unexpected response from MaxLengthStream"); } }