/// <summary> /// doenloads the image for a contact /// </summary> /// <param name="stdEntry">The std entry.</param> /// <param name="googleContact">The google contact.</param> /// <param name="requester">The requester.</param> public static void SetPicture(this StdContact stdEntry, Contact googleContact, ContactsRequest requester) { if (googleContact == null || googleContact.PhotoUri == null) { return; } try { using (var stream = requester.GetPhoto(googleContact)) { if (stream != null) { var value = new StreamReader(stream).ReadToEnd(); stdEntry.PictureData = Encoding.ASCII.GetBytes(value); } } } catch (GDataNotModifiedException) { var helper = HttpHelper.DefaultInstance; helper.ContentCredentials.LogOnDomain = "[GOOGLE]"; helper.ContentCredentials.LogOnPassword = ((GDataGAuthRequestFactory)requester.Service.RequestFactory).GAuthToken; stdEntry.PictureData = helper.GetContentBinary(googleContact.PhotoUri.AbsoluteUri, string.Empty, string.Empty); } }
public Stream GetGooglePhoto(Contact c) { try { return(_google.GetPhoto(c)); } catch (Exception) { return(null); } }
public void DownloadPhoto(Uri contactURL) { Google.Contacts.Contact contact = cr.Retrieve <Google.Contacts.Contact>(contactURL); Stream photoStream = cr.GetPhoto(contact); FileStream outStream = File.OpenWrite("test.jpg"); byte[] buffer = new byte[photoStream.Length]; photoStream.Read(buffer, 0, (int)photoStream.Length); outStream.Write(buffer, 0, (int)photoStream.Length); photoStream.Close(); outStream.Close(); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs an authentication test, inserts a new contact</summary> ////////////////////////////////////////////////////////////////////// [Test] public void ModelPhotoTest() { Tracing.TraceMsg("Entering ModelPhotoTest"); RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed <Contact> f = cr.GetContacts(); Contact e = null; if (f != null) { Contact entry = new Contact(); entry.AtomEntry = ObjectModelHelper.CreateContactEntry(1); entry.PrimaryEmail.Address = "*****@*****.**"; e = cr.Insert(f, entry); } Assert.IsTrue(e != null, "we should have a contact here"); Stream s = cr.GetPhoto(e); Assert.IsTrue(s == null, "There should be no photo yet"); using (FileStream fs = new FileStream(this.resourcePath + "contactphoto.jpg", System.IO.FileMode.Open)) { cr.SetPhoto(e, fs); } // now delete the guy, which requires us to reload him from the server first, as the photo change operation // changes the etag off the entry e = cr.Retrieve(e); cr.Delete(e); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs an authentication test, inserts a new contact</summary> ////////////////////////////////////////////////////////////////////// [Test] public void ModelPhotoTest() { Tracing.TraceMsg("Entering ModelPhotoTest"); RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed<Contact> f = cr.GetContacts(); Contact e = null; if (f != null) { Contact entry = new Contact(); entry.AtomEntry = ObjectModelHelper.CreateContactEntry(1); entry.PrimaryEmail.Address = "*****@*****.**"; e = cr.Insert(f, entry); } Assert.IsTrue(e!=null, "we should have a contact here"); Stream s = cr.GetPhoto(e); Assert.IsTrue(s == null, "There should be no photo yet"); using (FileStream fs = new FileStream(this.resourcePath + "contactphoto.jpg", System.IO.FileMode.Open)) { cr.SetPhoto(e, fs); } // now delete the guy, which requires us to reload him from the server first, as the photo change operation // changes the etag off the entry e = cr.Retrieve(e); cr.Delete(e); }