private void TestReadFileWinAPI3() { // This function tests out the Windows API function ReadFile. This test tests out the ReadUntilEOF method // in the WinFileIO class. String S; int FileLoop; try { // Get how fast it takes to read in the .683MB, 10MB, and 50MB files into memory. for (FileLoop = 0; FileLoop < 3; FileLoop++) { Stopwatch stopwatch = Stopwatch.StartNew(); WFIO.OpenForReading(FileNames[FileLoop]); WFIO.ReadBlocks(BufSizeM1M); WFIO.Close(); stopwatch.Stop(); S = " Total time reading " + FileDesc[FileLoop] + " with WFIO3.ReadBlocks API No Parsing = "+ stopwatch.Elapsed.TotalMilliseconds.ToString(); DispUIMsg(S); } } catch (System.Exception ex) { S = "TestReadFileWinAPI3: threw an exception of type " + ex.GetType().ToString(); DispUIMsg(S); DispUIMsg(ex.Message); } }
public static bool Copy(string sourceFileName, string destFileName, bool overwrite, IFileCopyCallout callout, Action <ProgressMessage> report = null, Func <bool> cancel = null ) { byte[] buf = new byte[BUFSIZ]; DateTime dt0 = DateTime.Now; long ivlcnt = 0; long total = new System.IO.FileInfo(sourceFileName).Length; long count = 0; using (var threadProgress = new ThreadProgress(report)) { using (WinFileIO wfioRd = new WinFileIO(buf), wfioWr = new WinFileIO(buf)) { wfioRd.OpenForReading(sourceFileName); wfioWr.OpenForWriting(destFileName, overwrite); int read = 0; while (true) { if (cancel?.Invoke() ?? false) { return(false); } read = wfioRd.ReadBlocks(BUFSIZ); if (read <= 0) { break; } callout?.ProcessBuffer(buf, read, count); wfioWr.Write(read); count += read; DateTime dt = DateTime.Now; long tot_ms = (int)(dt - dt0).TotalMilliseconds; long q = tot_ms / IVL_MS; if (q <= ivlcnt) { continue; } ivlcnt = q; threadProgress.Report((double)count / total); } ; } } return(true); }
public void TestReadWholeFile() { string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "WinFileIOTests.TestReadWholeFile"); createFile(filePath); byte[] buffer = new byte[FILE_CONTENT.Length]; WinFileIO wfio = new WinFileIO(buffer); wfio.OpenForReading(filePath); wfio.ReadBlocks(buffer.Length); wfio.Close(); CollectionAssert.AreEqual(FILE_CONTENT, buffer); }
public void TestReadFirst8Bytes() { string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "WinFileIOTests.TestReadFirst8Bytes"); createFile(filePath); byte[] buffer = new byte[8]; WinFileIO wfio = new WinFileIO(buffer); wfio.OpenForReading(filePath); wfio.ReadBlocks(buffer.Length); wfio.Close(); byte[] expected = FILE_CONTENT.Take(buffer.Length).ToArray(); CollectionAssert.AreEqual(expected, buffer); }
public void TestPositionIncrementsRead() { string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "WinFileIOTests.TestPositionIncrementsRead"); createFile(filePath); byte[] buffer = new byte[5]; WinFileIO wfio = new WinFileIO(buffer); wfio.OpenForReading(filePath); wfio.ReadBlocks(buffer.Length); Assert.AreEqual(5, wfio.Position); wfio.Close(); }
public void TestSetPositionReadWrite() { string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "WinFileIOTests.TestSetPositionReadWrite"); byte[] buffer = new byte[1]; WinFileIO wfio = new WinFileIO(buffer); wfio.OpenForReadingWriting(filePath); Assert.AreEqual(0, wfio.Position); //Write stuff, move about writing more, then come back in & read it in etc... buffer[0] = 1; wfio.WriteBlocks(1); buffer[0] = 3; wfio.WriteBlocks(1); buffer[0] = 3; wfio.WriteBlocks(1); buffer[0] = 7; wfio.WriteBlocks(1); wfio.Position = 0; wfio.ReadBlocks(1); Assert.AreEqual(1, buffer[0]); wfio.ReadBlocks(1); Assert.AreEqual(3, buffer[0]); wfio.ReadBlocks(1); Assert.AreEqual(3, buffer[0]); wfio.ReadBlocks(1); Assert.AreEqual(7, buffer[0]); wfio.Position = 2; buffer[0] = 24; wfio.WriteBlocks(1); wfio.Position = 0; buffer[0] = 10; wfio.WriteBlocks(1); wfio.Position = 2; wfio.ReadBlocks(1); Assert.AreEqual(24, buffer[0]); wfio.Position = 0; wfio.ReadBlocks(1); Assert.AreEqual(10, buffer[0]); wfio.Close(); //Now check that the final file is what we expected it to be byte[] expected = new byte[] { 10, 3, 24, 7 }; byte[] actual = readFile(filePath); CollectionAssert.AreEqual(expected, actual); }
public void TestSetPositionRead() { string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "WinFileIOTests.TestSetPositionRead"); createFile(filePath); byte[] buffer = new byte[4]; WinFileIO wfio = new WinFileIO(buffer); wfio.OpenForReading(filePath); Assert.AreEqual(0, wfio.Position); wfio.Position = 5; Assert.AreEqual(5, wfio.Position); wfio.ReadBlocks(buffer.Length); Assert.AreEqual(5 + buffer.Length, wfio.Position); byte[] expected = FILE_CONTENT.Skip(5).Take(buffer.Length).ToArray(); CollectionAssert.AreEqual(expected, buffer); wfio.Close(); }
private void TestReadBlocks() { // This function tests the ReadBlocks function. int BytesRead, Loop; String S; try { WFIO.OpenForReading(TestFileName); BytesRead = WFIO.ReadBlocks(VerBytesRead); WFIO.Close(); // Check to see if the data read in matches the verification buffer. if (BytesRead != VerBytesRead) { S = " TestReadBlocks: test failed - bytes read != VerBytesRead"; DispUIMsg(S); return; } // Compare the 2 arrays. If there are any differences, then report an error. for (Loop = 0; Loop < BytesRead; Loop++) { if (ByteBuf[Loop] != ByteBufVer[Loop]) { S = " TestReadBlocks: test failed - the " + Loop.ToString() + " element does not match the verification buffer."; DispUIMsg(S); return; } } S = " TestReadBlocks: Passed"; DispUIMsg(S); } catch (System.Exception ex) { S = " TestReadBlocks: threw an exception of type " + ex.GetType().ToString(); DispUIMsg(S); S = " " + ex.Message; DispUIMsg(S); } }
public void TestReadFileWinApi3(string pathToFile) { _wfio.OpenForReading(pathToFile); _wfio.ReadBlocks(BufSizeM1M); _wfio.Close(); }