示例#1
0
        public List <Photo> GetListFor(string albumId)
        {
            var service = new PicasaService("GPhotoSync");

            service.SetAuthenticationToken(_credentials.AccessToken);

            var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(_credentials.User, albumId));

            query.ExtraParameters = "imgmax=d";
            var feed = service.Query(query);

            if (feed != null)
            {
                var list = feed.Entries
                           .OfType <PicasaEntry>()
                           .Select(x =>
                {
                    var accessor = new PhotoAccessor(x);

                    return(new Photo
                    {
                        Id = accessor.Id,
                        Title = accessor.PhotoTitle,
                        Path = x.Media.Content.Url
                    });
                });

                return(list.OfType <Photo>().ToList());
            }
            else
            {
                return(new List <Photo>());
            }
        }
示例#2
0
    public string uploadImageToGoogle(string path, string username, string password, string blogId)
    {
        if (!System.IO.File.Exists(path))
        {
            return("Error! Image file not found");
        }
        ///////////////////////token session and shits...///////////
        PicasaService service = new PicasaService("HowToFixPRO");

        service.setUserCredentials(username, password);
        /////////////////cdefault album is dropBox or something////
        Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(username));

        System.IO.FileInfo   fileInfo   = new System.IO.FileInfo(path);
        System.IO.FileStream fileStream = fileInfo.OpenRead();

        PicasaEntry entry = (PicasaEntry)service.Insert(postUri, fileStream, "image/png", "nameOfYourFile");

        fileStream.Close();

        PhotoAccessor ac         = new PhotoAccessor(entry);
        string        contentUrl = entry.Media.Content.Attributes["url"] as string;

        return(contentUrl);
    }
示例#3
0
        public PicasaWebPhoto(PicasaEntry photo, string albumName)
        {
            PhotoAccessor pa = new PhotoAccessor(photo);

            this.m_accessId  = pa.Id;
            this.m_media     = photo.Media;
            this.m_id        = photo.Id.Uri.ToString();
            this.m_title     = photo.Title.Text;
            this.m_albumName = albumName;
            this.m_height    = pa.Height;
            this.m_width     = pa.Width;
            this.m_uploaded  = photo.Updated.ToShortDateString() + " " + photo.Updated.ToShortTimeString();
            this.m_location  = (string)photo.Media.Content.Attributes["url"];
            pa = null;
        }
示例#4
0
        public async Task <ActionResult> DeleteEventPhoto(Guid eventId, Guid photoId)
        {
            var evt = await UnitOfWork.Events.GetWithRelated(eventId, e => e.Photos);

            if (evt == null)
            {
                throw new RestError(HttpStatusCode.NotFound, new { Event = "Event not found" });
            }

            var userId = Guid.Parse(HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);

            if (evt.HostId != userId)
            {
                throw new RestError(HttpStatusCode.NotFound, new { Event = "Event not found..." });
            }

            Photo photo = evt.Photos.FirstOrDefault(p => p.Id == photoId);

            if (photo == null)
            {
                throw new RestError(HttpStatusCode.NotFound, new { Photo = "Photo not found" });
            }

            if (photo.IsMain)
            {
                throw new RestError(HttpStatusCode.BadRequest, new { Photo = "You can't delete the event's main photo" });
            }

            string result = PhotoAccessor.DeletePhoto(photo.PublicId);

            if (result == "ok")
            {
                // evt.Photos.Remove(photo); //only removes relation

                UnitOfWork.Photos.Remove(photo);

                await UnitOfWork.CompleteAsync();
            }
            else
            {
                throw new Exception(result);
            }

            return(NoContent());
        }
