Beispiel #1
0
        public static string Serialize(VCard vcard)
        {
            if ((vcard.Version == VCardVersion.V2_1 && vcard.Version == VCardVersion.V3) || string.IsNullOrWhiteSpace(vcard.SortString))
            {
                return(GroupProcessor.Serialize("N", vcard.Version, string.Empty, true, vcard.LastName, vcard.FirstName, vcard.MiddleName, vcard.Prefix, vcard.Suffix));
            }

            /*****************************************************************
            *   RFC 6350 examples for V4.0:
            *   FN:Rene van der Harten
            *   N;SORT-AS="Harten,Rene":van der Harten;Rene,J.;Sir;R.D.O.N.
            *
            *   FN:Robert Pau Shou Chang
            *   N;SORT-AS="Pau Shou Chang,Robert":Shou Chang;Robert,Pau;;
            *
            *   FN:Osamu Koura
            *   N;SORT-AS="Koura,Osamu":Koura;Osamu;;
            *
            *   FN:Oscar del Pozo
            *   N;SORT-AS="Pozo,Oscar":del Pozo Triscon;Oscar;;
            *
            *   FN:Chistine d'Aboville
            *   N;SORT-AS="Aboville,Christine":d'Aboville;Christine;;
            *****************************************************************/

            string key = "N;SORT-AS=\"{sortAs}\"";

            key = key.Replace("{sortAs}", vcard.SortString);

            return(GroupProcessor.Serialize(key, vcard.Version, string.Empty, true, vcard.LastName, vcard.FirstName, vcard.MiddleName, vcard.Prefix, vcard.Suffix));
        }
Beispiel #2
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.Emails == null || vcard.Emails.Count() == 0)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            foreach (var email in vcard.Emails)
            {
                if (string.IsNullOrWhiteSpace(email.EmailAddress))
                {
                    continue;
                }

                string type = email.Type.ToVCardString();

                string key = "EMAIL";

                if (vcard.Version == VCardVersion.V4)
                {
                    if (email.Preference > 0)
                    {
                        key = key + ";PREF=" + email.Preference;
                    }
                }

                builder.Append(GroupProcessor.Serialize(key, vcard.Version, type, true, email.EmailAddress));
            }

            return(builder.ToString());
        }
        public static string Serialize(VCard vcard)
        {
            if (vcard.Telephones == null || vcard.Telephones.Count() == 0)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            foreach (var phone in vcard.Telephones)
            {
                if (string.IsNullOrWhiteSpace(phone.Number))
                {
                    continue;
                }

                string type = phone.Type.ToVCardString(vcard.Version);

                string key = "TEL";

                if (vcard.Version == VCardVersion.V4)
                {
                    if (phone.Preference > 0)
                    {
                        key = key + ";PREF=" + phone.Preference;
                    }
                }

                builder.Append(GroupProcessor.Serialize(key, vcard.Version, type, true, phone.Number));
            }

            return(builder.ToString());
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.Longitude == 0 && vcard.Latitude == 0)
            {
                return(string.Empty);
            }

            return(GroupProcessor.Serialize("GEO", vcard.Version, string.Empty, false, vcard.Longitude.ToString("N2"), vcard.Latitude.ToString("N2")));
        }
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace((vcard.Organization + vcard.OrganizationalUnit).Trim()))
            {
                return(string.Empty);
            }

            return(GroupProcessor.Serialize("ORG", vcard.Version, string.Empty, false, vcard.Organization, vcard.OrganizationalUnit));
        }
        public static string Serialize(VCard vcard)
        {
            if (vcard.DeliveryAddress == null)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            string type = vcard.DeliveryAddress.Type.ToVCardString();

            const string key = "LABEL";

            builder.Append(GroupProcessor.Serialize(key, vcard.Version, type, true, vcard.DeliveryAddress.Address.Escape()));

            return(builder.ToString());
        }