Example #1
0
        /// <summary>
        /// Starts a corruption session
        /// </summary>
        private void Go()
        {
            if (!Running)
            {
                Trace.WriteLine("Go()");
                // First time through, setup the Queue. Note that there should ALWAYS be
                // at least one element in _settings.list.
                if (_queue == null || _queue.Count == 0)
                {
                    Trace.WriteLine("Creating _queue");
                    _queue = new Queue <TextImagePair>();
                    foreach (TextImagePair p in _settings.list)
                    {
                        Trace.WriteLine(String.Format("  Enqueue {0}, {1}", p.ImageFile, p.TextFile));
                        _queue.Enqueue(p);
                    }
                }

                TextImagePair pair = _queue.Dequeue();
                Trace.WriteLine(String.Format("Dequeued pair: {0}, {1}", pair.ImageFile, pair.TextFile));
                try
                {
                    Running = true;

                    // Read the files
                    CurrentTextFile  = pair.TextFile;
                    CurrentImageFile = pair.ImageFile;

                    FileCorruptBackgroundWorker.RunWorkerAsync();
                }
                catch (FileNotFoundException ex)
                {
                    Trace.WriteLine(ex.ToString());
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                Trace.WriteLine("Go called while already running. Doing nothing.");
            }
        }
Example #2
0
        /// <summary>
        /// Worker method for the background worker.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FileCorruptBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Trace.WriteLine("FileCorruptBackgroundWorker_DoWork()");
            FileCorruptBackgroundWorkerUserState UserState = new FileCorruptBackgroundWorkerUserState();

            int n = 1;

            foreach (string word in _wordList)
            {
                if (FileCorruptBackgroundWorker.CancellationPending)
                {
                    Trace.WriteLine("FileCorruptBackgroundWorker.CancellationPending");
                    return;
                }

                //Trace.WriteLine("_corruptionMode: " + _corruptionMode.ToString());
                switch (_corruptionMode)
                {
                case CorruptionMode.Random:
                    // This will block if needed
                    CorruptImageBytesRandom(_bytes, word);
                    break;

                case CorruptionMode.Sequential:
                    // This will block if needed
                    CorruptImageBytesSequential(_bytes, word);
                    break;
                }

                // Render to a bitmap for fast blitting
                //Trace.WriteLine("Render to bitmap...");
                UserState.Bitmap = PaintBitmap(_bytes);
                UserState.Word   = word;
                int percent = (int)((double)n * 100 / _wordList.Count);
                FileCorruptBackgroundWorker.ReportProgress(percent, UserState);

                n++;
            }
        }
Example #3
0
 /// <summary>
 /// Stop a corruption session
 /// </summary>
 private void Stop()
 {
     Trace.WriteLine("Stop()");
     StopPushed = true;
     FileCorruptBackgroundWorker.CancelAsync();
 }