public static bool ContainsGroup(Syncronizer sync, ContactEntry googleContact, string groupName) { GroupEntry groupEntry = sync.GetGoogleGroupByName(groupName); if (groupEntry == null) return false; return ContainsGroup(googleContact, groupEntry); }
public static void SetGoogleOutlookContactId(string syncProfile, ContactEntry googleContact, Outlook.ContactItem outlookContact) { if (outlookContact.EntryID == null) throw new Exception("Must save outlook contact before getting id"); SetGoogleOutlookContactId(syncProfile, googleContact, GetOutlookId(outlookContact)); }
public static string GetGoogleId(ContactEntry googleContact) { string id = googleContact.Id.ToString(); if (id == null) throw new Exception(); return id; }
public void CreateNewContact() { try { ContactsService service = new ContactsService("WebGear.GoogleContactsSync"); service.setUserCredentials(ConfigurationManager.AppSettings["Gmail.Username"], ConfigurationManager.AppSettings["Gmail.Password"]); #region Delete previously created test contact. ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default")); query.NumberToRetrieve = 500; ContactsFeed feed = service.Query(query); foreach (ContactEntry entry in feed.Entries) { if (entry.PrimaryEmail != null && entry.PrimaryEmail.Address == "*****@*****.**") { entry.Delete(); break; } } #endregion ContactEntry newEntry = new ContactEntry(); newEntry.Title.Text = "John Doe"; EMail primaryEmail = new EMail("*****@*****.**"); primaryEmail.Primary = true; primaryEmail.Rel = ContactsRelationships.IsWork; newEntry.Emails.Add(primaryEmail); PhoneNumber phoneNumber = new PhoneNumber("555-555-5551"); phoneNumber.Primary = true; phoneNumber.Rel = ContactsRelationships.IsMobile; newEntry.Phonenumbers.Add(phoneNumber); PostalAddress postalAddress = new PostalAddress(); postalAddress.Value = "123 somewhere lane"; postalAddress.Primary = true; postalAddress.Rel = ContactsRelationships.IsHome; newEntry.PostalAddresses.Add(postalAddress); newEntry.Content.Content = "Who is this guy?"; Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default")); ContactEntry createdEntry = (ContactEntry)service.Insert(feedUri, newEntry); Assert.IsNotNull(createdEntry.Id.Uri); //delete this temp contact createdEntry.Delete(); } catch (Exception ex) { } }
public static void AddGoogleGroup(ContactEntry googleContact, GroupEntry groupEntry) { if (ContainsGroup(googleContact, groupEntry)) return; GroupMembership m = new GroupMembership(); m.HRef = groupEntry.Id.AbsoluteUri; googleContact.GroupMembership.Add(m); }
public void FillProviderCreatedItem(Contact contact, ContactEntry c) { c.Title.Text = contact.GetFullName(this.Notation); foreach (Microsoft.Communications.Contacts.PhoneNumber phone in contact.PhoneNumbers) { Google.GData.Extensions.PhoneNumber p = new Google.GData.Extensions.PhoneNumber(); } }
public static bool ContainsGroup(ContactEntry googleContact, GroupEntry groupEntry) { foreach (GroupMembership m in googleContact.GroupMembership) { if (m.HRef == groupEntry.Id.AbsoluteUri) return true; } return false; }
public static string GetGoogleOutlookContactId(string syncProfile, ContactEntry googleContact) { // get extended prop foreach (Google.GData.Extensions.ExtendedProperty p in googleContact.ExtendedProperties) { if (p.Name == "gos:oid:" + syncProfile + "") return (string)p.Value; } return null; }
public static void ResetGoogleOutlookContactId(string syncProfile, ContactEntry googleContact) { // get extended prop foreach (Google.GData.Extensions.ExtendedProperty p in googleContact.ExtendedProperties) { if (p.Name == "gos:oid:" + syncProfile + "") { // remove googleContact.ExtendedProperties.Remove(p); return; } } }
static void Main(string[] args) { try { // create an OAuth factory to use GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp"); requestFactory.ConsumerKey = "CONSUMER_KEY"; requestFactory.ConsumerSecret = "CONSUMER_SECRET"; // example of performing a query (use OAuthUri or query.OAuthRequestorId) Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/owncalendars/full", "USER", "DOMAIN"); // can use plain Uri if setting OAuthRequestorId in the query // Uri calendarUri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full"); CalendarQuery query = new CalendarQuery(); query.Uri = calendarUri; query.OAuthRequestorId = "USER@DOMAIN"; // can do this instead of using OAuthUri for queries CalendarService service = new CalendarService("MyApp"); service.RequestFactory = requestFactory; service.Query(query); Console.WriteLine("Query Success!"); // example with insert (must use OAuthUri) Uri contactsUri = new OAuthUri("http://www.google.com/m8/feeds/contacts/default/full", "USER", "DOMAIN"); ContactEntry entry = new ContactEntry(); EMail primaryEmail = new EMail("*****@*****.**"); primaryEmail.Primary = true; primaryEmail.Rel = ContactsRelationships.IsHome; entry.Emails.Add(primaryEmail); ContactsService contactsService = new ContactsService("MyApp"); contactsService.RequestFactory = requestFactory; contactsService.Insert(contactsUri, entry); // this could throw if contact exists Console.WriteLine("Insert Success!"); // to perform a batch use // service.Batch(batchFeed, new OAuthUri(atomFeed.Batch, userName, domain)); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine("Fail!"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ReadKey(); } }
public static void MergeContacts(ContactEntry master, Outlook.ContactItem slave) { //// if no email or number, contact will be updated at each sync //if (master.Emails.Count == 0 && master.Phonenumbers.Count == 0) // return; if (!string.IsNullOrEmpty(master.Title.Text)) { //slave.FileAs = master.Title.Text; slave.FullName = master.Title.Text; } else slave.FileAs = master.Emails[0].Address; SetEmails(master, slave); foreach (PhoneNumber phone in master.Phonenumbers) { SetPhoneNumber(phone, slave); } foreach (PostalAddress address in master.PostalAddresses) { SetPostalAddress(address, slave); } slave.Companies = string.Empty; foreach (Organization company in master.Organizations) { if (string.IsNullOrEmpty(company.Title)) continue; if (company.Primary) slave.CompanyName = company.Title; if (!string.IsNullOrEmpty(slave.Companies)) slave.Companies += "; "; slave.Companies += company.Title; } slave.IMAddress = ""; foreach (IMAddress im in master.IMs) { if (!string.IsNullOrEmpty(slave.IMAddress)) slave.IMAddress += "; "; if (!string.IsNullOrEmpty(im.Protocol)) slave.IMAddress += im.Protocol + ": " + im.Address; slave.IMAddress += im.Address; } slave.Body = master.Content.Content; }
public static void MergeContacts(Outlook.ContactItem master, ContactEntry slave) { //// if no email or number, contact will be updated at each sync //if (string.IsNullOrEmpty(master.Email1Address) && string.IsNullOrEmpty(master.PrimaryTelephoneNumber)) // return; //TODO: convert to merge as opposed to replace if (master.FileAs != master.Email1Address) { if (master.FullName == "") { slave.Title.Text = master.FileAs; } else { slave.Title.Text = master.FullName; } } else { slave.Title.Text = null; } if (slave.Title.Text == null) slave.Title.Text = master.FullName; if (slave.Title.Text == null) slave.Title.Text = master.CompanyName; slave.Emails.Clear(); SetEmails(master, slave); slave.PostalAddresses.Clear(); SetAddresses(master, slave); slave.Phonenumbers.Clear(); SetPhoneNumbers(master, slave); slave.Organizations.Clear(); SetCompanies(master, slave); slave.IMs.Clear(); SetIMs(master, slave); slave.Content.Content = master.Body; }
public void TestCreatingGoogeAccountThatFailed1() { Outlook.ContactItem outlookContact = sync.OutlookContacts.Find( string.Format("[FirstName]='{0}' AND [LastName]='{1}'", ConfigurationManager.AppSettings["Test.FirstName"], ConfigurationManager.AppSettings["Test.LastName"])) as Outlook.ContactItem; ContactMatch match = FindMatch(outlookContact); Assert.IsNotNull(match); Assert.IsNull(match.GoogleContact); ContactEntry googleContact = new ContactEntry(); //ContactSync.UpdateContact(outlookContact, googleContact); googleContact.Title.Text = outlookContact.FileAs; if (googleContact.Title.Text == null) googleContact.Title.Text = outlookContact.FullName; if (googleContact.Title.Text == null) googleContact.Title.Text = outlookContact.CompanyName; ContactSync.SetEmails(outlookContact, googleContact); ContactSync.SetPhoneNumbers(outlookContact, googleContact); ContactSync.SetAddresses(outlookContact, googleContact); ContactSync.SetCompanies(outlookContact, googleContact); ContactSync.SetIMs(outlookContact, googleContact); googleContact.Content.Content = outlookContact.Body; Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default")); ContactEntry createdEntry = (ContactEntry)sync.GoogleService.Insert(feedUri, googleContact); ContactPropertiesUtils.SetOutlookGoogleContactId(sync, match.OutlookContact, createdEntry); match.GoogleContact = createdEntry; match.OutlookContact.Save(); }
public GDataTypes.GDataContactEntry CreateContactModifidEntry(ContactEntry contactEntry, string name) { var _gDataContactEntry = new GDataTypes.GDataContactEntry(); _gDataContactEntry.Name = name; foreach (var _emailEntry in contactEntry.Emails) { if (_emailEntry.Work == true) { _gDataContactEntry.Email = _emailEntry.Address; } } foreach (var _phoneNumberEntry in contactEntry.Phonenumbers) { if (_phoneNumberEntry.Rel == ContactsRelationships.IsWork) { _gDataContactEntry.PhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsHome) { _gDataContactEntry.HomePhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsMobile) { _gDataContactEntry.MobilePhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsOther) { _gDataContactEntry.OtherPhoneNumber = _phoneNumberEntry.Value; } } foreach (var _postaAddressEntry in contactEntry.PostalAddresses) { if (_postaAddressEntry.Rel == ContactsRelationships.IsWork) { _gDataContactEntry.PostalAddress = _postaAddressEntry.FormattedAddress; } if (_postaAddressEntry.Rel == ContactsRelationships.IsHome) { _gDataContactEntry.HomeAddress = _postaAddressEntry.FormattedAddress; } } _gDataContactEntry.SelfUri = contactEntry.SelfUri.ToString(); return _gDataContactEntry; }
/// <summary> /// Replaces all properties of <paramref name="destination"/> from corresponding properties of <paramref name="source"/> /// </summary> /// <param name="source"></param> /// <param name="destination"></param> public static void UpdateContact(Outlook.ContactItem source, ContactEntry destination) { //// if no email or number, contact will be updated at each sync //if (string.IsNullOrEmpty(source.Email1Address) && string.IsNullOrEmpty(source.PrimaryTelephoneNumber)) // return; if (source.FileAs != source.Email1Address) { if (source.FullName == "") { destination.Title.Text = source.FileAs; } else { destination.Title.Text = source.FullName; } } else { destination.Title.Text = null; } if (destination.Title.Text == null) destination.Title.Text = source.FullName; if (destination.Title.Text == null) destination.Title.Text = source.CompanyName; SetEmails(source, destination); SetPhoneNumbers(source, destination); SetAddresses(source, destination); SetCompanies(source, destination); SetIMs(source, destination); // CH - Fixed error with invalid xml being sent to google... This may need to be added to everything destination.Content.Content = String.Format( "<![CDATA[{0}]]>", source.Body); }
public static void UpdateContact(ContactEntry source, Outlook.ContactItem destination) { //// if no email or number, contact will be updated at each sync //if (source.Emails.Count == 0 && source.Phonenumbers.Count == 0) // return; if (!string.IsNullOrEmpty(source.Title.Text)) destination.FileAs = source.Title.Text; else destination.FileAs = source.Emails[0].Address; SetEmails(source, destination); foreach (PhoneNumber phone in source.Phonenumbers) { SetPhoneNumber(phone, destination); } foreach (PostalAddress address in source.PostalAddresses) { SetPostalAddress(address, destination); } destination.Companies = string.Empty; foreach (Organization company in source.Organizations) { if (company.Primary) destination.CompanyName = company.Title; if (destination.Companies.Length > 0) destination.Companies += "; "; destination.Companies += company.Title; } destination.IMAddress = ""; foreach (IMAddress im in source.IMs) { if (destination.IMAddress.Length > 0) destination.IMAddress += "; "; if (!string.IsNullOrEmpty(im.Protocol)) destination.IMAddress += im.Protocol + ": " + im.Address; destination.IMAddress += im.Address; } destination.Body = source.Content.Content; }
public static void SetPhoneNumbers(Outlook.ContactItem source, ContactEntry destination) { if (!string.IsNullOrEmpty(source.PrimaryTelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.PrimaryTelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsMobile; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.MobileTelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.MobileTelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsMobile; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.HomeTelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.HomeTelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsHome; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.BusinessTelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.BusinessTelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsWork; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.Business2TelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.Business2TelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsWork; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.HomeFaxNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.HomeFaxNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsHomeFax; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.BusinessFaxNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.BusinessFaxNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsWorkFax; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.OtherTelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.OtherTelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsOther; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.RadioTelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.RadioTelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsMobile; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.PagerNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.PagerNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsPager; destination.Phonenumbers.Add(phoneNumber); } if (!string.IsNullOrEmpty(source.CarTelephoneNumber)) { PhoneNumber phoneNumber = new PhoneNumber(source.CarTelephoneNumber); phoneNumber.Primary = destination.Phonenumbers.Count == 0; phoneNumber.Rel = ContactsRelationships.IsCar; destination.Phonenumbers.Add(phoneNumber); } }
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); } } }
public static void SetEmails(ContactEntry source, Outlook.ContactItem destination) { if (source.Emails.Count > 0) { destination.Email1Address = source.Emails[0].Address; destination.Email1DisplayName = source.Emails[0].Label; } if (source.Emails.Count > 1) destination.Email2Address = source.Emails[1].Address; if (source.Emails.Count > 2) destination.Email3Address = source.Emails[2].Address; }
public static void SetEmails(Outlook.ContactItem source, ContactEntry destination) { if (!string.IsNullOrEmpty(source.Email1Address)) { EMail primaryEmail = new EMail(source.Email1Address); primaryEmail.Primary = destination.Emails.Count == 0; primaryEmail.Rel = ContactsRelationships.IsWork; destination.Emails.Add(primaryEmail); } if (!string.IsNullOrEmpty(source.Email2Address)) { EMail secondaryEmail = new EMail(source.Email2Address); secondaryEmail.Primary = destination.Emails.Count == 0; secondaryEmail.Rel = ContactsRelationships.IsHome; destination.Emails.Add(secondaryEmail); } if (!string.IsNullOrEmpty(source.Email3Address)) { EMail secondaryEmail = new EMail(source.Email3Address); secondaryEmail.Primary = destination.Emails.Count == 0; secondaryEmail.Rel = ContactsRelationships.IsOther; destination.Emails.Add(secondaryEmail); } }
///// <summary> ///// Updates Outlook contact's categories (groups) ///// </summary> ///// <param name="outlookContact"></param> ///// <param name="currentGroups"></param> ///// <param name="newGroups"></param> //public void OverwriteOutlookContactGroups(Outlook.ContactItem outlookContact, string[] currentGroups, Collection<GroupEntry> newGroups) //{ // // remove obsolete groups // Collection<string> remove = new Collection<string>(); // bool found; // foreach (string cat in currentGroups) // { // found = false; // foreach (GroupEntry group in newGroups) // { // if (group.Title.Text == cat) // { // found = true; // break; // } // } // if (!found) // remove.Add(cat); // } // while (remove.Count != 0) // { // Utilities.RemoveOutlookGroup(outlookContact, remove[0]); // remove.RemoveAt(0); // } // // add new groups // foreach (GroupEntry group in newGroups) // { // if (!Utilities.ContainsGroup(outlookContact, group.Title.Text)) // Utilities.AddOutlookGroup(outlookContact, group.Title.Text); // } //} /// <summary> /// Updates Outlook contact's categories (groups) /// </summary> /// <param name="outlookContact"></param> /// <param name="currentGroups"></param> /// <param name="newGroups"></param> public void OverwriteContactGroups(ContactEntry master, Outlook.ContactItem slave) { Collection<GroupEntry> newGroups = Utilities.GetGoogleGroups(this, master); List<string> newCats = new List<string>(newGroups.Count); foreach (GroupEntry group in newGroups) { newCats.Add(group.Title.Text); } slave.Categories = string.Join(", ", newCats.ToArray()); }
public static bool SaveGooglePhoto(Syncronizer sync, ContactEntry googleContact, Image image) { if (googleContact.PhotoEditUri == null) throw new Exception("Must reload contact from google."); try { WebClient client = new WebClient(); client.Headers.Add(HttpRequestHeader.Authorization, "GoogleLogin auth=" + sync.AuthToken); client.Headers.Add(HttpRequestHeader.ContentType, "image/*"); Bitmap pic = new Bitmap(image); Stream s = client.OpenWrite(googleContact.PhotoEditUri.AbsoluteUri, "PUT"); byte[] bytes = BitmapToBytes(pic); s.Write(bytes, 0, bytes.Length); s.Flush(); s.Close(); s.Dispose(); client.Dispose(); pic.Dispose(); } catch { return false; } return true; }
///////////////////////////////////////////////////////////////////////////// private void AddContactPhoto(ContactEntry entry, ContactsService contactService) { try { using (FileStream fs = new FileStream(this.resourcePath + "contactphoto.jpg", System.IO.FileMode.Open)) { Stream res = contactService.StreamSend(entry.PhotoUri, fs, GDataRequestType.Update, "image/jpg", null); res.Close(); } } finally { } }
public GDataTypes.GDataContactEntrys AppendContactEntrys(ContactEntry contactEntry, GDataTypes.GDataContactEntrys gDataContactEntrys) { var _gDataContactEntry = new GDataTypes.GDataContactEntry(); _gDataContactEntry.Name = contactEntry.Title.Text; foreach (var _emailEntry in contactEntry.Emails) { if (_emailEntry.Work == true) { _gDataContactEntry.Email = _emailEntry.Address; } } foreach (var _phoneNumberEntry in contactEntry.Phonenumbers) { if (_phoneNumberEntry.Rel == ContactsRelationships.IsWork) { _gDataContactEntry.PhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsHome) { _gDataContactEntry.HomePhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsMobile) { _gDataContactEntry.MobilePhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsOther) { _gDataContactEntry.OtherPhoneNumber = _phoneNumberEntry.Value; } } foreach (var _postaAddressEntry in contactEntry.PostalAddresses) { if (_postaAddressEntry.Rel == ContactsRelationships.IsWork) { _gDataContactEntry.PostalAddress = _postaAddressEntry.FormattedAddress; } if (_postaAddressEntry.Rel == ContactsRelationships.IsHome) { _gDataContactEntry.HomeAddress = _postaAddressEntry.FormattedAddress; } } _gDataContactEntry.SelfUri = contactEntry.SelfUri.ToString(); gDataContactEntrys.Add(_gDataContactEntry); return gDataContactEntrys; }
public void TestPrimaryContactsProperties() { Tracing.TraceMsg("Entering TestPrimaryContactsProperties"); ContactEntry entry = new ContactEntry(); EMail e = new EMail(); e.Primary = true; e.Address = "*****@*****.**"; Assert.IsTrue(entry.PrimaryEmail == null, "Entry should have no primary Email"); entry.Emails.Add(e); Assert.IsTrue(entry.PrimaryEmail == e, "Entry should have one primary Email"); entry.Emails.Remove(e); Assert.IsTrue(entry.PrimaryEmail == null, "Entry should have no primary Email"); entry.Emails.Add(e); Assert.IsTrue(entry.PrimaryEmail == e, "Entry should have one primary Email"); entry.Emails.RemoveAt(0); Assert.IsTrue(entry.PrimaryEmail == null, "Entry should have no primary Email"); foreach (Object o in entry.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(entry.PrimaryPostalAddress == null, "Entry should have no primary Postal"); entry.PostalAddresses.Add(p); Assert.IsTrue(entry.PrimaryPostalAddress == p, "Entry should have one primary Postal"); entry.PostalAddresses.Remove(p); Assert.IsTrue(entry.PrimaryPostalAddress == null, "Entry should have no primary Postal"); PhoneNumber n = new PhoneNumber("123345"); n.Primary = true; Assert.IsTrue(entry.PrimaryPhonenumber == null, "Entry should have no primary Phonenumber"); entry.Phonenumbers.Add(n); Assert.IsTrue(entry.PrimaryPhonenumber == n, "Entry should have one primary Phonenumber"); entry.Phonenumbers.Remove(n); Assert.IsTrue(entry.PrimaryPhonenumber == null, "Entry should have no primary Phonenumber"); IMAddress i = new IMAddress("*****@*****.**"); i.Primary = true; Assert.IsTrue(entry.PrimaryIMAddress == null, "Entry should have no primary IM"); entry.IMs.Add(new IMAddress()); entry.IMs.Add(i); Assert.IsTrue(entry.PrimaryIMAddress == i, "Entry should have one primary IMAddress"); entry.IMs.Remove(i); Assert.IsTrue(entry.PrimaryIMAddress == null, "Entry 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; }
///// <summary> ///// Updates Google contact's groups ///// </summary> ///// <param name="googleContact"></param> ///// <param name="currentGroups"></param> ///// <param name="newGroups"></param> //public void OverwriteGoogleContactGroups(ContactEntry googleContact, Collection<GroupEntry> currentGroups, string[] newGroups) //{ // // remove obsolete groups // Collection<GroupEntry> remove = new Collection<GroupEntry>(); // bool found; // foreach (GroupEntry group in currentGroups) // { // found = false; // foreach (string cat in newGroups) // { // if (group.Title.Text == cat) // { // found = true; // break; // } // } // if (!found) // remove.Add(group); // } // while (remove.Count != 0) // { // Utilities.RemoveGoogleGroup(googleContact, remove[0]); // remove.RemoveAt(0); // } // // add new groups // GroupEntry g; // foreach (string cat in newGroups) // { // if (!Utilities.ContainsGroup(this, googleContact, cat)) // { // // (create and) add group to contact // g = GetGoogleGroupByName(cat); // if (g == null) // { // g = CreateGroup(cat); // SaveGoogleGroup(g); // LoadGoogleGroups(); // g = GetGoogleGroupByName(cat); // } // Utilities.AddGoogleGroup(googleContact, g); // } // } //} /// <summary> /// Updates Google contact's groups /// </summary> /// <param name="googleContact"></param> /// <param name="currentGroups"></param> /// <param name="newGroups"></param> public void OverwriteContactGroups(Outlook.ContactItem master, ContactEntry slave) { Collection<GroupEntry> currentGroups = Utilities.GetGoogleGroups(this, slave); // get outlook categories string[] cats = Utilities.GetOutlookGroups(master); // remove obsolete groups Collection<GroupEntry> remove = new Collection<GroupEntry>(); bool found; foreach (GroupEntry group in currentGroups) { found = false; foreach (string cat in cats) { if (group.Title.Text == cat) { found = true; break; } } if (!found) remove.Add(group); } while (remove.Count != 0) { Utilities.RemoveGoogleGroup(slave, remove[0]); remove.RemoveAt(0); } // add new groups GroupEntry g; foreach (string cat in cats) { if (!Utilities.ContainsGroup(this, slave, cat)) { // add group to contact g = GetGoogleGroupByName(cat); if (g == null) { throw new Exception(string.Format("Google Groups were supposed to be created prior to saving", cat)); } Utilities.AddGoogleGroup(slave, g); } } }
public static void SetAddresses(Outlook.ContactItem source, ContactEntry destination) { if (!string.IsNullOrEmpty(source.HomeAddress)) { PostalAddress postalAddress = new PostalAddress(); postalAddress.Value = source.HomeAddress; postalAddress.Primary = true; postalAddress.Rel = ContactsRelationships.IsHome; destination.PostalAddresses.Add(postalAddress); } if (!string.IsNullOrEmpty(source.BusinessAddress)) { PostalAddress postalAddress = new PostalAddress(); postalAddress.Value = source.BusinessAddress; postalAddress.Primary = destination.PostalAddresses.Count == 0; postalAddress.Rel = ContactsRelationships.IsWork; destination.PostalAddresses.Add(postalAddress); } if (!string.IsNullOrEmpty(source.OtherAddress)) { PostalAddress postalAddress = new PostalAddress(); postalAddress.Value = source.OtherAddress; postalAddress.Primary = destination.PostalAddresses.Count == 0; postalAddress.Rel = ContactsRelationships.IsOther; destination.PostalAddresses.Add(postalAddress); } }
public void SaveGoogleContact(ContactEntry googleContact) { //check if this contact was not yet inserted on google. if (googleContact.Id.Uri == null) { //insert contact. Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default")); try { ContactEntry createdEntry = (ContactEntry)_googleService.Insert(feedUri, googleContact); } catch (Exception ex) { //TODO: save google contact xml for diagnistics throw ex; } } else { try { //contact already present in google. just update //TODO: this will fail if original contact had an empty name or rpimary email address. ContactEntry updatedEntry = googleContact.Update() as ContactEntry; } catch (Exception ex) { //TODO: save google contact xml for diagnistics throw ex; } } }
public static void SetCompanies(Outlook.ContactItem source, ContactEntry destination) { if (!string.IsNullOrEmpty(source.Companies)) { //Companies are expected to be in form of "[Company]; [Company]". string[] companiesRaw = source.Companies.Split(';'); foreach (string companyRaw in companiesRaw) { Organization company = new Organization(); company.Name = companyRaw.Trim(); company.Primary = destination.Organizations.Count == 0; company.Rel = ContactsRelationships.IsWork; destination.Organizations.Add(company); } } if (destination.Organizations.Count == 0 && !string.IsNullOrEmpty(source.CompanyName)) { Organization company = new Organization(); company.Name = source.CompanyName; company.Primary = true; company.Rel = ContactsRelationships.IsWork; destination.Organizations.Add(company); } }