예제 #1
0
        public static string SerializeUris(IEnumerable <Uri> uris, string key, VCardVersion version)
        {
            var builder = new StringBuilder();

            if (uris == null)
            {
                return(string.Empty);
            }

            int preference = 0;

            foreach (var uri in uris)
            {
                if (uri == null)
                {
                    continue;
                }

                preference++;

                string memberKey = key;

                memberKey = memberKey + ";PREF=" + preference;

                builder.Append(DefaultSerializer.GetVCardString(memberKey, uri.ToString(), false, version));
            }

            return(builder.ToString());
        }
예제 #2
0
        private static string Serialize(Address address, VCardVersion version)
        {
            string type = address.Type.ToVCardString();

            string key = "ADR";

            if (version == VCardVersion.V4)
            {
                if (address.Longitude != null && address.Latitude != null)
                {
                    key = key + ";GEO=\"" + address.Longitude.Value.ToString("N4") + "," + address.Latitude.Value.ToString("N4") + "\"";
                }

                if (address.Preference > 0)
                {
                    key = key + ";PREF=" + address.Preference;
                }

                if (!string.IsNullOrWhiteSpace(address.Label))
                {
                    key = key + ";LABEL=\"" + address.Label.Escape() + "\"";
                }

                if (address.TimeZone != null)
                {
                    key = key + ";TZ=\"" + TimeZoneInfoProcessor.ToVCardValue(address.TimeZone) + "\"";
                }
            }

            return(GroupProcessor.Serialize(key, version, type, true, address.PoBox, address.ExtendedAddress, address.Street, address.Locality, address.Region, address.PostalCode, address.Country));
        }
예제 #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 string Serialize(string key, VCardVersion version, string type, bool mustEscape = false, params string[] members)
        {
            if (members == null || members.Count() == 0)
            {
                return(string.Empty);
            }

            string value = string.Join(";", members.Select(x => mustEscape ? x.Escape() : x));

            return(DefaultSerializer.GetVCardString(key, value, false, version, type));
        }
예제 #5
0
        public static string ToVCardString(this TelephoneType type, VCardVersion version)
        {
            string result = Lookup[type];

            if (result == "PCS" && version == VCardVersion.V2_1)
            {
                return(string.Empty);
                //throw new VCardSerializationException("The personal communication services telephone number type is not supported by vCard 2.1!");
            }

            return(result);
        }
예제 #6
0
    /// <summary>
    /// Schreibt den Inhalt eines <see cref="Contact"/>-Objekts in eine vCard-Datei.
    /// </summary>
    /// <param name="contact">Das zu serialisierende <see cref="Contact"/>-Objekt. Wenn <paramref name="contact"/>&#160;<c>null</c> ist
    /// oder keine 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="contact"/> 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>
    internal static void Write(Contact contact, string fileName, VCardVersion version)
    {
        if (contact is null)
        {
            throw new ArgumentNullException(nameof(contact));
        }

        if (fileName is null)
        {
            throw new ArgumentNullException(nameof(fileName));
        }

        ToVCard(contact)?.SaveVcf(fileName, (VC::Enums.VCdVersion)version);
    }
예제 #7
0
 public static string GetVCardString(string key, string value, bool mustEscape, VCardVersion version, string type = "", string encoding = "")
 {
     string[] types = { type };
     return(GetVCardString(key, value, mustEscape, version, types, encoding));
 }
예제 #8
0
        public static string GetVCardString(string key, string value, bool mustEscape, VCardVersion version, string[] types, string encoding = "")
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(string.Empty);
            }

            if (mustEscape)
            {
                value = value.Escape();
            }

            //Legal values for v3
            //"TYPE=dom;TYPE=postal"
            //or
            //"TYPE=dom,postal"
            string type = "TYPE=" + string.Join(",", types);

            if (version == VCardVersion.V2_1)
            {
                type = string.Join(";", types);
            }

            string line = key;


            if (types.Any(x => !string.IsNullOrWhiteSpace(x)))
            {
                line = line + ";" + type;
            }

            if (!string.IsNullOrWhiteSpace(encoding))
            {
                line = line + $";ENCODING={encoding}";
            }

            line = line + ":" + value + Environment.NewLine;
            return(line);
        }
예제 #9
0
#pragma warning disable CS1591 // Fehlender XML-Kommentar für öffentlich sichtbaren Typ oder Element
    public static void SaveVCard(this Contact contact, string fileName, VCardVersion version = VCardVersion.V3_0)
#pragma warning restore CS1591 // Fehlender XML-Kommentar für öffentlich sichtbaren Typ oder Element
    => SaveVcf(contact, fileName, version);
예제 #10
0
 /// <summary>
 /// Speichert den Inhalt eines <see cref="Contact"/>-Objekts als vCard-Datei (.vcf).
 /// </summary>
 /// <param name="contact">Das zu speichernde <see cref="Contact"/>-Objekt. Wenn <paramref name="contact"/> 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>
 /// <para>
 /// Die Methode ruft auf <paramref name="contact"/>&#160;<see cref="Contact.Clean"/> auf. Wenn
 /// die Eigenschaft <see cref="Contact.IsEmpty"/> von <paramref name="contact"/> danach <c>true</c> zurückgibt, wird eine keine Datei erzeugt.
 /// Falls es unerwünscht ist, dass die Methode <paramref name="contact"/> durch den Aufruf von <see cref="Contact.Clean"/> ändert,
 /// können Sie vorher mit <see cref="Contact.Clone"/> eine
 /// Kopie von <paramref name="contact"/> erstellen und der Methode dann die Kopie übergeben.
 /// </para>
 /// <para>Zum Speichern mehrerer <see cref="Contact"/>-Objekte in einer gemeinsamen VCF-Datei eignet sich die
 /// Methode <see cref="ContactPersistence.SaveVcf(string, IEnumerable{Contact?}, VCardVersion)"/> oder die
 /// Erweiterungsmethode <see cref="ContactCollectionExtension.SaveVcf(IEnumerable{Contact?}, string, VCardVersion)"/>.
 /// </para>
 /// </remarks>
 ///
 /// <exception cref="ArgumentNullException"><paramref name="contact"/> 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 Contact contact, string fileName, VCardVersion version = VCardVersion.V3_0)
 => VcfWriter.Write(contact, fileName, version);
