//////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void ContactsObjectModelTest()
        {
            Tracing.TraceMsg("Entering ContactsObjectModelTest");

            EMail email = new EMail("*****@*****.**");
            Assert.AreEqual(email.Address, "*****@*****.**", "constructor should have set address field");
        }
Exemplo n.º 2
0
        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)
            {

            }
        }
Exemplo n.º 3
0
        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 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");
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
 protected override bool internal_addMail(string mail)
 {
     if (_item.Emails.Where(m => m.Address.Equals(mail)).Count() > 0)
     {
         return false;
     }
     //System.Windows.Forms.MessageBox.Show("Adding " + mail + " as an email address for " + this.ToString() + ".");
     EMail theMail = new EMail(mail, ContactsRelationships.IsOther);
     _item.Emails.Add(theMail);
     return true;
 }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <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 void UpdateGoogleContactWithAvegaContactData(Contact contact, AvegaContact avegaContact) {
			contact.Title = avegaContact.DisplayName;

			contact.Phonenumbers.Clear();

			if (!string.IsNullOrEmpty(avegaContact.MobilePhone)) {
				PhoneNumber phoneNumber = new PhoneNumber(avegaContact.MobilePhone);
				phoneNumber.Primary = true;
				phoneNumber.Rel = ContactsRelationships.IsMobile;
				contact.Phonenumbers.Add(phoneNumber);
			}

            if (!string.IsNullOrEmpty(avegaContact.OfficePhone))
            {
				PhoneNumber workPhone = new PhoneNumber(avegaContact.OfficePhone);
				workPhone.Primary = false;
				workPhone.Rel = ContactsRelationships.IsWork;
				contact.Phonenumbers.Add(workPhone);
			}

            if (!string.IsNullOrEmpty(avegaContact.Email))
            {
				contact.Emails.Clear();
				EMail primaryEmail = new EMail(avegaContact.Email);
				primaryEmail.Primary = true;
				primaryEmail.Rel = ContactsRelationships.IsWork;
				contact.Emails.Add(primaryEmail);
			}
		}
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
            protected override void ProcessRecord()
            {
                var _domain = dgcGoogleContactsService.GetDomain(service.ContactsService);
                var _query = new ContactsQuery(ContactsQuery.CreateContactsUri(_domain));
                var _feed = service.ContactsService.Query(_query);
                foreach (ContactEntry _entry in _feed.Entries)
                {
                    if (_entry.SelfUri.Content == selfUri)
                    {

                        if (emailAddress != null)
                        {
                            var _primaryEmail = new EMail();
                            _primaryEmail.Address = emailAddress;
                            _primaryEmail.Primary = true;
                            _primaryEmail.Rel = ContactsRelationships.IsWork;
                            _entry.Emails.Add(_primaryEmail);
                        }

                        if (phoneNumber != null)
                        {
                            bool _exists = false;
                            foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                            {
                                if (_phEntry.Rel == ContactsRelationships.IsWork)
                                {
                                    _exists = true;
                                }
                            }
                            if (_exists == true)
                            {
                                foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                                {
                                    if (_phEntry.Rel == ContactsRelationships.IsWork)
                                    {
                                        _phEntry.Value = phoneNumber;
                                    }
                                }
                            }
                            else
                            {
                                var _phoneNumber = new PhoneNumber(phoneNumber);
                                _phoneNumber.Primary = true;
                                _phoneNumber.Rel = ContactsRelationships.IsWork;
                                _entry.Phonenumbers.Add(_phoneNumber);
                            }
                        }

                        if (homePhoneNumber != null)
                        {
                            bool _exists = false;
                            foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                            {
                                if (_phEntry.Rel == ContactsRelationships.IsHome)
                                {
                                    _exists = true;
                                }
                            }
                            if (_exists == true)
                            {
                                foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                                {
                                    if (_phEntry.Rel == ContactsRelationships.IsHome)
                                    {
                                        _phEntry.Value = homePhoneNumber;
                                    }
                                }
                            }
                            else
                            {
                                var _phoneNumber = new PhoneNumber(homePhoneNumber);
                                _phoneNumber.Primary = false;
                                _phoneNumber.Rel = ContactsRelationships.IsHome;
                                _entry.Phonenumbers.Add(_phoneNumber);

                            }
                        }

                        if (mobilePhoneNumber != null)
                        {
                            bool _exists = false;
                            foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                            {
                                if (_phEntry.Rel == ContactsRelationships.IsMobile)
                                {
                                    _exists = true;
                                }
                            }
                            if (_exists == true)
                            {
                                foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                                {
                                    if (_phEntry.Rel == ContactsRelationships.IsMobile)
                                    {
                                        _phEntry.Value = mobilePhoneNumber;
                                    }
                                }
                            }
                            else
                            {
                                var _phoneNumber = new PhoneNumber(mobilePhoneNumber);
                                _phoneNumber.Primary = false;
                                _phoneNumber.Rel = ContactsRelationships.IsMobile;
                                _entry.Phonenumbers.Add(_phoneNumber);
                            }
                        }

                        if (otherPhoneNumber != null)
                        {
                            bool _exists = false;
                            foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                            {
                                if (_phEntry.Rel == ContactsRelationships.IsOther)
                                {
                                    _exists = true;
                                }
                            }
                            if (_exists == true)
                            {
                                foreach (PhoneNumber _phEntry in _entry.Phonenumbers)
                                {
                                    if (_phEntry.Rel == ContactsRelationships.IsOther)
                                    {
                                        _phEntry.Value = otherPhoneNumber;
                                    }
                                }
                            }
                            else
                            {
                                var _phoneNumber = new PhoneNumber(otherPhoneNumber);
                                _phoneNumber.Primary = false;
                                _phoneNumber.Rel = ContactsRelationships.IsOther;
                                _entry.Phonenumbers.Add(_phoneNumber);
                            }
                        }

                        if (postalAddress != null)
                        {
                            bool _exists = false;
                            foreach (StructuredPostalAddress _poEntry in _entry.PostalAddresses)
                            {
                                if (_poEntry.Rel == ContactsRelationships.IsWork)
                                {
                                    _exists = true;
                                }
                            }
                            if (_exists == true)
                            {
                                foreach (StructuredPostalAddress _poEntry in _entry.PostalAddresses)
                                {
                                    if (_poEntry.Rel == ContactsRelationships.IsWork)
                                    {
                                        _poEntry.FormattedAddress = postalAddress;
                                    }
                                }
                            }
                            else
                            {
                                var _postalAddress = new StructuredPostalAddress();
                                _postalAddress.FormattedAddress = postalAddress;
                                _postalAddress.Primary = true;
                                _postalAddress.Rel = ContactsRelationships.IsWork;
                                _entry.PostalAddresses.Add(_postalAddress);
                            }
                        }

                        if (homePostalAddress != null)
                        {
                            bool _exists = false;
                            foreach (StructuredPostalAddress _poEntry in _entry.PostalAddresses)
                            {
                                if (_poEntry.Rel == ContactsRelationships.IsHome)
                                {
                                    _exists = true;
                                }
                            }
                            if (_exists == true)
                            {
                                foreach (StructuredPostalAddress _poEntry in _entry.PostalAddresses)
                                {
                                    if (_poEntry.Rel == ContactsRelationships.IsHome)
                                    {
                                        _poEntry.FormattedAddress = homePostalAddress;
                                    }
                                }
                            }
                            else
                            {
                                var _postalAddress = new StructuredPostalAddress();
                                _postalAddress.FormattedAddress = homePostalAddress;
                                _postalAddress.Primary = false;
                                _postalAddress.Rel = ContactsRelationships.IsHome;
                                _entry.PostalAddresses.Add(_postalAddress);
                            }
                        }

                        Uri _feedUri = new Uri(ContactsQuery.CreateContactsUri(_domain));

                        try
                        {
                            ContactEntry _updateEntry = (ContactEntry)service.ContactsService.Update(_entry);
                            if (name != null)
                            {
                                var _token = service.ContactsService.QueryClientLoginToken();
                                dgcGoogleContactsService.SetContactTitle(_token, _entry.SelfUri.ToString(), name);
                                var _contactEntry = dgcGoogleContactsService.CreateContactModifidEntry(_updateEntry, name);
                                WriteObject(_contactEntry);
                            }
                            else
                            {
                                var _contactEntry = dgcGoogleContactsService.CreateContactEntry(_updateEntry);
                                WriteObject(_contactEntry);
                            }
                        }
                        catch (Exception _exception)
                        {
                            WriteObject(_exception);
                        }
                    }
                }
            }
