/// <summary> /// Initializes a new instance of the <see cref="vCard"/> class. /// </summary> public vCard() { // Per Microsoft best practices, string properties should // never return null. String properties should always // return String.Empty. this.additionalNames = string.Empty; this.department = string.Empty; this.displayName = string.Empty; this.familyName = string.Empty; this.formattedName = string.Empty; this.givenName = string.Empty; this.mailer = string.Empty; this.namePrefix = string.Empty; this.nameSuffix = string.Empty; this.office = string.Empty; this.organization = string.Empty; this.productId = string.Empty; this.role = string.Empty; this.timeZone = string.Empty; this.title = string.Empty; this.uniqueId = string.Empty; this.categories = new List <string>(); this.certificates = new vCardCertificateCollection(); this.deliveryAddresses = new vCardDeliveryAddressCollection(); this.deliveryLabels = new vCardDeliveryLabelCollection(); this.emailAddresses = new vCardEmailAddressCollection(); this.nicknames = new List <string>(); this.notes = new vCardNoteCollection(); this.phones = new vCardPhoneCollection(); this.photos = new vCardPhotoCollection(); this.sources = new vCardSourceCollection(); this.websites = new vCardWebsiteCollection(); }
public static void Equals(vCardWebsiteCollection wc1, vCardWebsiteCollection wc2) { Assert.AreEqual( wc1.Count, wc2.Count, "The web site collections do not have the same count."); for (int index = 0; index < wc1.Count; index++) { Equals(wc1[index], wc2[index]); } }
/// <summary> /// Initializes a new instance of the <see cref="vCard"/> class. /// </summary> public vCard() { // Per Microsoft best practices, string properties should // never return null. String properties should always // return String.Empty. this.additionalNames = string.Empty; this.department = string.Empty; this.displayName = string.Empty; this.familyName = string.Empty; this.formattedName = string.Empty; this.givenName = string.Empty; this.mailer = string.Empty; this.namePrefix = string.Empty; this.nameSuffix = string.Empty; this.office = string.Empty; this.organization = string.Empty; this.productId = string.Empty; this.role = string.Empty; this.timeZone = string.Empty; this.title = string.Empty; this.uniqueId = string.Empty; this.categories = new StringCollection(); this.certificates = new vCardCertificateCollection(); this.deliveryAddresses = new vCardDeliveryAddressCollection(); this.deliveryLabels = new vCardDeliveryLabelCollection(); this.emailAddresses = new vCardEmailAddressCollection(); this.nicknames = new StringCollection(); this.notes = new vCardNoteCollection(); this.phones = new vCardPhoneCollection(); this.photos = new vCardPhotoCollection(); this.sources = new vCardSourceCollection(); this.websites = new vCardWebsiteCollection(); this.ims = new vCardIMPPCollection(); this.sps = new vCardSocialProfileCollection(); }
/// <summary> /// Parses a vCard contact /// </summary> /// <param name="vCard"></param> /// <returns></returns> private static Contact ParseVCard(vCard vCard) { Contact contact = new Contact(false); contact.ID = vCard.UniqueId; if (contact.ID == string.Empty) { contact.ID = IDGenerator.GenerateID(); } #region Name { Name name = Name.TryParse(vCard.FormattedName); if (name == null) { name = new Name(); } if (vCard.GivenName != string.Empty) { name.FirstName = vCard.GivenName; } if (vCard.AdditionalNames != string.Empty) { name.MiddleName = vCard.AdditionalNames; } if (vCard.FamilyName != string.Empty) { name.LastName = vCard.FamilyName; } if (vCard.NamePrefix != string.Empty) { name.Title = vCard.NamePrefix; } if (vCard.NameSuffix != string.Empty) { name.Suffix = vCard.NameSuffix; } contact.Name = name; } #endregion #region Delivery Address { vCardDeliveryAddressCollection vAddresses = vCard.DeliveryAddresses; int count = vAddresses.Count; Address[] addresses = new Address[count]; for (int i = 0; i < count; i++) { vCardDeliveryAddress vAddress = vAddresses[i]; Address address = new Address(); address.City = vAddress.City; address.Country = vAddress.Country; address.State = vAddress.Region; address.Street = vAddress.Street.TrimEnd(','); address.ZIP = vAddress.PostalCode; address.Type = vAddress.AddressType.ToString(); addresses[i] = address; } contact.Addresses = addresses; } #endregion #region Email Address { vCardEmailAddressCollection vEmails = vCard.EmailAddresses; int count = vEmails.Count; Email[] emails = new Email[count]; for (int i = 0; i < count; i++) { vCardEmailAddress vEmail = vEmails[i]; Email email = new Email(); email.Address = vEmail.Address; email.Type = vEmail.EmailType.ToString(); emails[i] = email; } contact.Emails = emails; } #endregion #region Website { vCardWebsiteCollection vWebsites = vCard.Websites; int count = vWebsites.Count; Website[] websites = new Website[count]; for (int i = 0; i < count; i++) { vCardWebsite vWebsite = vWebsites[i]; Website website = new Website(); website.Url = vWebsite.Url; website.Type = vWebsite.WebsiteType.ToString(); websites[i] = website; } contact.Websites = websites; } #endregion #region Notes { FlowDocument notes = new FlowDocument(); foreach (vCardNote each in vCard.Notes) { Paragraph para = new Paragraph(new Run(each.Text)); if (each.Language != string.Empty) { try { para.Language = XmlLanguage.GetLanguage(each.Language); } catch { } } notes.Blocks.Add(para); } contact.NotesDocument = notes; } #endregion #region Phone { vCardPhoneCollection vPhones = vCard.Phones; int count = vPhones.Count; PhoneNumber[] phones = new PhoneNumber[count]; for (int i = 0; i < count; i++) { vCardPhone vPhone = vPhones[i]; PhoneNumber phone = new PhoneNumber(); phone.Number = vPhone.FullNumber; phone.Type = InsertSpaces(vPhone.PhoneType.ToString()); phones[i] = phone; } contact.PhoneNumbers = phones; } #endregion if (vCard.BirthDate.HasValue) { contact.SpecialDates = new SpecialDate[] { new SpecialDate("Birthday", vCard.BirthDate.Value) } } ; contact.Private = vCard.AccessClassification.HasFlag(vCardAccessClassification.Confidential) || vCard.AccessClassification.HasFlag(vCardAccessClassification.Private); contact.Work = new Work() { Company = vCard.Organization, Department = vCard.Department, Office = vCard.Office, Title = vCard.Title }; contact.Gender = (Gender)vCard.Gender; if (vCard.IMAddress != string.Empty) { contact.IM = new IM[] { new IM("IM", vCard.IMAddress) } } ; foreach (vCardPhoto photo in vCard.Photos) { if (photo.Url != null) { try { photo.Fetch(); contact.encodeTile(photo.GetBytes()); //contact.Tile = Create96By96Tile(ConvertBytesToBitmapSource(photo.GetBytes())); break; } catch { } } else { contact.encodeTile(photo.GetBytes()); //contact.Tile = Create96By96Tile(ConvertBytesToBitmapSource(photo.GetBytes())); break; } } return(contact); }