/// <summary> /// passing a stream to a class <see cref="FileCabinetRecordCsvWriter"/> and record. /// </summary> /// <param name="sw">stream.</param> public void SaveToCsv(StreamWriter sw) { this.csvWriter = new FileCabinetRecordCsvWriter(sw); foreach (var record in this.records) { this.csvWriter.Write(record); } }
/// <summary>Saves snapshot to CSV format.</summary> /// <param name="sr">The stream for a file.</param> public void SaveToCsv(StreamWriter sr) { FileCabinetRecordCsvWriter writer = new FileCabinetRecordCsvWriter(sr); for (int i = 0; i < this.records.Length; i++) { writer.Write(this.records[i]); } }
/// <summary> /// Method calls FileCabinet Record CsvWriter. Write and send there record. /// </summary> /// <param name="streamWriter">Opened.</param> public void SaveToCsv(StreamWriter streamWriter) { this.csvWriter = new FileCabinetRecordCsvWriter(streamWriter); foreach (var item in this.fileCabinetRecords) { this.csvWriter.Write(item); } }
/// <summary> /// Saves the records to csv file. /// </summary> /// <param name="writer">Csv writer.</param> /// <returns>Whether operation succeeded.</returns> public bool SaveToCsv(StreamWriter writer) { FileCabinetRecordCsvWriter csvWriter = new FileCabinetRecordCsvWriter(writer); foreach (var record in this.Records) { csvWriter.Write(record); } return(true); }
public void SaveToCsv(StreamWriter streamWriter) { var csvWriter = new FileCabinetRecordCsvWriter(streamWriter); csvWriter.WriteString("Id,First name,Last name,Date of birth,Age,Money,Letter"); foreach (var record in records) { csvWriter.Write(record); } }
/// <summary> /// Save records to .csv file. /// </summary> /// <param name="stream">Stream.</param> public void SaveToCsv(FileStream stream) { using (StreamWriter writer = new StreamWriter(stream)) { FileCabinetRecordCsvWriter fileCabinetRecordCsvWriter = new FileCabinetRecordCsvWriter(writer); for (int i = 0; i < this.records.Length; i++) { fileCabinetRecordCsvWriter.Write(this.records[i]); } } }
private void WriteAllRecordsCsv(StreamWriter textWriter, FileCabinetRecord[] records) { var csvWriter = new FileCabinetRecordCsvWriter(textWriter); string fieldsName = "Id,First Name,Last Name,Date of Birth,Cabinet Number,Salary,Category"; textWriter.WriteLine(fieldsName); foreach (var item in records) { csvWriter.Write(item); } }
/// <summary> /// Saves records to csv file. /// </summary> /// <param name="writer">Streamwriter to save records.</param> /// <exception cref="ArgumentNullException">Writer must be not null.</exception> public void SaveToCsv(StreamWriter writer) { if (writer is null) { throw new ArgumentNullException(nameof(writer), Configurator.GetConstantString("NullStream")); } using FileCabinetRecordCsvWriter csvWriter = new FileCabinetRecordCsvWriter(writer); foreach (var record in this.records) { csvWriter.Write(record); } }
/// <summary>Saves snapshot to csv file.</summary> /// <param name="writer">Writer.</param> /// <exception cref="ArgumentNullException">Thrown when writer is null.</exception> public void SaveToCsv(StreamWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } var csvWriter = new FileCabinetRecordCsvWriter(writer); writer.WriteLine("Id;First Name;Last Name;Date of Birth;Sex;Number of Reviews;Salary"); foreach (var record in this.records) { csvWriter.Write(record); } }
private void ExportTo(string format, string path) { var snapshot = this.Service.MakeSnapshot(); bool isCanceled = false; string message = string.Empty; if (File.Exists(path)) { Console.Write($"File is exist - rewrite {path} [Y/n] "); isCanceled = !DataHelper.YesOrNo(); } if (isCanceled) { Console.WriteLine("Export canceled by the user."); } FileStream filestream = default; try { filestream = File.Create(path); } catch (FileNotFoundException) { Console.WriteLine($"Export failed: can't open file {path}."); } catch (UnauthorizedAccessException ex) { Console.WriteLine(ex.Message); } catch (DirectoryNotFoundException ex) { Console.WriteLine(ex.Message); } if (filestream is null) { message = "Invalid path."; } else { using var stream = new StreamWriter(filestream); if (format.Equals(CsvString, StringComparison.InvariantCultureIgnoreCase)) { using var writer = new FileCabinetRecordCsvWriter(stream); snapshot.SaveTo(writer); message = $"All records export into CSV file {path}"; } if (format.Equals(XmlString, StringComparison.InvariantCultureIgnoreCase)) { using var writer = new FileCabinetRecordXmlWriter(stream); snapshot.SaveTo(writer); message = $"All record export into XML file {path}"; } } Console.WriteLine(message); }
/// <summary> /// Saves to the CSV file. /// </summary> /// <param name="writer">Stream to write.</param> public void SaveToCsv(StreamWriter writer) { var csvWriter = new FileCabinetRecordCsvWriter(writer); csvWriter.Write(this.records); }
/// <summary> /// Save snapshot to CSV file. /// </summary> /// <param name="writer"> Get writer.</param> public void SaveToCSV(FileCabinetRecordCsvWriter writer) { writer.Write(this.records); }
/// <summary> /// Метод записи в csv. /// </summary> /// <param name="streamWriter">StreamWriter.</param> public void SaveToCsv(StreamWriter streamWriter) { FileCabinetRecordCsvWriter fileCabinetRecordCsvWriter = new FileCabinetRecordCsvWriter(streamWriter); fileCabinetRecordCsvWriter.Write(this.records); }