public static TestResult FromByteReader(MgByteReader byteReader, string operation = "") { try { TestResult res = new TestResult(); if (byteReader != null) { res.ContentType = byteReader.GetMimeType(); if (res.ContentType == MgMimeType.Html || res.ContentType == MgMimeType.Json || res.ContentType == MgMimeType.Kml || res.ContentType == MgMimeType.Text || res.ContentType == MgMimeType.Xml) { res.ResultData = byteReader.ToString(); } else { MgByteSink sink = new MgByteSink(byteReader); string path = operation + Guid.NewGuid().ToString() + "Result.bin"; if (string.IsNullOrEmpty(operation)) { path = Path.GetTempFileName(); } sink.ToFile(path); res.ResultData = File.ReadAllBytes(path); if (string.IsNullOrEmpty(operation)) { File.Delete(path); } else { System.Diagnostics.Debug.WriteLine(string.Format("[MgTestRunner]: Check out {0} if binary comparison results are strange", path)); } /* * byte[] bytes = new byte[byteReader.GetLength()]; * byteReader.Read(bytes, bytes.Length); * res.ResultData = bytes; */ } } return(res); } catch (MgException ex) { return(FromMgException(ex)); } }
public static TestResult FromByteReader(MgByteReader byteReader, string operation = "") { try { TestResult res = new TestResult(); if (byteReader != null) { res.ContentType = byteReader.GetMimeType(); if (res.ContentType == MgMimeType.Html || res.ContentType == MgMimeType.Json || res.ContentType == MgMimeType.Kml || res.ContentType == MgMimeType.Text || res.ContentType == MgMimeType.Xml) { res.ResultData = byteReader.ToString(); } else { MgByteSink sink = new MgByteSink(byteReader); string path = operation + Guid.NewGuid().ToString() + "Result.bin"; if (string.IsNullOrEmpty(operation)) path = Path.GetTempFileName(); sink.ToFile(path); res.ResultData = File.ReadAllBytes(path); if (string.IsNullOrEmpty(operation)) File.Delete(path); else System.Diagnostics.Debug.WriteLine(string.Format("[MgTestRunner]: Check out {0} if binary comparison results are strange", path)); /* byte[] bytes = new byte[byteReader.GetLength()]; byteReader.Read(bytes, bytes.Length); res.ResultData = bytes; */ } } return res; } catch (MgException ex) { return FromMgException(ex); } }
void OutputReaderContent(HttpResponse response, MgByteReader byteReader) { MemoryStream memBuf = new MemoryStream(); byte[] byteBuffer = new byte[1024]; int numBytes = byteReader.Read(byteBuffer, 1024); while (numBytes > 0) { memBuf.Write(byteBuffer, 0, numBytes); numBytes = byteReader.Read(byteBuffer, 1024); } response.ContentType = byteReader.GetMimeType(); byte[] content = memBuf.ToArray(); response.OutputStream.Write(content, 0, content.Length); }