Пример #1
0
    public static void ReadingAndWritingVCard(string directoryPath)
    {
        string v2FilePath = Path.Combine(directoryPath, v2FileName);
        string v3FilePath = Path.Combine(directoryPath, v3FileName);
        string v4FilePath = Path.Combine(directoryPath, v4FileName);

        VCard vcard = InitializeTheVCardAndFillItWithData(directoryPath, photoFileName);

        // Implements ITimeZoneIDConverter to convert IANA time zone names to UTC-Offsets.
        // (See the implementation in the example below.)
        VC::ITimeZoneIDConverter tzConverter = new TimeZoneIDConverter();

        // Save vcard as vCard 2.1:
        vcard.SaveVcf(v2FilePath, VC::Enums.VCdVersion.V2_1, tzConverter);

        // Save vcard as vCard 3.0:
        // You don't need to specify the version: Version 3.0 is the default.
        vcard.SaveVcf(v3FilePath, tzConverter: tzConverter);

        // Save vcard as vCard 4.0. (A time zone converter is not needed):
        vcard.SaveVcf(v4FilePath, VC::Enums.VCdVersion.V4_0);

        // Load vCard:
        vcard = VCard.LoadVcf(v3FilePath)[0];

        WriteResultsToConsole(vcard);
Пример #2
0
    public void ParseOutlook()
    {
        IList <VCard> vcard = VCard.LoadVcf(fileName: TestFiles.OutlookV2vcf);

        Assert.IsNotNull(vcard);
        Assert.IsNotNull(vcard.FirstOrDefault());

        //string s = vcard[0].ToString();

        DataProperty?photo = vcard[0].Photos?.FirstOrDefault();

        Assert.IsNotNull(photo);

        if (photo?.Value is DataUrl dataUrl)
        {
            Assert.AreEqual(dataUrl.MimeType.MediaType, "image/jpeg");
            //System.IO.File.WriteAllBytes(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), $"Testbild{dataUrl.GetFileExtension()}"), dataUrl.GetEmbeddedBytes());
        }
        else
        {
            Assert.Fail();
        }

        VCard.SaveVcf(System.IO.Path.Combine(
                          Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), $"TestV2.1.vcf"),
                      vcard !, VCdVersion.V2_1, options: VcfOptions.Default.Set(VcfOptions.WriteNonStandardProperties));
    }
Пример #3
0
    /// <summary>
    /// Schreibt den Inhalt einer Auflistung  von <see cref="Contact"/>-Objekten in eine gemeinsame
    /// vCard-Datei.
    /// </summary>
    /// <param name="contacts">Auflistung der in eine gemeinsame vCard-Datei zu schreibenden <see cref="Contact"/>-Objekte.
    /// Die Auflistung darf leer sein oder <c>null</c>-Werte
    /// enthalten. Wenn die Auflistung kein <see cref="Contact"/>-Objekt enthält, das Daten enthält, wird keine Datei geschrieben.</param>
    /// <param name="fileName">Der vollständige Pfad der zu erzeugenden vCard-Datei.
    /// Existiert die Datei schon, wird sie überschrieben.</param>
    /// <param name="version">Dateiversion der zu speichernden vCard. (optional)</param>
    /// <exception cref="ArgumentNullException"><paramref name="contacts"/> oder <paramref name="fileName"/> ist <c>null</c>.</exception>
    /// <exception cref="ArgumentException"><paramref name="fileName"/> ist kein gültiger Dateipfad.</exception>
    /// <exception cref="IOException">Die Datei konnte nicht geschrieben werden.</exception>
    /// <remarks><paramref name="contacts"/> darf nicht null sein, aber null-Werte enthalten.</remarks>
    internal static void Write(IEnumerable <Contact?> contacts, string fileName, VCardVersion version)
    {
        if (contacts is null)
        {
            throw new ArgumentNullException(nameof(contacts));
        }

        VCard.SaveVcf(fileName, contacts.Select(x => ToVCard(x)), (VC::Enums.VCdVersion)version);
    }
Пример #4
0
 public static void SaveVcf(
     this IEnumerable <VCard?> vCards,
     string fileName,
     VCdVersion version = VCard.DEFAULT_VERSION,
     VcfOptions options = VcfOptions.Default)
 => VCard.SaveVcf(fileName, vCards, version, options: options);
Пример #5
0
 public void SaveVcf(
     string fileName,
     VCdVersion version = DEFAULT_VERSION,
     ITimeZoneIDConverter?tzConverter = null,
     VcfOptions options = VcfOptions.Default) => VCard.SaveVcf(fileName, this, version, tzConverter, options);