/// <summary> /// Sets a postal address from the google contact into the std contact. /// </summary> /// <param name="stdEntry">The std entry to be updated.</param> /// <param name="address">The address to set.</param> public static void SetAddress(this StdContact stdEntry, StructuredPostalAddress address) { var stdAddress = new AddressDetail(address.FormattedAddress); if (address.Usage == "home") { if (stdEntry.PersonalAddressPrimary == null) { stdEntry.PersonalAddressPrimary = stdAddress; } else { stdEntry.PersonalAddressSecondary = stdAddress; } } if (address.Usage == "Work") { if (stdEntry.BusinessAddressPrimary == null) { stdEntry.BusinessAddressPrimary = stdAddress; } else { stdEntry.BusinessAddressSecondary = stdAddress; } } }
/// <summary> /// Adds a specific <see cref="AddressDetail"/> to the google address list of a google contact /// </summary> /// <param name="googleContact">The google contact.</param> /// <param name="stdAddress">The <see cref="AddressDetail"/> data from the <see cref="StdContact"/>.</param> /// <param name="addressType">A text type of address ("home", "work").</param> public static void AddAddress(this Contact googleContact, AddressDetail stdAddress, string addressType) { if (stdAddress == null) { return; } var addressText = stdAddress.ToString(AddressFormatting.StreetAndCity); if (!string.IsNullOrEmpty(addressText)) { var postalAddress = new StructuredPostalAddress { Street = stdAddress.StreetName, City = stdAddress.CityName, Rel = GoogleSchemaPrefix2005 + addressType, }; if (!IsAddressExisting(googleContact.PostalAddresses, stdAddress)) { googleContact.PostalAddresses.Add(postalAddress); } } googleContact.AddPhoneNumber(stdAddress.Phone, addressType); }
public static void WriteStructuredPostalAddress(this XmlWriter writer, StructuredPostalAddress postal) { if (postal != null) { if (!string.IsNullOrWhiteSpace(postal.Rel) || !string.IsNullOrWhiteSpace(postal.MailClass) || !string.IsNullOrWhiteSpace(postal.Usage) || !string.IsNullOrWhiteSpace(postal.Label) || postal.Primary.HasValue || !string.IsNullOrWhiteSpace(postal.Agent) || !string.IsNullOrWhiteSpace(postal.Housename) || !string.IsNullOrWhiteSpace(postal.Street) || !string.IsNullOrWhiteSpace(postal.Pobox) || !string.IsNullOrWhiteSpace(postal.Neighborhood) || !string.IsNullOrWhiteSpace(postal.City) || !string.IsNullOrWhiteSpace(postal.Subregion) || !string.IsNullOrWhiteSpace(postal.Region) || !string.IsNullOrWhiteSpace(postal.Postcode) || !string.IsNullOrWhiteSpace(postal.Country) || !string.IsNullOrWhiteSpace(postal.FormattedAddress)) { gdWriteStartElement(writer, "structuredPostalAddress"); gdWriteAttributeString(writer, "rel", postal.Rel); gdWriteAttributeString(writer, "mailClass", postal.MailClass); gdWriteAttributeString(writer, "usage", postal.Usage); gdWriteAttributeString(writer, "label", postal.Label); gdWriteAttributeString(writer, "primary", postal.Primary.Value.ToString()); gdWriteElementString(writer, "agent", postal.Agent); gdWriteElementString(writer, "housename", postal.Housename); gdWriteElementString(writer, "street", postal.Street); gdWriteElementString(writer, "pobox", postal.Pobox); gdWriteElementString(writer, "neighborhood", postal.Neighborhood); gdWriteElementString(writer, "city", postal.City); gdWriteElementString(writer, "subregion", postal.Subregion); gdWriteElementString(writer, "region", postal.Region); gdWriteElementString(writer, "postcode", postal.Postcode); gdWriteElementString(writer, "country", postal.Country); gdWriteElementString(writer, "formattedAddress", postal.FormattedAddress); writer.WriteEndElement(); } } }
public static StructuredPostalAddress CreatePostalAddress() { StructuredPostalAddress p = new StructuredPostalAddress(); p.City = "TestTown"; p.Street = "Rosanna Drive"; p.Postcode = "12345"; p.Country = "The good ole Country"; p.Primary = true; return(p); }
public static void SetAddresses(Outlook.ContactItem source, Contact destination) { destination.PostalAddresses.Clear(); if (!string.IsNullOrEmpty(source.HomeAddress)) { StructuredPostalAddress postalAddress = new StructuredPostalAddress(); postalAddress.Street = source.HomeAddressStreet; postalAddress.City = source.HomeAddressCity; postalAddress.Postcode = source.HomeAddressPostalCode; postalAddress.Country = source.HomeAddressCountry; postalAddress.Pobox = source.HomeAddressPostOfficeBox; postalAddress.Region = source.HomeAddressState; postalAddress.Primary = destination.PostalAddresses.Count == 0; postalAddress.Rel = ContactsRelationships.IsHome; //postalAddress.Subregion = source.home destination.PostalAddresses.Add(postalAddress); } if (!string.IsNullOrEmpty(source.BusinessAddress)) { StructuredPostalAddress postalAddress = new StructuredPostalAddress(); postalAddress.Street = source.BusinessAddressStreet; postalAddress.City = source.BusinessAddressCity; postalAddress.Postcode = source.BusinessAddressPostalCode; postalAddress.Country = source.BusinessAddressCountry; postalAddress.Pobox = source.BusinessAddressPostOfficeBox; postalAddress.Region = source.BusinessAddressState; postalAddress.Primary = destination.PostalAddresses.Count == 0; postalAddress.Rel = ContactsRelationships.IsWork; destination.PostalAddresses.Add(postalAddress); } if (!string.IsNullOrEmpty(source.OtherAddress)) { StructuredPostalAddress postalAddress = new StructuredPostalAddress(); postalAddress.Street = source.OtherAddressStreet; postalAddress.City = source.OtherAddressCity; postalAddress.Postcode = source.OtherAddressPostalCode; postalAddress.Country = source.OtherAddressCountry; postalAddress.Pobox = source.OtherAddressPostOfficeBox; postalAddress.Region = source.OtherAddressState; postalAddress.Primary = destination.PostalAddresses.Count == 0; postalAddress.Rel = ContactsRelationships.IsOther; destination.PostalAddresses.Add(postalAddress); } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>creates a new, in memory atom entry</summary> /// <returns>the new AtomEntry </returns> ////////////////////////////////////////////////////////////////////// public static ContactEntry CreateContactEntry(int iCount) { ContactEntry entry = new ContactEntry(); // some unicode chars Char[] chars = new Char[] { '\u0023', // # '\u0025', // % '\u03a0', // Pi '\u03a3', // Sigma '\u03d1', // beta }; // if unicode needs to be disabled for testing, just uncomment this line // chars = new Char[] { 'a', 'b', 'c', 'd', 'e'}; AtomPerson author = new AtomPerson(AtomPersonType.Author); author.Name = "John Doe" + chars[0] + chars[1] + chars[2] + chars[3]; author.Email = "*****@*****.**"; entry.Authors.Add(author); entry.Content.Content = "this is the default note for a contact entry"; entry.Published = new DateTime(2001, 11, 20, 22, 30, 0); entry.Title.Text = "This is a contact number: " + iCount; entry.Updated = DateTime.Now; // add an email. EMail email = new EMail("*****@*****.**" + Guid.NewGuid().ToString()); email.Primary = true; email.Rel = ContactsRelationships.IsWork; entry.Emails.Add(email); email = new EMail("*****@*****.**" + Guid.NewGuid().ToString()); email.Label = "some email"; entry.Emails.Add(email); IMAddress im = new IMAddress("*****@*****.**"); im.Primary = true; im.Rel = ContactsRelationships.IsWork; entry.IMs.Add(im); im = new IMAddress("*****@*****.**"); im.Rel = ContactsRelationships.IsHome; PhoneNumber p = new PhoneNumber("123-3453457"); p.Primary = true; p.Rel = ContactsRelationships.IsWork; entry.Phonenumbers.Add(p); p = new PhoneNumber("123-3334445"); p.Label = "some other thing"; entry.Phonenumbers.Add(p); StructuredPostalAddress pa = ContactsTestSuite.CreatePostalAddress(); 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 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); }
public static void SetPostalAddress(StructuredPostalAddress address, Outlook.ContactItem destination) { if (address.Rel == ContactsRelationships.IsHome) { destination.HomeAddressStreet = address.Street; destination.HomeAddressCity = address.City; destination.HomeAddressPostalCode = address.Postcode; destination.HomeAddressCountry = address.Country; destination.HomeAddressState = address.Region; destination.HomeAddressPostOfficeBox = address.Pobox; //Workaround because of Google bug: If a contact was created on GOOGLE side, it uses the unstructured approach //Therefore we need to check, if the structure was filled, if yes it resulted in a formatted string in the Address summary field //If not, the formatted string is null => overwrite it with the formmatedAddress from Google if (string.IsNullOrEmpty(destination.HomeAddress)) { destination.HomeAddress = address.FormattedAddress; } if (address.Primary) { destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olHome; } } else if (address.Rel == ContactsRelationships.IsWork) { destination.BusinessAddressStreet = address.Street; destination.BusinessAddressCity = address.City; destination.BusinessAddressPostalCode = address.Postcode; destination.BusinessAddressCountry = address.Country; destination.BusinessAddressState = address.Region; destination.BusinessAddressPostOfficeBox = address.Pobox; //Workaround because of Google bug: If a contact was created on GOOGLE side, it uses the unstructured approach //Therefore we need to check, if the structure was filled, if yes it resulted in a formatted string in the Address summary field //If not, the formatted string is null => overwrite it with the formmatedAddress from Google if (string.IsNullOrEmpty(destination.BusinessAddress)) { destination.BusinessAddress = address.FormattedAddress; } if (address.Primary) { destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olBusiness; } } else if (address.Rel == ContactsRelationships.IsOther) { destination.OtherAddressStreet = address.Street; destination.OtherAddressCity = address.City; destination.OtherAddressPostalCode = address.Postcode; destination.OtherAddressCountry = address.Country; destination.OtherAddressState = address.Region; destination.OtherAddressPostOfficeBox = address.Pobox; //Workaround because of Google bug: If a contact was created on GOOGLE side, it uses the unstructured approach //Therefore we need to check, if the structure was filled, if yes it resulted in a formatted string in the Address summary field //If not, the formatted string is null => overwrite it with the formmatedAddress from Google if (string.IsNullOrEmpty(destination.OtherAddress)) { destination.OtherAddress = address.FormattedAddress; } if (address.Primary) { destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olOther; } } }
public void CreateNewContact() { string gmailUsername; string syncProfile; LoadSettings(out gmailUsername, out syncProfile); ContactsRequest service; var scopes = new List <string>(); //Contacts-Scope scopes.Add("https://www.google.com/m8/feeds"); //Calendar-Scope 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); }
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); } } } }
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); } }
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"); } } StructuredPostalAddress p = CreatePostalAddress(); 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"); }
/// <summary> /// Merges the specified addresses. /// </summary> /// <param name="addresses">The addresses.</param> /// <param name="address">The address.</param> /// <returns>True if Changed.</returns> public static bool Merge(this ExtensionCollection<StructuredPostalAddress> addresses, StructuredPostalAddress address) { if (!string.IsNullOrWhiteSpace(address.Street) && !string.IsNullOrWhiteSpace(address.City) && !string.IsNullOrWhiteSpace(address.Postcode) && !string.IsNullOrWhiteSpace(address.Country) && !addresses.Any(e => (address.Street != null && address.Street.StartsWith(e.Street)) && e.City == address.City && e.Postcode == address.Postcode && e.Country == address.Country)) { addresses.Add(address); return true; } return false; }
public static void SetPostalAddress(StructuredPostalAddress address, Outlook.ContactItem destination) { if (address.Rel == ContactsRelationships.IsHome) { destination.HomeAddressStreet=address.Street; destination.HomeAddressCity=address.City; destination.HomeAddressPostalCode = address.Postcode; destination.HomeAddressCountry=address.Country; destination.HomeAddressState = address.Region; destination.HomeAddressPostOfficeBox = address.Pobox; //Workaround because of Google bug: If a contact was created on GOOGLE side, it uses the unstructured approach //Therefore we need to check, if the structure was filled, if yes it resulted in a formatted string in the Address summary field //If not, the formatted string is null => overwrite it with the formmatedAddress from Google if (string.IsNullOrEmpty(destination.HomeAddress)) destination.HomeAddress = address.FormattedAddress; if (address.Primary) destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olHome; } else if (address.Rel == ContactsRelationships.IsWork) { destination.BusinessAddressStreet = address.Street; destination.BusinessAddressCity = address.City; destination.BusinessAddressPostalCode = address.Postcode; destination.BusinessAddressCountry = address.Country; destination.BusinessAddressState = address.Region; destination.BusinessAddressPostOfficeBox = address.Pobox; //Workaround because of Google bug: If a contact was created on GOOGLE side, it uses the unstructured approach //Therefore we need to check, if the structure was filled, if yes it resulted in a formatted string in the Address summary field //If not, the formatted string is null => overwrite it with the formmatedAddress from Google if (string.IsNullOrEmpty(destination.BusinessAddress)) destination.BusinessAddress = address.FormattedAddress; if (address.Primary) destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olBusiness; } else if (address.Rel == ContactsRelationships.IsOther) { destination.OtherAddressStreet = address.Street; destination.OtherAddressCity = address.City; destination.OtherAddressPostalCode = address.Postcode; destination.OtherAddressCountry = address.Country; destination.OtherAddressState = address.Region; destination.OtherAddressPostOfficeBox = address.Pobox; //Workaround because of Google bug: If a contact was created on GOOGLE side, it uses the unstructured approach //Therefore we need to check, if the structure was filled, if yes it resulted in a formatted string in the Address summary field //If not, the formatted string is null => overwrite it with the formmatedAddress from Google if (string.IsNullOrEmpty(destination.OtherAddress)) destination.OtherAddress = address.FormattedAddress; if (address.Primary) destination.SelectedMailingAddress = Microsoft.Office.Interop.Outlook.OlMailingAddress.olOther; } }
/// <summary> /// Merges the specified addresses. /// </summary> /// <param name="addresses">The addresses.</param> /// <param name="address">The address.</param> /// <returns>True if Changed.</returns> public static bool Merge(this ExtensionCollection <StructuredPostalAddress> addresses, StructuredPostalAddress address) { if (!string.IsNullOrWhiteSpace(address.Street) && !string.IsNullOrWhiteSpace(address.City) && !string.IsNullOrWhiteSpace(address.Postcode) && !string.IsNullOrWhiteSpace(address.Country) && !addresses.Any(e => (address.Street != null && address.Street.StartsWith(e.Street)) && e.City == address.City && e.Postcode == address.Postcode && e.Country == address.Country)) { addresses.Add(address); return(true); } return(false); }
public static StructuredPostalAddress CreatePostalAddress() { StructuredPostalAddress p = new StructuredPostalAddress(); p.City = "TestTown"; p.Street = "Rosanna Drive"; p.Postcode = "12345"; p.Country = "The good ole Country"; p.Primary = true; return p; }