Example #1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            AnalysisHelper a = new AnalysisHelper();

            a.Analyze(textBoxSource, textBoxDestination);
            var           backgroundWorker  = sender as BackgroundWorker;
            int           dircount          = 0;
            int           filecount         = 0;
            List <string> sourceDirectories = DirectorySearch(textBoxSource.Text);
            List <string> sourceFiles       = FileSearch(textBoxSource.Text);

            backgroundWorker.ReportProgress(0, ", Creating directories");
            foreach (string s in sourceDirectories)
            {
                if (!Directory.Exists(textBoxDestination.Text + s.Replace(textBoxSource.Text, "")))
                {
                    dircount++;
                    Directory.CreateDirectory(textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                    //listBoxOutput.Items.Add("Created directory " + textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                    Debug.WriteLine("Created directory " + textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                    backgroundWorker.ReportProgress(((dircount + filecount) * 100) / (a.TotalActions() + 1), ", Created directory " + textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                }
            }

            backgroundWorker.ReportProgress(((dircount + filecount) * 100) / (a.TotalActions() + 1), ", Creating files");
            foreach (string s in sourceFiles)
            {
                if (!File.Exists(textBoxDestination.Text + s.Replace(textBoxSource.Text, "")))
                {
                    filecount++;
                    File.Copy(s, textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                    Debug.WriteLine("Copied file " + textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                    //listBoxOutput.Items.Add("Copied file " + textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                    backgroundWorker.ReportProgress(((dircount + filecount) * 100) / (a.TotalActions() + 1), ", Copied file " + textBoxDestination.Text + s.Replace(textBoxSource.Text, ""));
                }
            }
            //listBoxOutput.Items.Add(dircount + " directories created. " + filecount + " files created.");
            backgroundWorker.ReportProgress(100, dircount + ", directories created, " + filecount + " files created.");



            /*
             * var backgroundWorker = sender as BackgroundWorker;
             * for (int j = 0; j < 100; j++)
             * {
             *  Calculate(j);
             *  backgroundWorker.ReportProgress((j * 100) / 100000, "porkchop");
             * }
             */
        }
Example #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            AnalysisHelper a = new AnalysisHelper();

            a.Analyze(listBoxOutput, textBoxSource, textBoxDestination);
        }