Exemplo n.º 11
0
            protected override void ProcessRecord()
            {
                var _newEntry = new ContactEntry();
                EMail _primaryEmail = new EMail();
                _primaryEmail.Address = emailAddress;
                _primaryEmail.Primary = true;
                _primaryEmail.Rel = ContactsRelationships.IsWork;
                _newEntry.Emails.Add(_primaryEmail);

                        if (phoneNumber != null)
                        {
                            var _phoneNumber = new PhoneNumber(phoneNumber);
                            _phoneNumber.Primary = true;
                            _phoneNumber.Rel = ContactsRelationships.IsWork;
                            _newEntry.Phonenumbers.Add(_phoneNumber);
                        }

                        if (homePhoneNumber != null)
                        {
                            var _phoneNumber = new PhoneNumber(homePhoneNumber);
                            _phoneNumber.Primary = false;
                            _phoneNumber.Rel = ContactsRelationships.IsHome;
                            _newEntry.Phonenumbers.Add(_phoneNumber);
                        }

                        if (mobilePhoneNumber != null)
                        {
                            var _phoneNumber = new PhoneNumber(mobilePhoneNumber);
                            _phoneNumber.Primary = false;
                            _phoneNumber.Rel = ContactsRelationships.IsMobile;
                            _newEntry.Phonenumbers.Add(_phoneNumber);
                        }

                        if (otherPhoneNumber != null)
                        {
                            var _phoneNumber = new PhoneNumber(otherPhoneNumber);
                            _phoneNumber.Primary = false;
                            _phoneNumber.Rel = ContactsRelationships.IsOther;
                            _newEntry.Phonenumbers.Add(_phoneNumber);
                        }

                        if (postalAddress != null)
                        {
                            var _postalAddress = new StructuredPostalAddress();
                            _postalAddress.FormattedAddress = postalAddress;
                            _postalAddress.Primary = true;
                            _postalAddress.Rel = ContactsRelationships.IsWork;
                            _newEntry.PostalAddresses.Add(_postalAddress);
                        }

                        if (homePostalAddress != null)
                        {
                            var _postalAddress = new StructuredPostalAddress();
                            _postalAddress.FormattedAddress = homePostalAddress;
                            _postalAddress.Primary = false;
                            _postalAddress.Rel = ContactsRelationships.IsWork;
                            _newEntry.PostalAddresses.Add(_postalAddress);
                        }

                var _domain = dgcGoogleContactsService.GetDomain(service.ContactsService);

                Uri _feedUri = new Uri(ContactsQuery.CreateContactsUri(_domain));
                try
                {
                    ContactEntry _entry = (ContactEntry)service.ContactsService.Insert(_feedUri, _newEntry);
                    var _token = service.ContactsService.QueryClientLoginToken();
                    dgcGoogleContactsService.SetContactTitle(_token,_entry.SelfUri.ToString(),name);
                    var _contactEntry = dgcGoogleContactsService.CreateContactModifidEntry(_entry, name);
                    WriteObject(_contactEntry);
                }
                catch (Exception _exception)
                {
                    WriteObject(_exception);
                }
            }
