public void Execute(object parameter) { object[] parameters = (object[])parameter; MainWindowViewModel mainViewModel = (MainWindowViewModel)parameters[0]; int type = (int)parameters[1]; string filePath = (type < 2) ? myFilePathProvider.GetOpenFilePath() : myFilePathProvider.GetSaveFilePath(); if (!String.IsNullOrWhiteSpace(filePath)) { switch (type) { case 0: mainViewModel.DailyReportFilePath = filePath; break; case 1: mainViewModel.UnallocatedCashReportFilePath = filePath; break; case 2: mainViewModel.OutputFilePath = filePath; break; default: throw new NotSupportedException(); } } }
public void Execute(object parameter) { var parameters = (object[])parameter; string filePath = myFilePathProvider.GetSaveFilePath(); if (!String.IsNullOrWhiteSpace(filePath)) { using (FileStream fileStream = File.Open(filePath, FileMode.Create)) { using (StreamWriter writer = new StreamWriter(fileStream, Encoding.Unicode)) { foreach (string countryName in myFacade.CustomerDatabase.Select(_ => _.Country.Name).Distinct()) { writer.WriteLine("[{0}]", countryName); foreach (Customer customer in myFacade.CustomerDatabase.Where(_ => _.Country.Name == countryName)) { writer.WriteLine("Name={0}\nId={1}", customer.Name, string.Join(",", customer.Identifiers)); } writer.WriteLine(); } } } } }
private bool SaveAs() { var filePath = _filePathProvider.GetSaveFilePath(); if (string.IsNullOrEmpty(filePath)) { return(false); } try { Write(filePath); _notepad.OpenFilePath = filePath; FixContents(); return(true); } catch (DirectoryNotFoundException) { _displayDialogService.ShowError("指定されたディレクトリが存在しません。"); } catch (PathTooLongException) { _displayDialogService.ShowError("指定されたファイルパスが長すぎます。"); } catch (UnauthorizedAccessException) { _displayDialogService.ShowError("指定されたファイルへのアクセスが許可されておりません。"); } catch (IOException) { _displayDialogService.ShowError("指定されたファイルに書き込むことができません。"); } return(false); }