예제 #11
0
        public static string SerializeBase64String(string value, string key, string type, VCardVersion version)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(string.Empty);
            }

            /***************************************************************
             *  V2.1
             *
             *  PHOTO;VALUE=URL:file:///jqpublic.gif
             *
             *  OR
             *
             *  PHOTO;ENCODING=BASE64;TYPE=GIF:
             *      R0lGODdhfgA4AOYAAAAAAK+vr62trVIxa6WlpZ+fnzEpCEpzlAha/0Kc74+PjyGM
             *      SuecKRhrtX9/fzExORBSjCEYCGtra2NjYyF7nDGE50JrhAg51qWtOTl7vee1MWu1
             *      50o5e3PO/3sxcwAx/4R7GBgQOcDAwFoAQt61hJyMGHuUSpRKIf8A/wAY54yMjHtz
             *  ...
             *
             **************************************************************/


            string encoding = "BASE64";

            if (version == VCardVersion.V3)
            {
                /***************************************************************
                 *  Looks like this in V3.0
                 *
                 *  PHOTO;VALUE=uri:http://www.abc.com/pub/photos
                 *   /jqpublic.gif
                 *
                 *  OR
                 *
                 *  PHOTO;ENCODING=b;TYPE=JPEG:MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhvcN
                 *   AQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bm
                 *   ljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0
                 *   <...remainder of "B" encoded binary data...>
                 **************************************************************/

                encoding = "b";
            }
            else if (version == VCardVersion.V4)
            {
                /***************************************************************
                 *  Looks like this in V4.0
                 *  PHOTO:data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhv
                 *  AQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bm
                 *  ljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0
                 *  <...remainder of base64-encoded data...>
                 **************************************************************/
                encoding = string.Empty;
                value    = "data:" + type + ";base64," + value;
            }

            return(DefaultSerializer.GetVCardString(key, value, false, version, type, encoding));
        }
예제 #12
0
        public static string Serialize(DateTime?value, string key, VCardVersion version)
        {
            string serializedValue = value?.ToString("o") ?? string.Empty;

            return(string.IsNullOrWhiteSpace(serializedValue) ? string.Empty : DefaultSerializer.GetVCardString(key, serializedValue, false, version));
        }
예제 #13
0
 /// <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"/>&#160;<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);
예제 #14
0
 public static string ToVCardString(this VCardVersion addressType)
 {
     return(Lookup[addressType]);
 }
예제 #15
0
 /// <summary>
 /// Speichert den Inhalt einer Sammlung von <see cref="Contact"/>-Objekten in eine gemeinsame
 /// vCard-Datei (*.vcf).
 /// </summary>
 ///
 /// <param name="fileName">Der Dateipfad der zu erzeugenden VCF-Datei.
 /// Existiert die Datei schon, wird sie überschrieben.</param>
 /// <param name="contacts">
 /// <para>
 /// Die zu speichernde Sammlung von <see cref="Contact"/>-Objekten.
 /// </para>
 /// <para>
 /// Die Sammlung darf leer sein oder <c>null</c>-Werte
 /// enthalten. Wenn die Sammlung kein <see cref="Contact"/>-Objekt enthält, das Daten enthält, wird keine Datei erzeugt.
 /// </para>
 /// </param>
 /// <param name="version">Dateiversion der zu speichernden vCard.</param>
 ///
 /// <remarks>
 /// <para>
 /// Die Methode ruft auf allen als Argument übergebenen <see cref="Contact"/>-Objekten <see cref="Contact.Clean"/> auf. Alle
 /// <see cref="Contact"/>-Objekte deren Eigenschaft <see cref="Contact.IsEmpty"/> danach <c>true</c> zurückgibt, werden nicht in
 /// die Datei geschrieben.
 /// </para>
 /// <para>
 /// Falls es unerwünscht ist, dass die Methode die <see cref="Contact"/>-Objekte durch den Aufruf von <see cref="Contact.Clean"/> ändert,
 /// können Sie vorher mit <see cref="Contact.Clone"/>
 /// Kopien der <see cref="Contact"/>-Objekte erstellen und der Methode dann die Kopien übergeben.
 /// </para>
 /// </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(string fileName, IEnumerable <Contact?> contacts, VCardVersion version = VCardVersion.V3_0)
 => VcfWriter.Write(contacts, fileName, version);
예제 #16
0
#pragma warning disable CS1591 // Fehlender XML-Kommentar für öffentlich sichtbaren Typ oder Element
    public static void SaveVCard(string fileName, IEnumerable <Contact?> contacts, VCardVersion version = VCardVersion.V3_0)
#pragma warning restore CS1591 // Fehlender XML-Kommentar für öffentlich sichtbaren Typ oder Element
    => SaveVcf(fileName, contacts, version);