Ejemplo n.º 1
0
        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;
                }
            }
            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;
                }
            }
        }
Ejemplo n.º 2
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            ContactEntry contact = null;

            if (ContactsListBox.SelectedIndex != -1)
            {
                contact = ContactsListBox.SelectedItem as ContactEntry;

                contact.Title.Text = NameTextBox.Text;
                contact.Content.Content = DescriptionTextBox.Text;

                if (contact.PrimaryEmail == null)
                {
                    EMail email = new EMail(EmailTextBox.Text);
                    email.Primary = true;
                    contact.Emails.Add(email);
                }
                else
                {
                    contact.PrimaryEmail.Address = EmailTextBox.Text;
                }

                if (contact.Phonenumbers.Count > 0)
                {
                    if (PhoneTextBox.Text != "")   // update number
                    {
                        contact.Phonenumbers[0] = new PhoneNumber(PhoneTextBox.Text);
                        contact.Phonenumbers[0].Rel = ContactsRelationships.IsHome;
                    }
                    else
                    {
                        contact.Phonenumbers.Remove(contact.Phonenumbers[0]);   // delete number
                    }
                }
                else if (contact.Phonenumbers.Count == 0 && PhoneTextBox.Text != "") // add new number
                {
                    PhoneNumber phoneNumber = new PhoneNumber(PhoneTextBox.Text);
                    phoneNumber.Rel = ContactsRelationships.IsHome;
                    contact.Phonenumbers.Add(phoneNumber);
                }
            }
        
            try
            {
                contact.Update();

                // Dont't deal with 409 conflict errors. Update the ContactsListBox by querying the feed.
                this.selectedIndex = ContactsListBox.SelectedIndex;
                fillContactList(this.selfLink);
                ContactsListBox.SelectedIndex = this.selectedIndex;
            }
            catch (GDataRequestException ex)
            {
                MessageBox.Show(ex.InnerException.Message);
            }
        }
Ejemplo n.º 3
0
        public void TestUpdatingGoogeAccountThatFailed()
        {
            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.IsNotNull(match.GoogleContact);

            ContactEntry googleContact = match.GoogleContact;

            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);

            //SetAddresses(outlookContact, googleContact);

            //SetCompanies(outlookContact, googleContact);

            //SetIMs(outlookContact, googleContact);

            //googleContact.Content.Content = outlookContact.Body;

            ContactEntry updatedEntry = googleContact.Update() as ContactEntry;

            ContactPropertiesUtils.SetOutlookGoogleContactId(sync, match.OutlookContact, updatedEntry);
            match.GoogleContact = updatedEntry;
            match.OutlookContact.Save();
        }
        /////////////////////////////////////////////////////////////////////////////


        /////////////////////////////////////////////////////////////////////
        /// <summary>runs an basic auth test against the groups feed test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GroupsSystemTest()
        {
            Tracing.TraceMsg("Entering GroupsSystemTest");

            GroupsQuery     query   = new GroupsQuery(ContactsQuery.CreateGroupsUri(this.userName + "@googlemail.com"));
            ContactsService service = new ContactsService("unittests");

            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.userName, this.passWord);
            }

            GroupsFeed feed = service.Query(query);

            int i = 0;

            foreach (GroupEntry g in feed.Entries)
            {
                if (g.SystemGroup != null)
                {
                    i++;
                }
            }

            Assert.IsTrue(i == 4, "There should be 4 system groups in the groups feed");


            ObjectModelHelper.DumpAtomObject(feed, CreateDumpFileName("GroupsAuthTest"));

            GroupEntry newGroup = new GroupEntry();

            newGroup.Title.Text = "Private Data";

            GroupEntry insertedGroup = feed.Insert(newGroup);

            GroupEntry g2 = new GroupEntry();

            g2.Title.Text = "Another Private Group";
            GroupEntry insertedGroup2 = feed.Insert(g2);

            // now insert a new contact that belongs to that group
            ContactsQuery   q      = new ContactsQuery(ContactsQuery.CreateContactsUri(this.userName + "@googlemail.com"));
            ContactsFeed    cf     = service.Query(q);
            ContactEntry    entry  = ObjectModelHelper.CreateContactEntry(1);
            GroupMembership member = new GroupMembership();

            member.HRef = insertedGroup.Id.Uri.ToString();
            GroupMembership member2 = new GroupMembership();

            member2.HRef = insertedGroup2.Id.Uri.ToString();

            ContactEntry insertedEntry = cf.Insert(entry);

            // now change the group membership
            insertedEntry.GroupMembership.Add(member);
            insertedEntry.GroupMembership.Add(member2);
            ContactEntry currentEntry = insertedEntry.Update();

            Assert.IsTrue(currentEntry.GroupMembership.Count == 2, "The entry should be in 2 groups");

            currentEntry.GroupMembership.Clear();
            currentEntry = currentEntry.Update();
            // now we should have 2 new groups and one new entry with no groups anymore

            int oldCountGroups   = feed.Entries.Count;
            int oldCountContacts = cf.Entries.Count;

            currentEntry.Delete();

            insertedGroup.Delete();
            insertedGroup2.Delete();

            feed = service.Query(query);
            cf   = service.Query(q);

            Assert.AreEqual(oldCountContacts, cf.Entries.Count, "Contacts count should be the same");
            Assert.AreEqual(oldCountGroups, feed.Entries.Count, "Groups count should be the same");
        }