示例#5
0
        public async Task <ActionResult <AddEventPhotoResponseResource> > AddEventPhoto([FromForm] AddEventPhotoResource resource)
        {
            var evt = await UnitOfWork.Events.GetWithRelated(resource.EventId, e => e.Photos);

            if (evt == null)
            {
                throw new RestError(HttpStatusCode.NotFound, new { Event = "Event not found" });
            }

            var userId = Guid.Parse(HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);

            if (evt.HostId != userId)
            {
                throw new RestError(HttpStatusCode.NotFound, new { Event = "Event not found..." });
            }

            PhotoUploadResult result = PhotoAccessor.AddPhoto(resource.File);

            bool isMain = !evt.Photos.Any(p => p.IsMain == true);

            Photo photo = new Photo()
            {
                CreatedAt = DateTime.Now,
                IsMain    = isMain,
                PublicId  = result.PublicId,
                Url       = result.Url
            };

            evt.Photos.Add(photo);

            await UnitOfWork.CompleteAsync();

            var response = new AddEventPhotoResponseResource()
            {
                IsMain   = isMain,
                PublicId = photo.PublicId,
                Url      = photo.Url,
                EventId  = evt.Id
            };

            return(Ok(response));
        }
 private string UploadPhoto()
 {
     try
     {
         PicasaService service = new PicasaService("picasaupload");
         service.setUserCredentials(user.email, user.password);
         var         file       = "screenshot.png";
         var         fileStream = new FileStream(file, FileMode.Open);
         PicasaEntry entry      = (PicasaEntry)service.Insert(new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default"), fileStream, "image/jpeg", file);
         fileStream.Close();
         PhotoAccessor  ac           = new PhotoAccessor(entry);
         string         albumId      = ac.AlbumId;
         string         photoId      = ac.Id;
         string         contentUrl   = entry.Media.Content.Attributes["url"] as string;
         ThreadDelegate UploadFinish = delegate()
         {
             client.pid        = photoId;
             client.uploading  = false;
             label1.Opacity    = 0;
             button1.IsEnabled = true;
             button1.Content   = "Share";
             return("succeed");
         };
         this.Dispatcher.BeginInvoke(DispatcherPriority.Send, UploadFinish);
         return("succeed");
     }
     catch (Exception ex)
     {
         ThreadDelegate UploadFinish = delegate()
         {
             label1.Content   = "Upload failed";
             client.uploading = false;
             return("fail");
         };
         this.Dispatcher.BeginInvoke(DispatcherPriority.Send, UploadFinish);
         return("fail");
     }
 }
        public static PicasaInfo RetrievePicasaInfo(PicasaEntry picasaEntry)
        {
            PhotoAccessor photoAccessor = new PhotoAccessor(picasaEntry);

            LOG.InfoFormat("Retrieving Picasa info for {0}", photoAccessor.Id);

            PicasaInfo picasaInfo = new PicasaInfo();

            picasaInfo.ID                 = photoAccessor.Id;
            picasaInfo.Title              = picasaEntry.Title.Text;
            picasaInfo.Timestamp          = picasaEntry.Updated;
            picasaInfo.Description        = picasaEntry.Summary.Text;
            picasaInfo.SquareThumbnailUrl = picasaEntry.Media.Thumbnails[0].Url;
            picasaInfo.OriginalUrl        = picasaEntry.Media.Content.Url;

            List <AtomLink> links = picasaEntry.Links.Where(r => r.Type.Equals("text/html", StringComparison.OrdinalIgnoreCase)).ToList();

            picasaInfo.WebUrl = string.Empty;
            if (links.Count > 0)
            {
                picasaInfo.WebUrl = links.First().HRef.ToString();
            }
            return(picasaInfo);
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, iterates all entries</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void QueryPhotosTest()
        {
            Tracing.TraceMsg("Entering PhotosQueryPhotosTest");

            PhotoQuery    query   = new PhotoQuery();
            PicasaService service = new PicasaService("unittests");

            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                GDataLoggingRequestFactory factory = (GDataLoggingRequestFactory)this.factory;
                factory.MethodOverride = true;
                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.defaultPhotosUri);
                PicasaFeed feed = service.Query(query);

                ObjectModelHelper.DumpAtomObject(feed, CreateDumpFileName("PhotoAuthTest"));

                if (feed != null && feed.Entries.Count > 0)
                {
                    Tracing.TraceMsg("Found a Feed " + feed.ToString());
                    DisplayExtensions(feed);

                    foreach (PicasaEntry entry in feed.Entries)
                    {
                        Tracing.TraceMsg("Found an entry " + entry.ToString());
                        DisplayExtensions(entry);

                        GeoRssWhere w = entry.Location;
                        if (w != null)
                        {
                            Tracing.TraceMsg("Found an location " + w.Latitude + w.Longitude);
                        }

                        ExifTags tags = entry.Exif;
                        if (tags != null)
                        {
                            Tracing.TraceMsg("Found an exif block ");
                        }

                        MediaGroup group = entry.Media;
                        if (group != null)
                        {
                            Tracing.TraceMsg("Found a media Group");
                            if (group.Title != null)
                            {
                                Tracing.TraceMsg(group.Title.Value);
                            }
                            if (group.Keywords != null)
                            {
                                Tracing.TraceMsg(group.Keywords.Value);
                            }
                            if (group.Credit != null)
                            {
                                Tracing.TraceMsg(group.Credit.Value);
                            }
                            if (group.Description != null)
                            {
                                Tracing.TraceMsg(group.Description.Value);
                            }
                        }


                        PhotoAccessor photo = new PhotoAccessor(entry);

                        Assert.IsTrue(entry.IsPhoto, "this is a photo entry, it should have the kind set");
                        Assert.IsTrue(photo != null, "this is a photo entry, it should convert to PhotoEntry");

                        Assert.IsTrue(photo.AlbumId != null);
                        Assert.IsTrue(photo.Height > 0);
                        Assert.IsTrue(photo.Width > 0);
                    }
                }

                factory.MethodOverride = false;
            }
        }