Пример #1
0
        private void GoThread()
        {
            string path = null;
            bool?  duplicated = null, subFolders = null, numerals = null;

            txtPath.Dispatcher.Invoke(new Action(() => { path = txtPath.Text; }));
            txtPath.Dispatcher.Invoke(new Action(() => {
                duplicated = chkDuplicated.IsChecked;
                subFolders = chkSubfolders.IsChecked;
                numerals   = chkNumerals.IsChecked;
            }));

            StringBuilder sb = new StringBuilder();

            try
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                if (dir.Exists)
                {
                    _analyzer.FolderAnalyzed                 += analyzer_FolderAnalyzed;
                    _analyzer.FileRenamed                    += analyzer_FileRenamed;
                    _analyzer.DuplicatedFileRemoved          += analyzer_DuplicatedFileRemoved;
                    _analyzer.DeletingDuplicatedFilesStarted += analyzer_DeletingDuplicatedFilesStarted;
                    _analyzer.DeletingFolderStarted          += analyzer_DeletingFolderStarted;
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.Cursor          = Cursors.Wait;
                        lblStatus.Content    = "Organizing and cleaning folders...";
                        btnAnalyze.IsEnabled = false;
                        btnGo.IsEnabled      = false;
                    }));

                    AnalysisResult result2 = _analyzer.Execute(duplicated, subFolders, numerals);
                    sb.AppendLine("Analysis of folder \"" + dir.FullName + "\" has returned the following results after the execution:");
                    sb.AppendLine("Subfolders found: " + result2.FoldersAffected.ToString());
                    sb.AppendLine("Files found in folder and subfolders: " + result2.FilesAffected.ToString());
                    sb.AppendLine("Duplicated files in folder and subfolders: " + result2.DuplicatedFiles.Length.ToString());
                }
                else
                {
                    MessageBox.Show("The chosen folder does not exists.", "Pay attention...", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Pay attention...", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            Dispatcher.BeginInvoke(new Action(() =>
            {
                txbResult.Text       = sb.ToString();
                this.Cursor          = null;
                lblStatus.Content    = "Ready";
                progBar.Value        = 0.0d;
                btnAnalyze.IsEnabled = true;
                btnGo.IsEnabled      = true;
            }));
        }