コード例 #1
0
        /// <summary>
        /// Simulates the file copy.
        /// </summary>
        private void SimulateFileCopy()
        {
            FileCopyData fileCopyData = this.FileCopyData;

            if (0 != fileCopyData.RemainingFileCount)
            {
                if (this.CanSimulateAPause && (40 == fileCopyData.RemainingFileCount))
                {
                    this.animatedProgressBar.State = OperationState.Paused;
                    MessageBox.Show("The file 'xyz.txt' already exists, would you like to overwrite it?",
                                    "File Copy (Simluated)", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    this.animatedProgressBar.State = OperationState.Normal;
                }
                else if (this.CanSimulateAnError && (30 == fileCopyData.RemainingFileCount))
                {
                    this.animatedProgressBar.State = OperationState.Error;
                    MessageBox.Show("An error occurred while copying the file 'abc.txt'.",
                                    "File Copy (Simluated)", MessageBoxButton.OK, MessageBoxImage.Error);
                    this.animatedProgressBar.State = OperationState.Normal;
                }

                double fileTime = fileCopyData.TimeRemaining.TotalSeconds / fileCopyData.RemainingFileCount;
                double fileSize = fileCopyData.RemainingFileSize / fileCopyData.RemainingFileCount;
                fileCopyData.RemainingFileCount--;
                fileCopyData.RemainingFileSize -= fileSize;
                fileCopyData.CopiedFileSize     = fileCopyData.TotalFileSize - fileCopyData.RemainingFileSize;
                fileCopyData.Speed              = ((double)this.random.Next(6000) + 3000) / 100.0;
                fileCopyData.TimeRemaining     -= TimeSpan.FromSeconds(fileTime);
            }
            this.FileCopyData = fileCopyData;
        }
コード例 #2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Creates a <see cref="FileCopyData"/> with test values.
        /// </summary>
        /// <returns></returns>
        private static FileCopyData CreateSampleFileCopyData()
        {
            FileCopyData data = new FileCopyData();

            data.TotalFileCount = data.RemainingFileCount = 51;
            data.TotalFileSize  = data.RemainingFileSize = 59.3;
            data.TimeRemaining  = new TimeSpan(0, 15, 45);
            return(data);
        }