Пример #1
0
        private void SortButton_OnClick(object sender, RoutedEventArgs e)
        {
            var canSort = true;

            if (canSort)
            {
                canSort = Path.IsPathRooted(sortPathTextBox.Text);
            }

            if (canSort)
            {
                try
                {
                    using (File.OpenWrite(sortPathTextBox.Text)){ }
                }
                catch
                {
                    canSort = false;
                }
            }

            if (canSort)
            {
                try
                {
                    canSort = int.Parse(bucketSizeTextBox.Text) > 0;
                }
                catch
                {
                    canSort = false;
                }
            }

            if (canSort == false)
            {
                MessageBox.Show("Can't sort file: " + "\"" + sortPathTextBox.Text + "\""
                                , "Error"
                                , MessageBoxButton.OK
                                , MessageBoxImage.Error
                                , MessageBoxResult.OK
                                , MessageBoxOptions.None
                                );
            }
            else
            {
                var bucketSize = long.Parse(bucketSizeTextBox.Text);

                FileSorter sorter = new MergeSorter(bucketSize);
                var        start  = DateTime.Now;
                sorter.sort(sortPathTextBox.Text);
                showDone(DateTime.Now - start);
            }
        }