Exemplo n.º 12
0
 private static void AddEmail(Contact destination, string email, string label, string relationship)
 {
     if (email != null && !email.Trim().Equals(string.Empty))
     {
         EMail primaryEmail = new EMail(email);
         primaryEmail.Primary = destination.Emails.Count == 0;
         //Either label or relationship must be filled, if both filled, Google throws an error, prefer DisplayName, if empty, use relationship
         if (string.IsNullOrEmpty(label))
             primaryEmail.Rel = relationship;
         else
             primaryEmail.Label = label;
         destination.Emails.Add(primaryEmail);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Merges the specified emails.
        /// </summary>
        /// <param name="emails">The emails.</param>
        /// <param name="mail">The mail.</param>
        /// <returns>True if Changed.</returns>
        public static bool Merge(this ExtensionCollection<EMail> emails, EMail mail)
        {
            if (!string.IsNullOrWhiteSpace(mail.Address) && !emails.Any(e => e.Address == mail.Address))
            {
                emails.Add(mail);

                if (emails.Any() && !emails.Any(e => e.Primary))
                {
                    emails.First().Primary = true;
                }

                return true;
            }

            return false;
        }
Exemplo n.º 14
0
        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;
        }
Exemplo n.º 15
0
        public void CreateNewContact()
        {
            string gmailUsername;
            string syncProfile;
            GoogleAPITests.LoadSettings(out gmailUsername, out syncProfile);

            ContactsRequest service;

            var scopes = new List<string>();
            //Contacts-Scope
            scopes.Add("https://www.google.com/m8/feeds");
            //Notes-Scope
            scopes.Add("https://docs.google.com/feeds/");
            //scopes.Add("https://docs.googleusercontent.com/");
            //scopes.Add("https://spreadsheets.google.com/feeds/");
            //Calendar-Scope
            //scopes.Add("https://www.googleapis.com/auth/calendar");
            scopes.Add(CalendarService.Scope.Calendar);

            UserCredential credential;
            byte[] jsonSecrets = Properties.Resources.client_secrets;

            using (var stream = new MemoryStream(jsonSecrets))
            {
                FileDataStore fDS = new FileDataStore(Logger.AuthFolder, true);

                GoogleClientSecrets clientSecrets = GoogleClientSecrets.Load(stream);

                credential = GCSMOAuth2WebAuthorizationBroker.AuthorizeAsync(
                                clientSecrets.Secrets,
                                scopes.ToArray(),
                                gmailUsername,
                                CancellationToken.None,
                                fDS).
                                Result;

                OAuth2Parameters parameters = new OAuth2Parameters
                {
                    ClientId = clientSecrets.Secrets.ClientId,
                    ClientSecret = clientSecrets.Secrets.ClientSecret,

                    // Note: AccessToken is valid only for 60 minutes
                    AccessToken = credential.Token.AccessToken,
                    RefreshToken = credential.Token.RefreshToken
                };

                RequestSettings settings = new RequestSettings("GoContactSyncMod", parameters);

                service = new ContactsRequest(settings);
            }

            #region Delete previously created test contact.
            ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
            query.NumberToRetrieve = 500;

            Feed<Contact> feed = service.Get<Contact>(query);

            Logger.Log("Loaded Google contacts", EventType.Information);

            foreach (Contact entry in feed.Entries)
            {
                if (entry.PrimaryEmail != null && entry.PrimaryEmail.Address == "*****@*****.**")
                {
                    service.Delete(entry);
                    Logger.Log("Deleted Google contact", EventType.Information);
                    //break;
                }
            }
            #endregion

            Contact newEntry = new Contact();
            newEntry.Title = "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);

            StructuredPostalAddress postalAddress = new StructuredPostalAddress();
            postalAddress.Street = "123 somewhere lane";
            postalAddress.Primary = true;
            postalAddress.Rel = ContactsRelationships.IsHome;
            newEntry.PostalAddresses.Add(postalAddress);

            newEntry.Content = "Who is this guy?";

            Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));

            Contact createdEntry = service.Insert(feedUri, newEntry);

            Logger.Log("Created Google contact", EventType.Information);

            Assert.IsNotNull(createdEntry.ContactEntry.Id.Uri);

            Contact updatedEntry = service.Update(createdEntry);

            Logger.Log("Updated Google contact", EventType.Information);

            //delete test contacts
            service.Delete(createdEntry);

            Logger.Log("Deleted Google contact", EventType.Information);
        }