Esempio n. 1
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)
            {

            }
        }
Esempio n. 2
0
		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 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");
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        public static void SetPhoneNumber(PhoneNumber phone, Outlook.ContactItem destination)
        {
            if (phone.Rel == ContactsRelationships.IsHome)
                destination.HomeTelephoneNumber = phone.Value;
            if (phone.Rel == ContactsRelationships.IsWork)
                destination.BusinessTelephoneNumber = phone.Value;
            if (phone.Rel == ContactsRelationships.IsMobile)
            {
                destination.MobileTelephoneNumber = phone.Value;
                //destination.PrimaryTelephoneNumber = phone.Value;
            }
            if (phone.Rel == ContactsRelationships.IsWorkFax)
                destination.BusinessFaxNumber = phone.Value;
            if (phone.Rel == ContactsRelationships.IsHomeFax)
                destination.HomeFaxNumber = phone.Value;

            if (phone.Rel == ContactsRelationships.IsPager)
                destination.PagerNumber = phone.Value;
            if (phone.Rel == ContactsRelationships.IsSatellite)
                destination.RadioTelephoneNumber = phone.Value;
            if (phone.Rel == ContactsRelationships.IsOther)
                destination.OtherTelephoneNumber = phone.Value;
            if (phone.Rel == ContactsRelationships.IsCar)
                destination.CarTelephoneNumber = phone.Value;
            if (phone.Rel == ContactsRelationships.IsVoip)
                destination.Business2TelephoneNumber = phone.Value;
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <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);
			}
		}
        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;
        }
Esempio n. 9
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);
                        }
                    }
                }
            }
Esempio n. 10
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);
                }
            }
Esempio n. 11
0
        public static void SetPhoneNumbers(Outlook.ContactItem source, Contact destination)
        {
            destination.Phonenumbers.Clear();

            if (!string.IsNullOrEmpty(source.PrimaryTelephoneNumber))
            {
                //ToDo: Temporary cleanup algorithm to get rid of duplicate primary phone numbers
                //Can be removed once the contacts are clean for all users:
                //if (source.PrimaryTelephoneNumber.Equals(source.MobileTelephoneNumber))
                //{
                //    //Reset primary TelephoneNumber because it is duplicate, and maybe even MobilePhone Number if duplicate
                //    source.PrimaryTelephoneNumber = string.Empty;
                //    if (source.MobileTelephoneNumber.Equals(source.HomeTelephoneNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.Home2TelephoneNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.BusinessTelephoneNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.Business2TelephoneNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.HomeFaxNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.BusinessFaxNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.OtherTelephoneNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.PagerNumber) ||
                //        source.MobileTelephoneNumber.Equals(source.CarTelephoneNumber))
                //    {
                //        source.MobileTelephoneNumber = string.Empty;
                //    }

                //}
                //else if (source.PrimaryTelephoneNumber.Equals(source.HomeTelephoneNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.Home2TelephoneNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.BusinessTelephoneNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.Business2TelephoneNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.HomeFaxNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.BusinessFaxNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.OtherTelephoneNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.PagerNumber) ||
                //        source.PrimaryTelephoneNumber.Equals(source.CarTelephoneNumber))
                //{
                //    //Reset primary TelephoneNumber because it is duplicate
                //    source.PrimaryTelephoneNumber = string.Empty;
                //}
                //else
                //{
                    PhoneNumber phoneNumber = new PhoneNumber(source.PrimaryTelephoneNumber);
                    phoneNumber.Primary = destination.Phonenumbers.Count == 0;
                    phoneNumber.Rel = ContactsRelationships.IsMain;
                    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.Home2TelephoneNumber))
            {
                PhoneNumber phoneNumber = new PhoneNumber(source.Home2TelephoneNumber);
                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);
            }

            //ToDo: Currently IsSatellite is returned as invalid Rel value
            //if (!string.IsNullOrEmpty(source.RadioTelephoneNumber))
            //{
            //    PhoneNumber phoneNumber = new PhoneNumber(source.RadioTelephoneNumber);
            //    phoneNumber.Primary = destination.Phonenumbers.Count == 0;
            //    phoneNumber.Rel = ContactsRelationships.IsSatellite;
            //    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);
            }

            if (!string.IsNullOrEmpty(source.AssistantTelephoneNumber))
            {
                PhoneNumber phoneNumber = new PhoneNumber(source.AssistantTelephoneNumber);
                phoneNumber.Primary = destination.Phonenumbers.Count == 0;
                phoneNumber.Rel = ContactsRelationships.IsAssistant;
                destination.Phonenumbers.Add(phoneNumber);
            }
        }
