Beispiel #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());
        }
Beispiel #2
0
        public static string Serialize(VCard vcard)
        {
            //The property "CATEGORIES" is valid only for VCardVersion 3.0 and above.
            if (vcard.Version == VCardVersion.V2_1)
            {
                return(string.Empty);
            }

            if (vcard.Categories == null || !vcard.Categories.Any())
            {
                return(string.Empty);
            }

            string categories = string.Empty;

            if (vcard.Categories != null && vcard.Categories.Any())
            {
                categories = string.Join(",", vcard.Categories.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Escape()));
            }

            if (string.IsNullOrWhiteSpace(categories))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("CATEGORIES", categories, false, vcard.Version));
        }
Beispiel #3
0
        public static string Serialize(VCard vcard)
        {
            //Only vCard 4.0 supports RELATED property
            if (vcard.Version != VCardVersion.V4)
            {
                return(string.Empty);
            }

            if (vcard.Relations == null || vcard.Relations.Count() == 0)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            foreach (var relation in vcard.Relations)
            {
                string key = "RELATED";

                key = key + ";TYPE=" + relation.Type.ToVCardString();

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

                builder.Append(DefaultSerializer.GetVCardString(key, relation.RelationUri.ToString(), false, vcard.Version));
            }

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

            var builder = new StringBuilder();

            foreach (var extension in vcard.CustomExtensions)
            {
                var key = extension.Key;
                foreach (var value in extension.Values)
                {
                    if (string.IsNullOrWhiteSpace(value))
                    {
                        continue;
                    }

                    var vcardString = DefaultSerializer.GetVCardString(key, value, true, vcard.Version);
                    builder.Append(vcardString);
                }
            }

            return(builder.ToString());
        }
Beispiel #5
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));
        }
Beispiel #6
0
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.Mailer))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("MAILER", vcard.Mailer, true, vcard.Version));
        }
Beispiel #7
0
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.UniqueIdentifier))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("UID", vcard.UniqueIdentifier, true, vcard.Version));
        }
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.Title))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("TITLE", vcard.Title, false, vcard.Version));
        }
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.Note))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("NOTE", vcard.Note, true, vcard.Version));
        }
Beispiel #10
0
        public static string Serialize(VCard vcard)
        {
            //Only vCard 4.0 supports KIND property
            if (vcard.Version != VCardVersion.V4)
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("KIND", vcard.Kind.ToVCardString(), true, vcard.Version));
        }
Beispiel #11
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));
        }
Beispiel #12
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.Url == null)
            {
                return(string.Empty);
            }

            string url = vcard.Url.ToString();

            return(DefaultSerializer.GetVCardString("URL", url, true, vcard.Version));
        }
Beispiel #13
0
        public static string Serialize(VCard vcard)
        {
            var timeZone = ToVCardValue(vcard.TimeZone);

            if (string.IsNullOrWhiteSpace(timeZone))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("TZ", timeZone, false, vcard.Version));
        }
Beispiel #14
0
        public static string Serialize(VCard vcard)
        {
            //The property "CLASS" is valid only for VCardVersion 3.0 and above.
            if (vcard.Version == VCardVersion.V2_1)
            {
                return(string.Empty);
            }

            string classification = ClassificationLookup.ToVCardString(vcard.Classification);

            return(DefaultSerializer.GetVCardString("CLASS", classification, true, vcard.Version));
        }
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.NickName))
            {
                return(string.Empty);
            }

            //The property "NICKNAME" is valid only for VCardVersion 3.0 and above.
            if (vcard.Version == VCardVersion.V2_1)
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("NICKNAME", vcard.NickName, false, vcard.Version));
        }
Beispiel #16
0
        public static string Serialize(VCard vcard)
        {
            //Please note that the property "SORT-STRING" only exists for VCardVersion 3.0
            //where VCardVersion 4.0 uses "SORT-AS" key in N property
            if (vcard.Version != VCardVersion.V3)
            {
                return(string.Empty);
            }

            if (string.IsNullOrWhiteSpace(vcard.SortString))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("SORT-STRING", vcard.SortString, true, vcard.Version));
        }
Beispiel #17
0
        public static string Serialize(VCard vcard)
        {
            //Only vCard 4.0 supports SOURCE property
            if (vcard.Version != VCardVersion.V4)
            {
                return(string.Empty);
            }

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

            string source = vcard.Source.ToString();

            return(DefaultSerializer.GetVCardString("SOURCE", source, false, vcard.Version));
        }
Beispiel #18
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.Languages == null || vcard.Languages.Count() == 0)
            {
                return(string.Empty);
            }

            //Only vCard 4.0 supports LANG property
            if (vcard.Version != VCardVersion.V4)
            {
                return(string.Empty);
            }


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

            var builder = new StringBuilder();

            foreach (var language in vcard.Languages)
            {
                if (string.IsNullOrWhiteSpace(language.Name))
                {
                    continue;
                }

                string key = "LANG";

                key = key + ";TYPE=" + language.Type.ToVCardString();

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

                builder.Append(DefaultSerializer.GetVCardString(key, language.Name, false, vcard.Version));
            }

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

            // Whatever, f**k you, they will ignore the info if they don't support it
            // //Only vCard 4.0 supports IMPP property
            // if (vcard.Version != VCardVersion.V4)
            // {
            //     return string.Empty;
            // }


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

            var builder = new StringBuilder();

            foreach (var impp in vcard.Impps)
            {
                if (impp.Address == null)
                {
                    continue;
                }

                string key = "IMPP";

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

                builder.Append(DefaultSerializer.GetVCardString(key, impp.Address.ToString(), false, vcard.Version));
            }

            return(builder.ToString());
        }
 public static string Serialize(VCard vcard)
 {
     return(DefaultSerializer.GetVCardString("FN", vcard.FormattedName, true, vcard.Version));
 }
Beispiel #21
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));
        }
Beispiel #22
0
 public static string Serialize(VCard vcard)
 {
     return(DefaultSerializer.GetVCardString("VERSION", vcard.Version.ToVCardString(), false, vcard.Version));
 }