private async void UploadCSVFile(object sender, RoutedEventArgs e) { Button uploadFileBtn = sender as Button; uploadFileBtn.IsEnabled = false; try { Process.SetInitialStatus("Открытие файла"); CSVService.UpdateFilePath(filePathTextBox.Text); IFileService <TunnelExit> csvService = CSVService.CSVServiceObject; Process.UpdateStatus("Чтение данных"); var tunnelsList = await csvService.ReadAsync(); Process.UpdateStatus("Отображение данных"); await Task.Run(() => MainPageModel.PageModel.CreateNewTunnelData(tunnelsList)); await MainPageModel.UploadDelegate(); int damagedRecNum = MainPageModel.PageModel.NumberOfDamagedRecords; Process.SetFinalStatus($"Файл загружен\n" + ((damagedRecNum == 0) ? string.Empty : $"Кол-во повреждений: {damagedRecNum}"), true); } catch (Exception ex) { Process.SetFinalStatus("Файл не загружен", false); ExceptionHandler.Handler.HandleExceptionWithMessageBox(ex, "Ошибка при загрузке файла"); } finally { uploadFileBtn.IsEnabled = true; } }
/// <summary> /// Saves the changes in CSV file in a mode which was selected by user /// (Rewrite, append w/o header string, append w header string) /// </summary> private async void SaveFile(object sender, EventArgs e) { string filePath = filePathTextBox.Text; try { Close(); Process.SetInitialStatus("Открываем файл"); CSVService.UpdateFilePath(filePathTextBox.Text); IFileService <TunnelExit> csvService = CSVService.CSVServiceObject; Process.UpdateStatus("Записываем в файл"); if (rewriteFileRadioBtn.IsChecked == true) { await csvService.RewriteAsync(TunnelExits); } else { await csvService.AppendAsync(TunnelExits, false); } Process.SetFinalStatus("Файл перезаписан", true); } catch (UnauthorizedAccessException ex) { HandleSaveFileException(ex); } catch (IOException ex) { HandleSaveFileException(ex); } catch (Exception ex) { HandleSaveFileException(ex); } }