/// <summary> /// Utility method to convert website information from the vCard library to a /// WinRT ContactWebsite instance. /// No 1:1 matching is possible between both classes, the method tries to /// keep the conversion as accurate as possible. /// </summary> /// <param name="website">Website information from the vCard library.</param> /// <returns>The website information from the vCard library converted to a /// WinRT ContactWebsite instance.</returns> private ContactWebsite ConvertVcardToWebsite(vCardWebsite website) { return(new ContactWebsite { Uri = new Uri(website.Url) }); }
/// <summary> /// Asserts that two web sites are identical. /// </summary> public static void Equals(vCardWebsite w1, vCardWebsite w2) { Assert.AreEqual( w1.IsPersonalSite, w2.IsPersonalSite, "vCardWebSite.IsPersonalSite differs."); Assert.AreEqual( w1.IsWorkSite, w2.IsWorkSite, "vCardWebSite.IsWorkSite differs."); Assert.AreEqual( w1.ToString(), w2.ToString(), "vCardWebSite.ToString() differs."); Assert.AreEqual( w1.Url, w2.Url, "vCardWebSite.Url differs."); Assert.AreEqual( w1.WebsiteType, w2.WebsiteType, "vCardWebSite.WebSiteType differs."); }
public void Constructor_NullUrl() { vCardWebsite site = new vCardWebsite((string)null); Assert.IsEmpty( site.Url, "The Url should be String.Empty even when initialized to null."); }
private void SetSummaryValue(StateTextBox valueLabel, vCardWebsite webSite) { valueLabel.Text = string.Empty; if (webSite != null) { SetSummaryValue(valueLabel, webSite.Url.ToString()); } }
public void ReadWriteProperty_Url() { vCardWebsite site = new vCardWebsite(); site.Url = TestUrl; Assert.AreEqual( TestUrl, site.Url, "The Url property is not working."); }
public void ReadWriteProperty_WebSiteType() { vCardWebsite site = new vCardWebsite(); site.WebsiteType = vCardWebsiteTypes.Personal; Assert.AreEqual( vCardWebsiteTypes.Personal, site.WebsiteType, "The web site type should be set to Personal."); Assert.IsTrue( site.IsPersonalSite, "The IsPersonalSite property should be true."); Assert.IsFalse( site.IsWorkSite, "The IsWorkSite property should be false."); site.WebsiteType = vCardWebsiteTypes.Work; Assert.AreEqual( vCardWebsiteTypes.Work, site.WebsiteType, "The web site type should be set to Work."); Assert.IsFalse( site.IsPersonalSite, "The IsPersonalSite property should be false."); Assert.IsTrue( site.IsWorkSite, "The IsWorkSite property should be true."); // Now set both types. site.WebsiteType = vCardWebsiteTypes.Personal | vCardWebsiteTypes.Work; Assert.IsTrue( site.IsPersonalSite, "The IsPersonalSite property should also be true."); Assert.IsTrue( site.IsWorkSite, "The IsWorkSite property should also be true."); Assert.AreEqual( vCardWebsiteTypes.Personal | vCardWebsiteTypes.Work, site.WebsiteType, "The WebSiteType property is not working for multiple values."); }
public void ReadWriteProperty_IsPersonalSite() { vCardWebsite site = new vCardWebsite(); site.IsPersonalSite = true; Assert.IsTrue( site.IsPersonalSite, "The IsPersonSite property should be true."); site.IsPersonalSite = false; Assert.IsFalse( site.IsPersonalSite, "The IsPersonSite property should be false."); }
public void Constructor_Url_WebSiteType() { vCardWebsite site = new vCardWebsite( TestUrl, vCardWebsiteTypes.Personal); Assert.AreEqual( TestUrl, site.Url, "The URL was not assigned properly by the constructor."); Assert.AreEqual( vCardWebsiteTypes.Personal, site.WebsiteType, "The site type should have been set."); }
public void Constructor() { // Tests for default values when a web site // object is created without parameters. vCardWebsite site = new vCardWebsite(); Assert.AreEqual( site.WebsiteType, vCardWebsiteTypes.Default, "The site type should be the default."); Assert.IsEmpty( site.Url, "The Url should be String.Empty because it was not initialized."); }
public void Constructor_Url() { // Tests for values when a web site is created // with a URL. vCardWebsite site = new vCardWebsite(TestUrl); Assert.AreEqual( TestUrl, site.Url, "The URL was not assigned properly by the constructor."); Assert.AreEqual( vCardWebsiteTypes.Default, site.WebsiteType, "The site type should be default because it was not specified."); }
/// <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); }