/// <summary> /// Delete contact /// </summary> /// <param name="contact"></param> public void Delete(Google.Contacts.Contact contact) { try { cr.Delete(contact); // _isUpdated = true; LoggerProvider.Instance.Logger.Debug("Contact delete sucesfull"); } catch (GDataRequestException e) { Stream receiver = e.Response.GetResponseStream(); if (receiver != null) { // Pipe the stream to ahigher level stream reader with the default encoding // format. which is UTF8 StreamReader readStream = new StreamReader(receiver); // Read 256 charcters at a time. char[] buffer = new char[256]; StringBuilder builder = new StringBuilder(1024); int count = readStream.Read(buffer, 0, 256); while (count > 0) { builder.Append(buffer); count = readStream.Read(buffer, 0, 256); } // Release the resources of stream object. readStream.Close(); receiver.Close(); LoggerProvider.Instance.Logger.Error(builder.ToString()); LoggerProvider.Instance.Logger.Error(e); } } }
/// <summary> /// Add one contact to Google /// </summary> /// <param name="c">Outlook contact to add</param> /// <returns>true if add success</returns> internal bool AddNewGoogleContact(OneContact c) { Google.Contacts.Contact goContact = null; #warning There is a problem with add google contact with Image #if (!SIMULATE_SAVE) Google.Contacts.Contact goContactNew = null; OneContact hlp = null; #endif try { goContact = c.GetGoogle(); } catch (Exception e) { /// Can't create Google Entity from OneContacs Class LoggerProvider.Instance.Logger.Error("Problem to read Google.Contacts.Contact from GoogleSynchronizer.OneContact"); LoggerProvider.Instance.Logger.Error(e); return(false);; } if (goContact == null) { LoggerProvider.Instance.Logger.Error("Can't insert NULL object"); return(false); } #if (!SIMULATE_SAVE) goContactNew = GoogleProvider.GetProvider.Insert(goContact); // If don't insert new contact to Google need continue if (goContactNew == null) { return(false); } #endif #if (!SIMULATE_SAVE) hlp = new OneContact(goContactNew); c.ReferenceID = hlp.ContactID; goContacts.Add(hlp.ContactID, hlp); c.UpdateRefInOutlook(hlp.CreateReferenceID()); #endif LoggerProvider.Instance.Logger.Debug("Save update to Outlook"); #region DEBUG infos #if (DEBUG1) LoggerProvider.Instance.Logger.Debug("Source contact MD5/Count MD5: {0}/{1}", c.MD5selfCount, Utils.CountMD5(c.SummAllData())); LoggerProvider.Instance.Logger.Debug(c.SummAllData()); LoggerProvider.Instance.Logger.Debug("Destination contact MD5/Count MD5: {0}/{1}", hlp.MD5selfCount, Utils.CountMD5(hlp.SummAllData())); LoggerProvider.Instance.Logger.Debug(hlp.SummAllData()); hlp = null; #endif #endregion return(true); }
/// <summary> /// Delete photo from Google contact /// </summary> /// <param name="contact"></param> public void DeleteContactPhoto(Google.Contacts.Contact contact) { try { cr.Delete(contact.PhotoUri, contact.PhotoEtag); } catch (GDataVersionConflictException e) { LoggerProvider.Instance.Logger.Error("Problem in delete photo"); LoggerProvider.Instance.Logger.Error(e); } }
public bool IsMatch(Google.Contacts.Contact contact) { if (this.FirstName == contact.Name.GivenName && (contact.Name.FamilyName == null || this.LastName == contact.Name.FamilyName) && (contact.Organizations.FirstOrDefault() == null || this.CompanyName == contact.Organizations.FirstOrDefault().Name) && (contact.Organizations.FirstOrDefault() == null || this.JobTitle == contact.Organizations.FirstOrDefault().JobDescription) && (contact.Phonenumbers.FirstOrDefault() == null || this.PhoneNumber == contact.Phonenumbers.FirstOrDefault().Value)) { return(true); } return(false); }
/// <summary> /// Add or Update photo in RAW Google contact /// </summary> /// <param name="contact"></param> /// <param name="photoContact"></param> public Google.Contacts.Contact AddOrUpdateContactPhoto(Google.Contacts.Contact contact, string photoPath) { using (Stream s = new FileStream(photoPath, FileMode.Open)) { LoggerProvider.Instance.Logger.Debug("Start upload picture to Google contact: {0}", photoPath); string et = contact.PhotoEtag; try { cr.SetPhoto(contact, s); contact = cr.Retrieve <Google.Contacts.Contact>(new Uri(contact.Id)); } catch (GDataVersionConflictException e) { LoggerProvider.Instance.Logger.Error("Problem in Update photo"); LoggerProvider.Instance.Logger.Error(e); } catch (ArgumentNullException ee) { LoggerProvider.Instance.Logger.Error("Problem in Update photo"); LoggerProvider.Instance.Logger.Error(ee); } catch (GDataRequestException ge) { using (Stream receiver = ge.Response.GetResponseStream()) { if (receiver != null) { StringBuilder builder = new StringBuilder(1024); using (StreamReader readStream = new StreamReader(receiver)) { char[] buffer = new char[256]; int count = readStream.Read(buffer, 0, 256); while (count > 0) { builder.Append(buffer); count = readStream.Read(buffer, 0, 256); } readStream.Close(); } receiver.Close(); LoggerProvider.Instance.Logger.Error("Error in Add or Update image to Google Contact.\r\n{0}", builder.ToString()); LoggerProvider.Instance.Logger.Error(ge); } } } LoggerProvider.Instance.Logger.Debug("Old/New Etag is: {0}/{1}", et, contact.PhotoEtag); } return(contact); }
/// <summary> /// Insert new contact to Google and return it's references /// </summary> /// <param name="contact"></param> /// <returns></returns> public Google.Contacts.Contact Insert(Google.Contacts.Contact contact) { Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default")); Google.Contacts.Contact ret = null; try { ret = cr.Insert(feedUri, contact); // _isUpdated = true; LoggerProvider.Instance.Logger.Debug("New contact inserted sucessful"); } catch (GDataRequestException e) { Stream receiver = e.Response.GetResponseStream(); if (receiver != null) { // Pipe the stream to ahigher level stream reader with the default encoding // format. which is UTF8 StreamReader readStream = new StreamReader(receiver); // Read 256 charcters at a time. char[] buffer = new char[256]; StringBuilder builder = new StringBuilder(1024); int count = readStream.Read(buffer, 0, 256); while (count > 0) { builder.Append(buffer); count = readStream.Read(buffer, 0, 256); } // Release the resources of stream object. readStream.Close(); receiver.Close(); LoggerProvider.Instance.Logger.Error(builder.ToString()); LoggerProvider.Instance.Logger.Error(e); } } return(ret); }
/// <summary> /// Return Image for specific contact /// </summary> /// <param name="contact"></param> /// <returns></returns> public Image GetImage(Google.Contacts.Contact contact) { Image img = null; try { contact.PhotoEtag = ""; using (Stream photoStream = cr.GetPhoto(contact)) img = Image.FromStream(photoStream); } catch (GDataNotModifiedException gd) { LoggerProvider.Instance.Logger.Error("Problem when read data (GDataNotModifiedException)"); LoggerProvider.Instance.Logger.Error(gd); } catch (GDataRequestException re) { LoggerProvider.Instance.Logger.Error("Problem when read data (GDataRequestException)"); LoggerProvider.Instance.Logger.Error(re); } return(img); }
/// <summary> /// Return image photo saved on HDD /// </summary> /// <param name="contact"></param> /// <returns></returns> public static string GetContactPicturePath(Google.Contacts.Contact contact) { string picturePath = CreateContactPictureName(contact); if (File.Exists(picturePath)) { if (File.GetCreationTime(picturePath) >= contact.Updated) { return(picturePath); } CleanupContactPictures(picturePath); } Image image = GoogleProvider.GetProvider.GetImage(contact); if (image != null) { LoggerProvider.Instance.Logger.Debug(string.Format("Try write image to:[{0}]", picturePath)); image.Save(picturePath); return(picturePath); } LoggerProvider.Instance.Logger.Error("Proble read image from Google {0}", picturePath); return(""); }
/// <summary> /// Create name for Contact picture from Google /// </summary> /// <param name="contact"></param> /// <returns></returns> public static string CreateContactPictureName(Google.Contacts.Contact contact) { Uri ur = new Uri(contact.Id); return(Path.Combine(Path.GetDirectoryName(PathToTempPicture()), string.Format(Constants.FormatImageCacheGoogle, ur.Segments[ur.Segments.Length - 1]))); }
/// <summary> /// Converts the current VPContact to a Google Contact class. /// If the user is new, a new contact is created, if the Google Contact /// is entered, it will update that. /// </summary> /// <returns></returns> public Google.Contacts.Contact GetGoogleContact() { if (GoogleContact == null) { GoogleContact = new Google.Contacts.Contact(); } //Name & Nick Name name = new Name(); if (!string.IsNullOrEmpty(NameFamily)) { name.FamilyName = NameFamily; } if (!string.IsNullOrEmpty(NameGiven)) { name.GivenName = NameGiven; } if (!string.IsNullOrEmpty(NameFull)) { name.FullName = NameFull; } if (!string.IsNullOrEmpty(NameFamily) || !string.IsNullOrEmpty(NameGiven) || !string.IsNullOrEmpty(NameFull)) { GoogleContact.Name = name; } if (GoogleContact.ContactEntry != null && !string.IsNullOrEmpty(Initials)) { GoogleContact.ContactEntry.Nickname = Initials; } //organization if (GoogleContact.Organizations != null) { GoogleContact.Organizations.Clear(); } Organization org = new Organization(); if (!string.IsNullOrEmpty(Department)) { org.Name = Department; } if (!string.IsNullOrEmpty(WorkTitle)) { org.Title = WorkTitle; } if (!string.IsNullOrEmpty(Department) || !string.IsNullOrEmpty(WorkTitle)) { org.Label = "Vestas"; org.Primary = true; GoogleContact.Organizations.Add(org); } //Emails if (GoogleContact.Emails != null) { GoogleContact.Emails.Clear(); } if (!string.IsNullOrEmpty(EmailPrivate)) { GoogleContact.Emails.Add(new EMail { Address = EmailPrivate, Rel = "http://schemas.google.com/g/2005#home" }); } if (!string.IsNullOrEmpty(EmailWork)) { GoogleContact.Emails.Add(new EMail { Address = EmailWork, Primary = true, Rel = "http://schemas.google.com/g/2005#work" }); } //Phone if (GoogleContact.Phonenumbers != null) { GoogleContact.Phonenumbers.Clear(); } if (!string.IsNullOrEmpty(PhoneWorkLandline)) { GoogleContact.Phonenumbers.Add(new PhoneNumber { Rel = ContactsRelationships.IsWork, Value = PhoneWorkLandline }); } if (!string.IsNullOrEmpty(PhoneWorkMobile)) { GoogleContact.Phonenumbers.Add(new PhoneNumber { Rel = ContactsRelationships.IsWorkMobile, Value = PhoneWorkMobile, Primary = true }); } if (!string.IsNullOrEmpty(PhonePrivateMobile)) { GoogleContact.Phonenumbers.Add(new PhoneNumber { Rel = ContactsRelationships.IsMobile, Value = PhonePrivateMobile }); } return(GoogleContact); }
internal static string GetTitleFirstLastAndSuffix(Google.Contacts.Contact googleContact) { return(GetTitleFirstLastAndSuffix(googleContact.Name.NamePrefix, googleContact.Name.GivenName, googleContact.Name.AdditionalName, googleContact.Name.FamilyName, googleContact.Name.NameSuffix)); }