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 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");
        }
Exemple #3
0
 public static void SetPostalAddress(PostalAddress address, Outlook.ContactItem destination)
 {
     if (address.Rel == ContactsRelationships.IsHome)
     {
         destination.HomeAddress = address.Value;
         if (address.Primary)
             destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olHome;
         return;
     }
     if (address.Rel == ContactsRelationships.IsWork)
     {
         destination.BusinessAddress = address.Value;
         if (address.Primary)
             destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olBusiness;
         return;
     }
     if (address.Rel == ContactsRelationships.IsOther)
     {
         destination.OtherAddress = address.Value;
         if (address.Primary)
             destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olOther;
         return;
     }
 }
Exemple #4
0
        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);
            }
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <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;
        }
        private void UpdateContactDataFromOutlook(ContactItem oContact, Contact gContact)
        {
            var BusinessAddressQuery = gContact.PostalAddresses.Where(a => a.Work);
            if (BusinessAddressQuery.Count() > 0)
            {
                gContact.PostalAddresses.Remove(BusinessAddressQuery.First());
            }
            if (oContact.BusinessAddress != null)
            {
                PostalAddress BusinessAddress = new PostalAddress();
                BusinessAddress.Rel = ContactsRelationships.IsWork;
                BusinessAddress.Value = oContact.BusinessAddress;
                gContact.PostalAddresses.Add(BusinessAddress);
            }

            var HomeAddressQuery = gContact.PostalAddresses.Where(a => a.Home);
            if (HomeAddressQuery.Count() > 0)
            {
                gContact.PostalAddresses.Remove(HomeAddressQuery.First());
            }
            if (oContact.HomeAddress != null)
            {
                PostalAddress HomeAddress = new PostalAddress();
                HomeAddress.Rel = ContactsRelationships.IsHome;
                HomeAddress.Value = oContact.HomeAddress;
                gContact.PostalAddresses.Add(HomeAddress);
            }
            gContact.Emails.Clear();
            if (oContact.Email1Address != null)
            {
                EMail email = new EMail(oContact.Email1Address);
                email.Rel = ContactsRelationships.IsOther;
                gContact.Emails.Add(email);
            }
            if (oContact.Email2Address  != null)
            {
                EMail email = new EMail(oContact.Email2Address);
                email.Rel = ContactsRelationships.IsOther;
                gContact.Emails.Add(email);
            }
            if (oContact.Email3Address != null)
            {
                EMail email = new EMail(oContact.Email3Address);
                email.Rel = ContactsRelationships.IsOther;
                gContact.Emails.Add(email);
            }
            gContact.Title = oContact.FullName;

            var BusinessPhoneQuery = gContact.Phonenumbers.Where(a => a.Rel == ContactsRelationships.IsWork);
            if (BusinessPhoneQuery.Count() > 0)
            {
                gContact.Phonenumbers.Remove(BusinessPhoneQuery.First());
            }
            if (oContact.BusinessTelephoneNumber != null)
            {
                PhoneNumber BusinessPhone = new PhoneNumber();
                BusinessPhone.Rel = ContactsRelationships.IsWork;
                BusinessPhone.Value = oContact.BusinessTelephoneNumber;
                gContact.Phonenumbers.Add(BusinessPhone);
            }
            var HomePhoneQuery = gContact.Phonenumbers.Where(a => a.Rel == ContactsRelationships.IsHome);
            if (HomePhoneQuery.Count() > 0)
            {
                gContact.Phonenumbers.Remove(HomePhoneQuery.First());
            }
            if (oContact.HomeTelephoneNumber != null)
            {
                PhoneNumber HomePhone = new PhoneNumber();
                HomePhone.Rel = ContactsRelationships.IsHome;
                HomePhone.Value = oContact.HomeTelephoneNumber;
                gContact.Phonenumbers.Add(HomePhone);
            }
            var MobilePhoneQuery = gContact.Phonenumbers.Where(a => a.Rel == ContactsRelationships.IsMobile);
            if (MobilePhoneQuery.Count() > 0)
            {
                gContact.Phonenumbers.Remove(MobilePhoneQuery.First());
            }
            if (oContact.MobileTelephoneNumber != null)
            {
                PhoneNumber MobilePhone = new PhoneNumber();
                MobilePhone.Rel = ContactsRelationships.IsMobile;
                MobilePhone.Value = oContact.MobileTelephoneNumber;
                gContact.Phonenumbers.Add(MobilePhone);
            }
            var BusinessFaxQuery = gContact.Phonenumbers.Where(a => a.Rel == ContactsRelationships.IsWorkFax);
            if (BusinessFaxQuery.Count() > 0)
            {
                gContact.Phonenumbers.Remove(BusinessFaxQuery.First());
            }
            if (oContact.BusinessFaxNumber != null)
            {
                PhoneNumber BusinessFaxPhone = new PhoneNumber();
                BusinessFaxPhone.Rel = ContactsRelationships.IsWorkFax;
                BusinessFaxPhone.Value = oContact.BusinessFaxNumber;
                gContact.Phonenumbers.Add(BusinessFaxPhone);
            }
            var HomeFaxQuery = gContact.Phonenumbers.Where(a => a.Rel == ContactsRelationships.IsHomeFax);
            if (HomeFaxQuery.Count() > 0)
            {
                gContact.Phonenumbers.Remove(HomeFaxQuery.First());
            }
            if (oContact.HomeFaxNumber != null)
            {
                PhoneNumber HomeFaxPhone = new PhoneNumber();
                HomeFaxPhone.Rel = ContactsRelationships.IsHomeFax;
                HomeFaxPhone.Value = oContact.HomeFaxNumber;
                gContact.Phonenumbers.Add(HomeFaxPhone);
            }
            gContact.Organizations.Clear();
            if (oContact.CompanyName != null)
            {
                Organization org = new Organization();
                org.Name = oContact.CompanyName;
                org.Rel = ContactsRelationships.IsWork;
                if (oContact.JobTitle != null)
                    org.Title = oContact.JobTitle;
                gContact.Organizations.Add(org);
            }
            else
                gContact.Organizations.Clear();
            gContact.Title = oContact.FullName;
        }