예제 #1
0
        private async void buttonExport_ClickAsync(object sender, RoutedEventArgs e)
        {
            SetButtonsEnabled(false);
            var inputWindow = new InputWindow("Введите имя файла");
            var result      = inputWindow.ShowDialog();

            if (result == true)
            {
                var fileName = inputWindow.Text;
                try
                {
                    var progressWindow = new ProgressWindow(TextFilesHandler.GetLinesCount(fileName));
                    try
                    {
                        progressWindow.Show();
                        var currentSyncContext = SynchronizationContext.Current;
                        await Task.Run(() => TextFilesHandler.ExportFilesToDB(fileName, i => currentSyncContext.Send(o => progressWindow.Pass((int)o), i)));
                    }
                    finally
                    {
                        progressWindow.Close();
                    }


                    MessageBox.Show("Выполнено");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            SetButtonsEnabled(true);
        }
예제 #2
0
        private async void buttonUnite_ClickAsync(object sender, RoutedEventArgs e)
        {
            SetButtonsEnabled(false);
            var inputWindow = new InputWindow("Введите пропускаемую подстроку");
            var result      = inputWindow.ShowDialog();

            if (result == true)
            {
                var substr = inputWindow.Text;
                try
                {
                    int numOfSkippedLines;
                    var waitWindow = new WaitWindow();
                    try
                    {
                        waitWindow.Show();
                        numOfSkippedLines = await Task.Run(() => TextFilesHandler.UniteFiles(substr));
                    }
                    finally
                    {
                        waitWindow.Close();
                    }

                    MessageBox.Show($"Выполнено, {numOfSkippedLines} строк пропущено");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            SetButtonsEnabled(true);
        }