private void MapPhoto2To1(vCard source, ContactItem target, IEntityMappingLogger logger) { if (source.Photos.Count > 0) { if (target.HasPicture && _configuration.KeepOutlookPhoto) { return; } vCardPhoto contactPhoto = source.Photos[0]; if (contactPhoto.IsLoaded) { try { string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg"; File.WriteAllBytes(picturePath, contactPhoto.GetBytes()); try { target.AddPicture(picturePath); } catch (COMException x) { s_logger.Warn("Could not add picture for contact.", x); logger.LogMappingWarning("Could not add picture for contact.", x); } File.Delete(picturePath); } catch (Exception ex) { s_logger.Warn("Could not add picture for contact.", ex); logger.LogMappingWarning("Could not add picture for contact.", ex); } } } else { if (target.HasPicture) { try { target.RemovePicture(); } catch (COMException x) { s_logger.Warn("Could not remove picture for contact.", x); logger.LogMappingWarning("Could not remove picture for contact.", x); } } } }
private void MapPhoto2To1(GoogleContactWrapper source, ContactItem target, IEntityMappingLogger logger) { if (source.PhotoOrNull != null) { if (target.HasPicture && _configuration.KeepOutlookPhoto) { return; } try { string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg"; File.WriteAllBytes(picturePath, source.PhotoOrNull); try { target.AddPicture(picturePath); } catch (COMException x) { s_logger.Warn("Could not add picture for contact.", x); logger.LogMappingWarning("Could not add picture for contact.", x); } File.Delete(picturePath); } catch (System.Exception ex) { s_logger.Warn("Could not add picture for contact.", ex); logger.LogMappingWarning("Could not add picture for contact.", ex); } } else { if (target.HasPicture) { try { target.RemovePicture(); } catch (COMException x) { s_logger.Warn("Could not remove picture for contact.", x); logger.LogMappingWarning("Could not remove picture for contact.", x); } } } }
private async Task MapPhoto2To1(vCard source, ContactItem target, IEntitySynchronizationLogger logger) { if (source.Photos.Count > 0) { if (target.HasPicture && _configuration.KeepOutlookPhoto) { return; } vCardPhoto contactPhoto = source.Photos[0]; string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg"; try { if (!contactPhoto.IsLoaded && contactPhoto.Url != null) { using (var client = _webClientFactory()) { await client.DownloadFileTaskAsync(contactPhoto.Url, picturePath); } } else if (contactPhoto.IsLoaded) { File.WriteAllBytes(picturePath, contactPhoto.GetBytes()); } else { s_logger.Warn("Could not load picture for contact."); logger.LogWarning("Could not load picture for contact."); return; } try { target.AddPicture(picturePath); } catch (COMException x) { s_logger.Warn("Could not add picture for contact.", x); logger.LogWarning("Could not add picture for contact.", x); } File.Delete(picturePath); } catch (Exception ex) { s_logger.Warn("Could not add picture for contact.", ex); logger.LogWarning("Could not add picture for contact.", ex); } } else { if (target.HasPicture) { try { target.RemovePicture(); } catch (COMException x) { s_logger.Warn("Could not remove picture for contact.", x); logger.LogWarning("Could not remove picture for contact.", x); } } } }
public void RemovePicture() { contact.RemovePicture(); }