Esempio n. 12
0
 public static void SetPhoneNumber(PhoneNumber phone, Outlook.ContactItem destination)
 {
     //if (phone.Primary)
     if (phone.Rel == ContactsRelationships.IsMain)
         destination.PrimaryTelephoneNumber = phone.Value;
     else if (phone.Rel == ContactsRelationships.IsHome)
     {
         if (destination.HomeTelephoneNumber == null)
             destination.HomeTelephoneNumber = phone.Value;
         else
             destination.Home2TelephoneNumber = phone.Value;
     }
     else if (phone.Rel == ContactsRelationships.IsWork)
     {
         if (destination.BusinessTelephoneNumber == null)
             destination.BusinessTelephoneNumber = phone.Value;
         else
             destination.Business2TelephoneNumber = phone.Value;
     }
     else if (phone.Rel == ContactsRelationships.IsMobile)
     {
         destination.MobileTelephoneNumber = phone.Value;
         //destination.PrimaryTelephoneNumber = phone.Value;
     }
     else if (phone.Rel == ContactsRelationships.IsWorkFax)
         destination.BusinessFaxNumber = phone.Value;
     else if (phone.Rel == ContactsRelationships.IsHomeFax)
         destination.HomeFaxNumber = phone.Value;
     else if (phone.Rel == ContactsRelationships.IsPager)
         destination.PagerNumber = phone.Value;
     //else if (phone.Rel == ContactsRelationships.IsSatellite)
     //    destination.RadioTelephoneNumber = phone.Value;
     else if (phone.Rel == ContactsRelationships.IsOther)
         destination.OtherTelephoneNumber = phone.Value;
     else if (phone.Rel == ContactsRelationships.IsCar)
         destination.CarTelephoneNumber = phone.Value;
     else if (phone.Rel == ContactsRelationships.IsAssistant)
         destination.AssistantTelephoneNumber = phone.Value;
     //else if (phone.Rel == ContactsRelationships.IsVoip)
     //    destination.Business2TelephoneNumber = phone.Value;
     //else no phone category matches
 }
Esempio n. 13
0
        /// <summary>
        /// Merges the specified phone numbers.
        /// </summary>
        /// <param name="phoneNumbers">The phone numbers.</param>
        /// <param name="phone">The phone.</param>
        /// <returns>True if Changed.</returns>
        public static bool Merge(this ExtensionCollection<PhoneNumber> phoneNumbers, PhoneNumber phone)
        {
            if (!string.IsNullOrWhiteSpace(phone.Value) && !phoneNumbers.Any(e => e.Value.FormatPhoneClean() == phone.Value.FormatPhoneClean()))
            {
                phoneNumbers.Add(phone);

                return true;
            }

            return false;
        }
 private string GetPhoneNumberDescription(PhoneNumber pn)
 {
     if (pn == null)
     {
         return "(unset)";
     }
     return pn.Value;
 }
Esempio n. 15
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);
            }
        }
        private void UpdatePhoneNumber(PhoneNumber existingPhoneNumber, string numberType, Contact googleContact, string newPhoneNumber)
        {
            if (existingPhoneNumber == null)
            {
                existingPhoneNumber = new PhoneNumber();
                existingPhoneNumber.Rel = numberType;
                googleContact.Phonenumbers.Add(existingPhoneNumber);
            }

            if (!string.IsNullOrWhiteSpace(newPhoneNumber))
            {
                existingPhoneNumber.Value = newPhoneNumber;
            }
            else
            {
                googleContact.Phonenumbers.Remove(existingPhoneNumber);
            }
        }
Esempio n. 17
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);
        }