public static void Equals(vCardPhoneCollection pc1, vCardPhoneCollection pc2) { Assert.AreEqual( pc1.Count, pc2.Count, "The phone collections do not have the same count."); for (int index = 0; index < pc1.Count; index++) { Equals(pc1[index], pc2[index]); } }
private void CheckPhone(vCardPhoneCollection phones, string value, vCardPhoneTypes types, bool isPreferred) { if (phones == null || phones.Count == 0) { Assert.Fail("phones null or empty"); } var p = phones.FirstOrDefault(x => x.FullNumber == value); if (p == null) { Assert.Fail("phone number not found for value " + value); } Assert.AreEqual(types, p.PhoneType); Assert.AreEqual(isPreferred, p.IsPreferred); // types.HasFlag( }
/// <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(); }
} var sp = sps.FirstOrDefault(x => x.Username == username && x.ServiceType == serviceType); Assert.IsNotNull(sp, "no match for socialProfile for " + username + " for serviceType " + serviceType.ToString()); Assert.AreEqual(url, sp.ProfileUrl); Assert.AreEqual(username, sp.Username); Assert.AreEqual(serviceType, sp.ServiceType); } private void CheckIM(vCardIMPPCollection ims, string handle, IMServiceType serviceType, ItemType itemType, bool isPreferred) { if (ims == null || ims.Count == 0) { Assert.Fail("ims null or empty"); } var im = ims.FirstOrDefault(x => x.Handle == handle && x.ServiceType == serviceType); Assert.IsNotNull(im, "im not matched for handle " + handle + " and servicetype " + serviceType.ToString()); Assert.AreEqual(itemType,im.ItemType);
/// <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); }