public static void ReadingAndWritingVCard() { // Initialize data (see code-example above): Contact[] contactArr = ContactExample.InitializeContacts(); const string fileName = "FamilyDoe.vcf"; // Save all contacts to a common VCF file: contactArr.SaveVcf(fileName); // Display the content of the VCF file: Console.WriteLine("Saved VCF:"); Console.WriteLine(); Console.WriteLine(File.ReadAllText(fileName)); // Reload the VCF file: List <Contact> contactList = ContactPersistence.LoadVcf(fileName); // Display the content of the reloaded Contact objects: Console.WriteLine(); Console.WriteLine("Reloaded Contact objects:"); for (int i = 0; i < contactList.Count; i++) { Console.WriteLine(); Console.WriteLine($"Contact {i + 1}:"); Console.WriteLine(contactArr[i]); Console.WriteLine(); } }
public void LoadVCardTest2() { List <Contact> conts = ContactPersistence.LoadVcf(TestFiles.V4vcf); Assert.IsNotNull(conts); Assert.AreEqual(2, conts.Count); }
public static void ReadingAndWritingCsv() { // Initialize data (see code-example above): Contact[] contactArr = ContactExample.InitializeContacts(); const string fileName = "FamilyDoe.csv"; // Save the Contacts: contactArr.SaveCsv(fileName, CsvCompatibility.Thunderbird); // Display the content of the CSV file: Console.WriteLine("Saved CSV:"); Console.WriteLine(); Console.WriteLine(File.ReadAllText(fileName)); // Reload the CSV file: List <Contact> contactList = ContactPersistence.LoadCsv(fileName, CsvCompatibility.Thunderbird); // Display the content of the reloaded Contact objects: Console.WriteLine(); Console.WriteLine("Reloaded Contact objects:"); for (int i = 0; i < contactList.Count; i++) { Console.WriteLine(); Console.WriteLine($"Contact {i + 1}:"); Console.WriteLine(contactArr[i]); Console.WriteLine(); } }
public void LoadCsvTest_Thunderbird3() { List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.ThunderbirdUtf8EnglishColumnsInvalidBDayCsv, CsvCompatibility.Thunderbird); Assert.IsNotNull(conts); Assert.AreEqual(1, conts.Count); CollectionAssert.DoesNotContain(conts, null); }
public void LoadCsvTest_Thunderbird2() { List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.ThunderbirdUtf8UnknownAndLessColumnNamesCsv, CsvCompatibility.Thunderbird); Assert.IsNotNull(conts); Assert.AreEqual(1, conts.Count); CollectionAssert.DoesNotContain(conts, null); }
public void LoadCsvTest_Google() { List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.GoogleCsv, CsvCompatibility.Google); Assert.IsNotNull(conts); Assert.AreEqual(1, conts.Count); CollectionAssert.DoesNotContain(conts, null); }
public void SaveTest_Outlook2() { string fileName = Path.Combine(TestContext.TestRunResultsDirectory, "Outlook2.csv"); List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.Outlook365Csv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture); conts.SaveCsv(fileName, CsvCompatibility.Outlook); }
public void SaveCsvTest() { List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.GoogleCsv, CsvCompatibility.Google); conts.Insert(0, null !); string fileName = Path.Combine(TestContext.TestRunResultsDirectory, "Google_CollectionExtension1.csv"); conts.SaveCsv(fileName, CsvCompatibility.Google); }
public void SaveVCardTest() { List <Contact> conts = ContactPersistence.LoadVcf(TestFiles.V3vcf); conts.Insert(0, null !); string fileName = Path.Combine(TestContext.TestRunResultsDirectory, "CollectionExtension1.vcf"); conts.SaveVcf(fileName); }
public void LoadCsvTest_Outlook_DifferentColumnNames() { List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.Outlook365DifferentColumnNamesCsv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture); Assert.IsNotNull(conts); Assert.AreEqual(6, conts.Count); CollectionAssert.DoesNotContain(conts, null); Assert.IsNotNull(conts[0].Person); Assert.AreEqual(new DateTime(1981, 1, 20), conts[0]?.Person?.BirthDay); Assert.AreEqual(new DateTime(2005, 6, 3), conts[0]?.Person?.Anniversary); }
public void LoadCsvTest_Outlook_DifferentColumnNamesLessColumns() { List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.Outlook365DifferentColumnNamesLessColumnsCsv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture); Assert.IsNotNull(conts); Assert.AreEqual(6, conts.Count); CollectionAssert.DoesNotContain(conts, null); Assert.IsNotNull(conts[5].Person); Assert.AreEqual("Mustermann", conts[5].Person?.Name?.LastName); }
public void LoadCsvTest_Unspecified() { var sw = new Stopwatch(); sw.Start(); List <Contact> conts = ContactPersistence.LoadCsv(TestFiles.WindowsLiveMail, CsvCompatibility.Unspecified); sw.Stop(); TestContext.WriteLine($"Stopwatch: {sw.ElapsedMilliseconds}"); Assert.IsNotNull(conts); Assert.AreEqual(1, conts.Count); CollectionAssert.DoesNotContain(conts, null); }
/// <summary> /// Speichert den Inhalt einer Sammlung von <see cref="Contact"/>-Objekten als gemeinsame vCard-Datei (.vcf). /// </summary> /// <param name="contacts">Die zu speichernde Sammlung von <see cref="Contact"/>-Objekten. /// Wenn <paramref name="contacts"/> keine Daten enthält, wird keine Datei erzeugt.</param> /// <param name="fileName">Der Dateipfad der zu erzeugenden VCF-Datei. /// Existiert die Datei schon, wird sie überschrieben.</param> /// <param name="version">Dateiversion der zu speichernden VCF-Datei.</param> /// /// <remarks> /// Die Methode ruft auf jedem <see cref="Contact"/>-Objekt in <paramref name="contacts"/> <see cref="Contact.Clean"/> auf. /// </remarks> /// /// <exception cref="ArgumentNullException"><paramref name="contacts"/> oder <paramref name="fileName"/> ist <c>null</c>.</exception> /// <exception cref="ArgumentException"> /// <para><paramref name="fileName"/> ist kein gültiger Dateipfad.</para> /// <para>- oder -</para> /// <para><paramref name="version"/> hat einen nichtdefinierten Wert.</para> /// </exception> /// <exception cref="IOException">Die Datei konnte nicht geschrieben werden.</exception> public static void SaveVcf(this IEnumerable <Contact?> contacts, string fileName, VCardVersion version = VCardVersion.V3_0) => ContactPersistence.SaveVcf(fileName, contacts, version);
/// <summary> /// Speichert den Inhalt einer Sammlung von <see cref="Contact"/>-Objekten als CSV-Datei. /// </summary> /// /// <param name="contacts">Die zu speichernde Sammlung von <see cref="Contact"/>-Objekten.</param> /// <param name="fileName">Der Dateipfad der zu erzeugenden CSV-Datei. Existiert die Datei schon, wird sie überschrieben.</param> /// <param name="platform">Die Plattform, für die die CSV-Datei bestimmt ist.</param> /// <param name="formatProvider">Ein Objekt, das kulturabhängige Formatierungsinformationen bereitstellt, oder <c>null</c>, um automatisch /// die am besten geeignete <see cref="CultureInfo"/> aussuchen zu lassen.</param> /// <param name="textEncoding">Die zu verwendende Textkodierung oder <c>null</c> für UTF-8 mit BOM (<see cref="Encoding.UTF8"/>).</param> /// /// <remarks> /// Die Methode ruft auf jedem <see cref="Contact"/>-Objekt in <paramref name="contacts"/> <see cref="Contact.Clean"/> auf. /// </remarks> /// /// <exception cref = "ArgumentNullException"><paramref name="contacts"/> oder <paramref name="fileName"/> ist <c>null</c>.</exception> /// <exception cref="ArgumentException"> /// <para><paramref name="fileName"/> ist kein gültiger Dateipfad.</para> /// <para>- oder -</para> /// <para><paramref name="platform"/> hat einen nichtdefinierten Wert.</para> /// </exception> /// <exception cref="IOException">E/A-Fehler.</exception> public static void SaveCsv(this IEnumerable <Contact?> contacts, string fileName, CsvCompatibility platform, IFormatProvider?formatProvider = null, Encoding?textEncoding = null) => ContactPersistence.SaveCsv(fileName, contacts, platform, formatProvider, textEncoding);
public void LoadCsvTest2() { List <Contact> res = ContactPersistence.LoadCsv(TestFiles.NoHeaderCsv, CsvCompatibility.Outlook, CultureInfo.InvariantCulture); Assert.AreEqual(0, res.Count); }
public void LoadCsvTest1() { _ = ContactPersistence.LoadCsv(TestFiles.Outlook365Csv, (CsvCompatibility)4711, CultureInfo.InvariantCulture); }