コード例 #1
0
        private void TestReadFileWinAPI1()
        {
            // This function tests out the Windows API function ReadFile.  This function tests the ReadFile function
            // by reading in the entire file with one call.
            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.Read(BufSizeM1M);
                    WFIO.Close();
                    stopwatch.Stop();

                    S = "   Total time reading " + FileDesc[FileLoop] + " with WFIO1.Read No Parsing			= "
                        + stopwatch.Elapsed.TotalMilliseconds.ToString();
                    DispUIMsg(S);
                }
            }
            catch (System.Exception ex)
            {
                S = "TestReadFileWinAPI1: threw an exception of type " + ex.GetType().ToString();
                DispUIMsg(S);
                DispUIMsg(ex.Message);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        private void TestRead()
        {
            // This function tests the Read function.
            int    BytesRead, Loop;
            String S;

            try
            {
                WFIO.OpenForReading(TestFileName);
                BytesRead = WFIO.Read(BufSize);
                WFIO.Close();
                // Check to see if the data read in matches the verification buffer.
                if (BytesRead != VerBytesRead)
                {
                    S = "  TestRead: 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 = "  TestRead: test failed - the " + Loop.ToString() + " element does not match the verification buffer.";
                        DispUIMsg(S);
                        return;
                    }
                }
                S = "  TestRead: Passed";
                DispUIMsg(S);
            }
            catch (System.Exception ex)
            {
                S = "  TestRead: threw an exception of type " + ex.GetType().ToString();
                DispUIMsg(S);
                S = "  " + ex.Message;
                DispUIMsg(S);
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public void TestLengthRead()
        {
            string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "WinFileIOTests.TestLengthRead");

            createFile(filePath);

            byte[]    buffer = new byte[1];
            WinFileIO wfio   = new WinFileIO(buffer);

            wfio.OpenForReading(filePath);

            Assert.AreEqual((long)FILE_CONTENT.Length, wfio.Length);

            wfio.Close();
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
 public void TestReadFileWinApi1(string pathToFile)
 {
     _wfio.OpenForReading(pathToFile);
     _wfio.Read(BufSizeM1M);
     _wfio.Close();
 }