Beispiel #1
0
        void SourceRead_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] TempData = new byte[MaxNumBytesPerTime];

            while (!SourceRead.CancellationPending)
            {
                StartSource.WaitOne();

                long SizeToCopy      = SourceInfo.Length;
                uint SizeReadyToCopy = 0;

                FileStream SourceFile = null;
                try
                {
                    SourceFile = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None, MaxNumBytesPerTime, FileOptions.SequentialScan);

                    while (SizeToCopy > 0 && CopyRunning)
                    {
                        SizeReadyToCopy = (uint)Math.Min(SizeToCopy, MaxNumBytesPerTime);
                        if (SizeReadyToCopy != SourceFile.Read(TempData, 0, (int)SizeReadyToCopy))
                        {
                            throw new Exception("Не совпадают размеры для считывания " + SizeReadyToCopy.ToString());
                        }

                        while (CircBuf.GetFIFOCounterFreeWithWait() < SizeReadyToCopy && CopyRunning)
                        {
                            ;
                        }

                        CircBuf.WriteData(ref TempData, 0, SizeReadyToCopy);

                        SizeToCopy -= SizeReadyToCopy;
                    }
                }
                catch (Exception ex)
                {
                    ErrorWorkProc.ErrorProcess(ex);
                }
                finally
                {
                    if (SourceFile != null)
                    {
                        SourceFile.Close();
                    }
                    SourceComplited.Set();
                }
            }
        }
Beispiel #2
0
        public bool Start(string Source, string Destination, bool WaitCompletion)
        {
            if (Source == null || Destination == null ||
                !File.Exists(Source))
            {
                return(false);
            }

            source      = Source;
            destination = Destination;
            SizeCopied  = 0;

            SourceInfo = new FileInfo(source);

            if (File.Exists(destination))
            {
                c_SysIO.DeleteFile(destination);
            }

            CircBuf.AbortWait(false);
            CircBuf.FlushBuffer();

            CopyRunning = true;

            DestinationComplited.Reset();
            SourceComplited.Reset();

            StartSource.Set();
            StartDestination.Set();

            if (WaitCompletion)
            {
                WaitResult();
            }

            CopyRunning = false;

            return(true);
        }
Beispiel #3
0
 public void WaitResult()
 {
     DestinationComplited.WaitOne();
     SourceComplited.WaitOne();
 }