public void ModelPrimaryContactsProperties() { Tracing.TraceMsg("Entering TestModelPrimaryContactsProperties"); Contact c = new Contact(); EMail e = new EMail(); e.Primary = true; e.Address = "*****@*****.**"; Assert.IsTrue(c.PrimaryEmail == null, "Contact should have no primary Email"); c.Emails.Add(e); Assert.IsTrue(c.PrimaryEmail == e, "Contact should have one primary Email"); c.Emails.Remove(e); Assert.IsTrue(c.PrimaryEmail == null, "Contact should have no primary Email"); c.Emails.Add(e); Assert.IsTrue(c.PrimaryEmail == e, "Contact should have one primary Email"); c.Emails.RemoveAt(0); Assert.IsTrue(c.PrimaryEmail == null, "Contact should have no primary Email"); foreach (Object o in c.ContactEntry.ExtensionElements) { if (o is EMail) { Assert.IsTrue(o == null, "There should be no email in the collection"); } } PostalAddress p = new PostalAddress("Testaddress"); p.Primary = true; Assert.IsTrue(c.PrimaryPostalAddress == null, "Contact should have no primary Postal"); c.PostalAddresses.Add(p); Assert.IsTrue(c.PrimaryPostalAddress == p, "Contact should have one primary Postal"); c.PostalAddresses.Remove(p); Assert.IsTrue(c.PrimaryPostalAddress == null, "Contact should have no primary Postal"); PhoneNumber n = new PhoneNumber("123345"); n.Primary = true; Assert.IsTrue(c.PrimaryPhonenumber == null, "Contact should have no primary Phonenumber"); c.Phonenumbers.Add(n); Assert.IsTrue(c.PrimaryPhonenumber == n, "Contact should have one primary Phonenumber"); c.Phonenumbers.Remove(n); Assert.IsTrue(c.PrimaryPhonenumber == null, "Contact should have no primary Phonenumber"); IMAddress i = new IMAddress("*****@*****.**"); i.Primary = true; Assert.IsTrue(c.PrimaryIMAddress == null, "Contact should have no primary IM"); c.IMs.Add(new IMAddress()); c.IMs.Add(i); Assert.IsTrue(c.PrimaryIMAddress == i, "Contact should have one primary IMAddress"); c.IMs.Remove(i); Assert.IsTrue(c.PrimaryIMAddress == null, "Contact should have no primary IM"); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>creates a new, in memory atom entry</summary> /// <returns>the new AtomEntry </returns> ////////////////////////////////////////////////////////////////////// public static ContactEntry CreateContactEntry(int iCount) { ContactEntry entry = new ContactEntry(); // some unicode chars Char[] chars = new Char[] { '\u0023', // # '\u0025', // % '\u03a0', // Pi '\u03a3', // Sigma '\u03d1', // beta }; // if unicode needs to be disabled for testing, just uncomment this line // chars = new Char[] { 'a', 'b', 'c', 'd', 'e'}; AtomPerson author = new AtomPerson(AtomPersonType.Author); author.Name = "John Doe" + chars[0] + chars[1] + chars[2] + chars[3]; author.Email = "*****@*****.**"; entry.Authors.Add(author); entry.Content.Content = "this is the default note for a contact entry"; entry.Published = new DateTime(2001, 11, 20, 22, 30, 0); entry.Title.Text = "This is a contact number: " + iCount; entry.Updated = DateTime.Now; // add an email. EMail email = new EMail("*****@*****.**" + Guid.NewGuid().ToString()); email.Primary = true; email.Rel = ContactsRelationships.IsWork; entry.Emails.Add(email); email = new EMail("*****@*****.**" + Guid.NewGuid().ToString()); email.Label = "some email"; entry.Emails.Add(email); IMAddress im = new IMAddress("*****@*****.**"); im.Primary = true; im.Rel = ContactsRelationships.IsWork; entry.IMs.Add(im); im = new IMAddress("*****@*****.**"); im.Rel = ContactsRelationships.IsHome; PhoneNumber p = new PhoneNumber("123-3453457"); p.Primary = true; p.Rel = ContactsRelationships.IsWork; entry.Phonenumbers.Add(p); p = new PhoneNumber("123-3334445"); p.Label = "some other thing"; entry.Phonenumbers.Add(p); PostalAddress pa = new PostalAddress("This is the address"); pa.Primary = true; pa.Rel = ContactsRelationships.IsHome; entry.PostalAddresses.Add(pa); Organization org = new Organization(); org.Name = "This Test Org.Com"; org.Title = "Junior guy"; org.Label = "volunteer stuff"; entry.Organizations.Add(org); return entry; }
public static void SetIMs(Outlook.ContactItem source, ContactEntry destination) { if (!string.IsNullOrEmpty(source.IMAddress)) { //IMAddress are expected to be in form of ([Protocol]: [Address]; [Protocol]: [Address]) string[] imsRaw = source.IMAddress.Split(';'); foreach (string imRaw in imsRaw) { string[] imDetails = imRaw.Trim().Split(':'); IMAddress im = new IMAddress(); if (imDetails.Length == 1) im.Address = imDetails[0].Trim(); else { im.Protocol = imDetails[0].Trim(); im.Address = imDetails[1].Trim(); } im.Primary = destination.IMs.Count == 0; im.Rel = ContactsRelationships.IsHome; destination.IMs.Add(im); } } }
/// <summary> /// Merges the specified ims. /// </summary> /// <param name="ims">The ims.</param> /// <param name="im">The im.</param> /// <returns>True if Changed.</returns> public static bool Merge(this ExtensionCollection<IMAddress> ims, IMAddress im) { if (!string.IsNullOrWhiteSpace(im.Address) && !ims.Any(e => e.Address == im.Address)) { ims.Add(im); if (ims.Any() && !ims.Any(e => e.Primary)) { ims.First().Primary = true; } return true; } return false; }