Ejemplo n.º 1
0
        private void TestWriteFileWinAPI1()
        {
            // This function tests out the Windows API function WriteFile.  This function tests the WriteFile function
            // by writing out the entire file with one call.
            String S;
            int    FileLoop;

            try
            {
                // Get how fast it takes to write ou the .683MB, 10MB, and 50MB files into memory.
                for (FileLoop = 0; FileLoop < 3; FileLoop++)
                {
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    WFIO.OpenForWriting(FileNames[FileLoop]);
                    WFIO.Write(BytesInFiles[FileLoop]);
                    WFIO.Close();
                    stopwatch.Stop();

                    S = "   Total time writing " + FileDesc[FileLoop] + " with WFIO1.Write API No Parsing		                = "
                        + stopwatch.Elapsed.TotalMilliseconds.ToString();
                    DispUIMsg(S);
                }
            }
            catch (System.Exception ex)
            {
                S = "TestWriteFileWinAPI1: threw an exception of type " + ex.GetType().ToString();
                DispUIMsg(S);
                DispUIMsg(ex.Message);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        private void TestWrite()
        {
            // This function tests the Write function.
            int    BytesWritten, BytesRead, Loop;
            String S;

            try
            {
                // Open the file and output the buffer.
                WFIO.OpenForWriting(TestFileName2);
                BytesWritten = WFIO.Write(VerBytesRead);
                WFIO.Close();
                // Check to see if the data that was written out matches the verification buffer.
                if (BytesWritten != VerBytesRead)
                {
                    S = "  TestWrite: test failed - BytesWritten != VerBytesRead";
                    DispUIMsg(S);
                    return;
                }
                // Read in the file that was just written out.
                WFIO.OpenForReading(TestFileName2);
                BytesRead = WFIO.ReadUntilEOF();
                WFIO.Close();
                // Check to see if the data read in matches the verification buffer.
                if (BytesRead != BytesWritten)
                {
                    S = "  TestWrite: test failed - bytes read != bytes written";
                    DispUIMsg(S);
                    return;
                }
                // Compare the 2 arrays.  If there are any differences, then report an error.
                for (Loop = 0; Loop < BytesWritten; Loop++)
                {
                    if (ByteBuf[Loop] != ByteBufVer[Loop])
                    {
                        S = "  TestWrite: test failed - the " + Loop.ToString() + " element does not match the verification buffer.";
                        DispUIMsg(S);
                        return;
                    }
                }
                S = "  TestWrite: Passed";
                DispUIMsg(S);
            }
            catch (System.Exception ex)
            {
                S = "  TestWrite: threw an exception of type " + ex.GetType().ToString();
                DispUIMsg(S);
                S = "  " + ex.Message;
                DispUIMsg(S);
            }
        }
 public void TestWriteFileWinApi1(string pathToFile, int bytesInFile)
 {
     _wfio.OpenForWriting(pathToFile);
     _wfio.Write(bytesInFile);
     _wfio.Close();
 }