/// <summary> /// sets the correct IM address from a google contacts Ims /// </summary> /// <param name="stdEntry">The std entry.</param> /// <param name="instantMessengerAddress">The IM address.</param> public static void SetInstantMessenger(this StdContact stdEntry, IMAddress instantMessengerAddress) { if (stdEntry.PersonalInstantMessengerAddresses == null) { stdEntry.PersonalInstantMessengerAddresses = new InstantMessengerAddresses(); } if (instantMessengerAddress.Home) { switch (instantMessengerAddress.Protocol) { case "msn": stdEntry.PersonalInstantMessengerAddresses.MsnMessenger = instantMessengerAddress.Address; break; } } if (instantMessengerAddress.Work) { switch (instantMessengerAddress.Protocol) { case "msn": stdEntry.BusinessInstantMessengerAddresses.MsnMessenger = instantMessengerAddress.Address; break; } } }
public static void SetIMs(Outlook.ContactItem source, Contact destination) { destination.IMs.Clear(); 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(); } //Only add the im Address if not empty (to avoid Google exception "address" empty) if (!string.IsNullOrEmpty(im.Address)) { 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); }
public GoogleContactWrapper Map1To2(ContactItemWrapper source, GoogleContactWrapper targetWrapper, IEntityMappingLogger logger) { var target = targetWrapper.Contact; #region Title/FileAs if (!string.IsNullOrEmpty(source.Inner.FileAs)) { target.Title = source.Inner.FileAs; } else if (!string.IsNullOrEmpty(source.Inner.CompanyAndFullName)) { target.Title = source.Inner.CompanyAndFullName; } else if (!string.IsNullOrEmpty(source.Inner.FullName)) { target.Title = source.Inner.FullName; } else if (!string.IsNullOrEmpty(source.Inner.CompanyName)) { target.Title = source.Inner.CompanyName; } else if (!string.IsNullOrEmpty(source.Inner.Email1Address)) { target.Title = source.Inner.Email1Address; } #endregion Title/FileAs #region Name Name name = new Name() { GivenName = source.Inner.FirstName, FamilyName = source.Inner.LastName, AdditionalName = source.Inner.MiddleName, NamePrefix = source.Inner.Title, NameSuffix = source.Inner.Suffix, }; //Use the Google's full name to save a unique identifier. When saving the FullName, it always overwrites the Google Title if (!string.IsNullOrEmpty(source.Inner.FullName)) //Only if source.FullName has a value, i.e. not only a company or email contact { name.FullName = source.Inner.FileAs; } target.Name = name; #endregion Name MapEmailAddresses1To2(source.Inner, target, logger); MapPostalAddresses1To2(source.Inner, target); MapPhoneNumbers1To2(source.Inner, target); target.ContactEntry.Nickname = source.Inner.NickName; target.ContactEntry.Initials = source.Inner.Initials; #region company target.Organizations.Clear(); if (!string.IsNullOrEmpty(source.Inner.Companies)) { //Companies are expected to be in form of "[Company]; [Company]". string[] companiesRaw = source.Inner.Companies.Split(';'); foreach (string companyRaw in companiesRaw) { Organization company = new Organization(); company.Name = (target.Organizations.Count == 0) ? source.Inner.CompanyName : companyRaw; company.Title = (target.Organizations.Count == 0) ? source.Inner.JobTitle : null; company.Department = (target.Organizations.Count == 0) ? source.Inner.Department : null; company.Primary = target.Organizations.Count == 0; company.Rel = ContactsRelationships.IsWork; target.Organizations.Add(company); } } if (target.Organizations.Count == 0 && (!string.IsNullOrEmpty(source.Inner.CompanyName) || !string.IsNullOrEmpty(source.Inner.Department) || !string.IsNullOrEmpty(source.Inner.JobTitle))) { target.Organizations.Add(new Organization() { Name = source.Inner.CompanyName, Department = source.Inner.Department, Title = source.Inner.JobTitle, Rel = ContactsRelationships.IsWork, Primary = true, }); } #endregion company target.ContactEntry.Occupation = source.Inner.Profession; target.Location = source.Inner.OfficeLocation; target.ContactEntry.Websites.Clear(); if (!string.IsNullOrEmpty(source.Inner.WebPage)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.WebPage, Rel = REL_HOMEPAGE, Primary = true, }); } if (!string.IsNullOrEmpty(source.Inner.BusinessHomePage)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.BusinessHomePage, Rel = REL_WORK, Primary = target.ContactEntry.Websites.Count == 0, }); } if (!string.IsNullOrEmpty(source.Inner.PersonalHomePage)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.PersonalHomePage, Rel = REL_HOME, Primary = target.ContactEntry.Websites.Count == 0, }); } if (!string.IsNullOrEmpty(source.Inner.FTPSite)) { target.ContactEntry.Websites.Add(new Website() { Href = source.Inner.FTPSite, Rel = REL_FTP, Primary = target.ContactEntry.Websites.Count == 0, }); } #region birthday if (_configuration.MapBirthday && !source.Inner.Birthday.Equals(OU_OUTLOOK_DATE_NONE)) { target.ContactEntry.Birthday = source.Inner.Birthday.ToString("yyyy-MM-dd"); } else { target.ContactEntry.Birthday = null; } #endregion birthday #region anniversary //Todo: Check, if (_configuration.MapAnniversary) //{ //First remove anniversary foreach (Event ev in target.ContactEntry.Events) { if (ev.Relation != null && ev.Relation.Equals(REL_ANNIVERSARY)) { target.ContactEntry.Events.Remove(ev); break; } } try { //Then add it again if existing if (!source.Inner.Anniversary.Equals(OU_OUTLOOK_DATE_NONE)) //earlier also || source.Inner.Birthday.Year < 1900 { Event ev = new Event(); ev.Relation = REL_ANNIVERSARY; ev.When = new When(); ev.When.AllDay = true; ev.When.StartTime = source.Inner.Anniversary.Date; target.ContactEntry.Events.Add(ev); } } catch (System.Exception ex) { s_logger.Warn("Anniversary couldn't be updated from Outlook to Google for '" + source.Inner.FileAs + "': " + ex.Message, ex); logger.LogMappingWarning("Anniversary couldn't be updated from Outlook to Google for '" + source.Inner.FileAs + "': " + ex.Message, ex); } //} #endregion anniversary #region relations (spouse, child, manager and assistant) //First remove spouse, child, manager and assistant for (int i = target.ContactEntry.Relations.Count - 1; i >= 0; i--) { Relation rel = target.ContactEntry.Relations[i]; if (rel.Rel != null && (rel.Rel.Equals(REL_SPOUSE) || rel.Rel.Equals(REL_CHILD) || rel.Rel.Equals(REL_MANAGER) || rel.Rel.Equals(REL_ASSISTANT))) { target.ContactEntry.Relations.RemoveAt(i); } } //Then add spouse again if existing if (!string.IsNullOrEmpty(source.Inner.Spouse)) { Relation rel = new Relation(); rel.Rel = REL_SPOUSE; rel.Value = source.Inner.Spouse; target.ContactEntry.Relations.Add(rel); } //Then add children again if existing if (!string.IsNullOrEmpty(source.Inner.Children)) { Relation rel = new Relation(); rel.Rel = REL_CHILD; rel.Value = source.Inner.Children; target.ContactEntry.Relations.Add(rel); } //Then add manager again if existing if (!string.IsNullOrEmpty(source.Inner.ManagerName)) { Relation rel = new Relation(); rel.Rel = REL_MANAGER; rel.Value = source.Inner.ManagerName; target.ContactEntry.Relations.Add(rel); } //Then add assistant again if existing if (!string.IsNullOrEmpty(source.Inner.AssistantName)) { Relation rel = new Relation(); rel.Rel = REL_ASSISTANT; rel.Value = source.Inner.AssistantName; target.ContactEntry.Relations.Add(rel); } #endregion relations (spouse, child, manager and assistant) #region IMs target.IMs.Clear(); if (!string.IsNullOrEmpty(source.Inner.IMAddress)) { //IMAddress are expected to be in form of ([Protocol]: [Address]; [Protocol]: [Address]) string[] imsRaw = source.Inner.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(); } //Only add the im Address if not empty (to avoid Google exception "address" empty) if (!string.IsNullOrEmpty(im.Address)) { im.Primary = target.IMs.Count == 0; im.Rel = ContactsRelationships.IsHome; target.IMs.Add(im); } } } #endregion IMs target.Content = !string.IsNullOrEmpty(source.Inner.Body) ? System.Security.SecurityElement.Escape(source.Inner.Body) : null; target.ContactEntry.Sensitivity = MapPrivacy1To2(source.Inner.Sensitivity); target.Languages.Clear(); if (!string.IsNullOrEmpty(source.Inner.Language)) { foreach (var lang in source.Inner.Language.Split(';')) { target.Languages.Add(new Language() { Label = lang }); } } target.ContactEntry.Hobbies.Clear(); if (!string.IsNullOrEmpty(source.Inner.Hobby)) { foreach (var hobby in source.Inner.Hobby.Split(';')) { target.ContactEntry.Hobbies.Add(new Hobby(hobby)); } } targetWrapper.Groups.Clear(); targetWrapper.Groups.AddRange(CommonEntityMapper.SplitCategoryString(source.Inner.Categories)); if (_configuration.MapContactPhoto) { MapPhoto1To2(source.Inner, targetWrapper, logger); } return(targetWrapper); }
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"); } } StructuredPostalAddress p = CreatePostalAddress(); 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>Commit an instant message struct in the contact's collection of instant messages.</summary> /// <param name="contact">The contact that is having this IM struct committed.</param> /// <param name="arrayNode">The array node where this IM struct is being committed.</param> /// <param name="value">The IM struct being committed.</param> private static void _CommitIM(Contact contact, string arrayNode, IMAddress value) { Assert.IsTrue(arrayNode.StartsWith(PropertyNames.IMAddressCollection + PropertyNames.IMAddressArrayNode, StringComparison.Ordinal)); contact._SetOrRemoveStringProperty(arrayNode + PropertyNames.Value, value.Handle); contact._SetOrRemoveStringProperty(arrayNode + PropertyNames.Protocol , value.Protocol); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <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); StructuredPostalAddress pa = ContactsTestSuite.CreatePostalAddress(); 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); }