示例#1
0
        public override void Parse()
        {
            if (this.addressbooks != null)
            {
                if (this.addressbooks.Cards != null)
                {
                    foreach (var vcardByte in this.addressbooks.Cards)
                    {
                        var vcard = VCard.Parse(Encoding.Default.GetString(vcardByte.CardData));
                        foreach (var item in vcard)
                        {
                            if (item.EmailAddresses == null || !item.EmailAddresses.Any())
                            {
                                continue;
                            }

                            var contact = new OCContact()
                            {
                                Emails = item.EmailAddresses.Select(v => v.Value).Distinct().ToList()
                            };

                            if (item.Addresses != null && item.Addresses.Any())
                            {
                                contact.Address = item.Addresses.First().Value.ToString();
                            }
                            if (item.DisplayNames != null && item.DisplayNames.Any())
                            {
                                contact.ContactName = item.DisplayNames.First().Value.ToString();
                            }
                            if (item.Notes != null && item.Notes.Any())
                            {
                                contact.Description = string.Join("\n", item.Notes.Select(v => v.Value));
                            }
                            if (item.PhoneNumbers != null && item.PhoneNumbers.Any())
                            {
                                contact.Phones = item.PhoneNumbers.Select(v => v.Value).Distinct().ToList();
                            }

                            contacts.Add(contact);
                        }
                    }
                }
            }
        }