Exemplo n.º 1
3
        public IPhoto UploadPhoto(Stream stream, string filename, string title, string description, string tags)
        {
            using (MiniProfiler.Current.Step("FlickrPhotoRepository.UploadPhoto"))
            {
                Flickr fl = new Flickr();

                string authToken = (ConfigurationManager.AppSettings["FlickrAuth"] ?? "").ToString();
                if (string.IsNullOrEmpty(authToken))
                    throw new ApplicationException("Missing Flickr Authorization");

                fl.AuthToken = authToken;
                string photoID = fl.UploadPicture(stream, filename, title, description, tags, true, true, false,
                    ContentType.Photo, SafetyLevel.Safe, HiddenFromSearch.Visible);
                var photo = fl.PhotosGetInfo(photoID);
                var allSets = fl.PhotosetsGetList();
                var blogSet = allSets
                                .FirstOrDefault(s => s.Description == "Blog Uploads");
                if (blogSet != null)
                    fl.PhotosetsAddPhoto(blogSet.PhotosetId, photo.PhotoId);

                FlickrPhoto fphoto = new FlickrPhoto();
                fphoto.Description = photo.Description;
                fphoto.WebUrl = photo.MediumUrl;
                fphoto.Title = photo.Title;
                fphoto.Description = photo.Description;

                return fphoto;
            }
        }
Exemplo n.º 2
0
        void Tile_Click(object sender, EventArgs e)
        {
            Tile tile = sender as Tile;

            if (tile != null)
            {
                FlickrPhoto photo = (FlickrPhoto)tile.Tag;
                string      uri   = photo.ContentUri;
                if (!string.IsNullOrEmpty(uri))
                {
                    pictureBox.Image    = pictureBox.InitialImage;
                    pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
                    imgPanel.Visible    = true;
                    imgPanel.BringToFront();
                    titleLabel.Text   = photo.Title;
                    authorLabel.Text  = photo.AuthorName;
                    waitLabel.Visible = true;
                    pictureBox.LoadAsync(uri);
                    tagBox.Enabled        = false;
                    setTagButton.Enabled  = false;
                    refreshButton.Enabled = false;
                    loadNewButton.Enabled = false;
                    flickrTiles.Enabled   = false;
                    backButton.Enabled    = true;
                    this.Focus();
                }
            }
        }
Exemplo n.º 3
0
 public CachedFlickrPhoto(FlickrPhoto photo, DateTime uploadDate, string source)
 {
     Id         = photo.Id;
     UploadDate = uploadDate;
     Source     = source;
     Title      = photo.Title;
 }
        //Opción Compartir al dar Click sobre una imágen.
        //En xaml se debe habilitar: <GridView IsItemClickEnabled="True" ItemClick="grdFlickrImageOutput_ItemClick_1">
        private void grdFlickrImageOutput_ItemClick(object sender, ItemClickEventArgs e)
        {
            FlickrPhoto selectedPhoto = e.ClickedItem as FlickrPhoto;
            var         urt           = selectedPhoto.ImageUrl;

            strsharedText = "Hey mira esta foto " + urt + " me encanta #CSharpCornerMvpSummit #Demo";
            DataTransferManager.ShowShareUI();
        }
        //Pasar a nueva página al dar Click sobre una imágen.
        //Código para el xaml: <GridView x:Name="grdFlickrImagen" Grid.Row="2" Margin="30,0,0,0" SelectionMode="Single" SelectionChanged="grdFlickrImagen_SelectionChanged">
        private void grdFlickrImagen_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FlickrPhoto selectedPhoto = e.AddedItems.SingleOrDefault() as FlickrPhoto;
            var         parameters    = new FlickrPhoto();

            parameters.Title    = selectedPhoto.Title;
            parameters.ImageUrl = selectedPhoto.ImageUrl;
            Frame.Navigate(typeof(ImgSelec), parameters);
        }
Exemplo n.º 6
0
        //TODO Move out to a service
        async void GetData()
        {
            var url = WebRequestHelper.BaseUrl + "?method=flickr.photos.search";

            var content = new Dictionary <string, string>
            {
                ["api_key"]        = "1ec450bec545d2e66304e349b78ce1c9",
                ["lat"]            = CurrentLat,
                ["lon"]            = CurrentLong,
                ["format"]         = "json",
                ["nojsoncallback"] = "1",
            };

            var response = await WebRequestHelper.MakeAsyncRequest(url, content);

            var json = response.Content.ReadAsStringAsync().Result;

            var apidata = JsonConvert.DeserializeObject <FlickerData>(json);

            if (apidata.stat == "ok")
            {
                for (int i = 1; i < 10; i++)
                {
                    i++;

                    var photo = apidata.photos.photo[i];

                    long id = long.Parse(photo.id);

                    string photoUrl     = "http://farm{0}.staticFlickr.com/{1}/{2}_{3}_n.jpg";
                    string baseFlickUrl = string.Format(photoUrl, photo.farm, photo.server, photo.id, photo.secret);

                    var bitmap = await Helpers.BitmapHelper.GetImageFromUrl(baseFlickUrl);

                    var flickrPhoto = new FlickrPhoto
                    {
                        ID       = id,
                        ImageURL = baseFlickUrl,
                        Title    = photo.title,
                        Image    = bitmap
                    };

                    _photos.Add(flickrPhoto);
                }

                Adapter.NotifyDataSetChanged();

                _progress.Hide();
            }
        }
Exemplo n.º 7
0
        private async void LoadPhotos()
        {
            loading.Visibility = Visibility.Visible;
            retry.Visibility   = Visibility.Collapsed;
            try
            {
                var photos = await FlickrPhoto.Load("people");

                loading.Visibility = Visibility.Collapsed;
                this.DataContext   = photos;
            }
            catch
            {
                var dialog = new Windows.UI.Popups.MessageDialog(Strings.DownloadFlickrErrorMessage);
                dialog.ShowAsync();
                retry.Visibility   = Visibility.Visible;
                loading.Visibility = Visibility.Collapsed;
            }
            splitView.IsPaneOpen = true;
        }
Exemplo n.º 8
0
        public void GetFlickrPhotoByCoordinate(double lng, double lat, string locationId)
        {
            PhotoCollection photos = _FlickrService.SearchPhotos(lng, lat);

            var photoList = photos.OrderBy(x => x.PhotoId).ToList();

            var photoByLocationList = _FlickrPhotoRepository.GetByLocationId(locationId);

            if (photoByLocationList.Any())
            {
                var maxPhotoId = photoByLocationList.Max(x => x.PhotoID);

                photoList = photoList.Where(x => double.Parse(x.PhotoId) > maxPhotoId).ToList();
            }

            List <FlickrPhoto> flickrPhotos = new List <FlickrPhoto>();

            foreach (var flickrPhoto in photoList)
            {
                FlickrPhoto photo = new FlickrPhoto
                {
                    FlickrPhotoID    = Guid.NewGuid().ToString(),
                    LocationID       = locationId,
                    DateUploaded     = (flickrPhoto.DateUploaded >= (DateTime)SqlDateTime.MinValue) ? flickrPhoto.DateUploaded : (DateTime?)null,
                    Description      = flickrPhoto.Description,
                    PhotoID          = double.Parse(flickrPhoto.PhotoId),
                    OwnerName        = flickrPhoto.OwnerName,
                    Title            = flickrPhoto.Title,
                    OriginalURL      = String.IsNullOrEmpty(flickrPhoto.OriginalUrl) ? flickrPhoto.LargeSquareThumbnailUrl : flickrPhoto.OriginalUrl,
                    LargeThumnailURL = flickrPhoto.LargeSquareThumbnailUrl
                };

                flickrPhotos.Add(photo);
            }

            _FlickrPhotoRepository.AddRange(flickrPhotos);
        }
        private async void LoadContent()
        {
            sv.Visibility      = Visibility.Collapsed;
            loading.Visibility = Visibility.Visible;
            retry.Visibility   = Visibility.Collapsed;
            try
            {
                foreach (C1Tile tile in tilePanel.Children)
                {
                    var content = await FlickrPhoto.Load((string)tile.Header);

                    loading.Visibility = Visibility.Collapsed;
                    sv.Visibility      = Visibility.Visible;
                    tile.ContentSource = content;
                }
            }
            catch
            {
                var dialog = new Windows.UI.Popups.MessageDialog(Strings.DownloadFlickrErrorMessage);
                dialog.ShowAsync();
                retry.Visibility   = Visibility.Visible;
                loading.Visibility = Visibility.Collapsed;
            }
        }
 internal static string UrlFormat(FlickrPhoto p, PhotoSize size, string extension)
 {
     return(UrlFormat(p.Farm, p.Server, p.PhotoId, p.Secret, size, extension));
 }
Exemplo n.º 11
0
        void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Cancelled || _targetItem == null)
            {
                return;
            }
            Exception ex = e.Error;

            if (ex == null)
            {
                try
                {
                    if (_targetItem.Tile == null)
                    {
                        var doc = new XmlDocument();
                        doc.Load(e.Result);

                        var nameTable = new NameTable();
                        var nm        = new XmlNamespaceManager(nameTable);
                        nm.AddNamespace("ns", "http://www.w3.org/2005/Atom");
                        nm.AddNamespace("flickr", "urn:flickr:user");

                        List <FlickrPhoto> result = new List <FlickrPhoto>();
                        TileCollection     tiles  = flickrTiles.Groups[0].Tiles;
                        bool keepExistent         = _targetItem.IsBuddyIcon;

                        foreach (XmlNode node in doc.DocumentElement.SelectNodes("ns:entry", nm))
                        {
                            string id = node.SelectSingleNode("ns:id", nm).InnerText;

                            if (keepExistent)
                            {
                                bool found = false;
                                foreach (Tile tile in tiles)
                                {
                                    if (((FlickrPhoto)tile.Tag).ID == id)
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (found)
                                {
                                    continue;
                                }
                            }

                            var photo = new FlickrPhoto();
                            photo.ID    = id;
                            photo.Title = PrepareTitle(node.SelectSingleNode("ns:title", nm).InnerText);
                            var authorNode = node.SelectSingleNode("ns:author", nm);
                            if (authorNode != null)
                            {
                                photo.AuthorName         = authorNode.SelectSingleNode("ns:name", nm).InnerText;
                                photo.AuthorBuddyIconUri = authorNode.SelectSingleNode("flickr:buddyicon", nm).InnerText;
                            }
                            var linkNode = node.SelectSingleNode("ns:link[@rel='enclosure']", nm);
                            if (linkNode != null)
                            {
                                photo.ContentUri   = linkNode.Attributes["href"].Value;
                                photo.ThumbnailUri = photo.ContentUri.Replace("_b.jpg", "_m.jpg");
                            }
                            result.Add(photo);
                        }
                        UpdatePhotos(result, tiles, keepExistent);
                    }
                    else
                    {
                        Image img  = Image.FromStream(e.Result);
                        Tile  tile = _targetItem.Tile;
                        if (!_targetItem.IsBuddyIcon)
                        {
                            tile.Image = img;
                        }
                        else
                        {
                            tile.Image1 = img;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ex = exception;
                }
            }

            if (ex != null && _targetItem.Tile == null && !_targetItem.IsBuddyIcon)
            {
                _targetItem = null;
                _lastError  = ex.Message;
                ShowErrorTile();
            }
            else
            {
                _targetItem = null;
                _lastError  = null;
                if (_outOfTurnItem != null)
                {
                    _targetItem    = _outOfTurnItem;
                    _outOfTurnItem = null;
                }
                else if (_downloadQueue.Count > 0)
                {
                    _targetItem = _downloadQueue.Dequeue();
                }
                if (_targetItem != null)
                {
                    _client.OpenReadAsync(new Uri(_targetItem.Uri));
                }
            }
            waitLabel.Visible = false;
        }
Exemplo n.º 12
0
        private List <FlickrPhoto> DeserializePhotos(string response)
        {
            var photos = new List <FlickrPhoto>();

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(response);

            var xmlPhotos = xmlDoc.GetElementsByTagName("photo");

            for (int i = 0; i < xmlPhotos.Count; i++)
            {
                var xmlPhoto = xmlPhotos.Item(i);
                var Photo    = new FlickrPhoto();

                Photo.Id          = xmlPhoto.Attributes["id"] != null ? xmlPhoto.Attributes["id"].Value : "";
                Photo.Owner       = xmlPhoto.Attributes["owner"] != null ? xmlPhoto.Attributes["owner"].Value : "";
                Photo.OwnerName   = xmlPhoto.Attributes["ownername"] != null ? xmlPhoto.Attributes["ownername"].Value : "";
                Photo.Secret      = xmlPhoto.Attributes["secret"] != null ? xmlPhoto.Attributes["secret"].Value : "";
                Photo.Server      = xmlPhoto.Attributes["server"] != null ? xmlPhoto.Attributes["server"].Value : "";
                Photo.Farm        = xmlPhoto.Attributes["farm"] != null ? xmlPhoto.Attributes["farm"].Value : "";
                Photo.Title       = xmlPhoto.Attributes["title"] != null ? xmlPhoto.Attributes["title"].Value : "";
                Photo.Description = xmlPhoto.Attributes["description"] != null ? xmlPhoto.Attributes["description"].Value : "";
                Photo.IsPrimary   = xmlPhoto.Attributes["isprimary"] != null ? xmlPhoto.Attributes["isprimary"].Value == "1" ? true : false : false;
                Photo.IsPublic    = xmlPhoto.Attributes["ispublic"] != null ? xmlPhoto.Attributes["ispublic"].Value == "1" ? true : false : false;
                Photo.IsFriend    = xmlPhoto.Attributes["isfriend"] != null ? xmlPhoto.Attributes["isfriend"].Value == "1" ? true : false : false;
                Photo.IsFamily    = xmlPhoto.Attributes["isfamily"] != null ? xmlPhoto.Attributes["isfamily"].Value == "1" ? true : false : false;
                Photo.HasComment  = xmlPhoto.Attributes["has_comment"] != null ? xmlPhoto.Attributes["has_comment"].Value == "1" ? true : false : false;

                Photo.Url_SQ    = xmlPhoto.Attributes["url_sq"] != null ? xmlPhoto.Attributes["url_sq"].Value : "";
                Photo.Height_SQ = xmlPhoto.Attributes["height_sq"] != null?Int32.Parse(xmlPhoto.Attributes["height_sq"].Value) : 0;

                Photo.Width_SQ = xmlPhoto.Attributes["width_sq"] != null?Int32.Parse(xmlPhoto.Attributes["width_sq"].Value) : 0;

                Photo.Url_T    = xmlPhoto.Attributes["url_t"] != null ? xmlPhoto.Attributes["url_t"].Value : "";
                Photo.Height_T = xmlPhoto.Attributes["height_t"] != null?Int32.Parse(xmlPhoto.Attributes["height_t"].Value) : 0;

                Photo.Width_T = xmlPhoto.Attributes["width_t"] != null?Int32.Parse(xmlPhoto.Attributes["width_t"].Value) : 0;

                Photo.Url_S    = xmlPhoto.Attributes["url_s"] != null ? xmlPhoto.Attributes["url_s"].Value : "";
                Photo.Height_S = xmlPhoto.Attributes["height_s"] != null?Int32.Parse(xmlPhoto.Attributes["height_s"].Value) : 0;

                Photo.Width_S = xmlPhoto.Attributes["width_s"] != null?Int32.Parse(xmlPhoto.Attributes["width_s"].Value) : 0;

                Photo.Url_M    = xmlPhoto.Attributes["url_m"] != null ? xmlPhoto.Attributes["url_m"].Value : "";
                Photo.Height_M = xmlPhoto.Attributes["height_m"] != null?Int32.Parse(xmlPhoto.Attributes["height_m"].Value) : 0;

                Photo.Width_M = xmlPhoto.Attributes["width_m"] != null?Int32.Parse(xmlPhoto.Attributes["width_m"].Value) : 0;

                Photo.Url_Z    = xmlPhoto.Attributes["url_z"] != null ? xmlPhoto.Attributes["url_z"].Value : "";
                Photo.Height_Z = xmlPhoto.Attributes["height_z"] != null?Int32.Parse(xmlPhoto.Attributes["height_z"].Value) : 0;

                Photo.Width_Z = xmlPhoto.Attributes["width_z"] != null?Int32.Parse(xmlPhoto.Attributes["width_z"].Value) : 0;

                Photo.Url_L    = xmlPhoto.Attributes["url_l"] != null ? xmlPhoto.Attributes["url_l"].Value : "";
                Photo.Height_L = xmlPhoto.Attributes["height_l"] != null?Int32.Parse(xmlPhoto.Attributes["height_l"].Value) : 0;

                Photo.Width_L = xmlPhoto.Attributes["width_l"] != null?Int32.Parse(xmlPhoto.Attributes["width_l"].Value) : 0;

                Photo.Url_O    = xmlPhoto.Attributes["url_o"] != null ? xmlPhoto.Attributes["url_o"].Value : "";
                Photo.Height_O = xmlPhoto.Attributes["height_o"] != null?Int32.Parse(xmlPhoto.Attributes["height_o"].Value) : 0;

                Photo.Width_O = xmlPhoto.Attributes["width_o"] != null?Int32.Parse(xmlPhoto.Attributes["width_o"].Value) : 0;

                photos.Add(Photo);
            }

            return(photos);
        }
 public void SetPermissions(FlickrPhoto photo, bool @public, bool friends, bool family)
 {
     Flickr.PhotosSetPerms(photo.PhotoId.Id, @public, friends, family, PermissionComment.Nobody, PermissionAddMeta.Owner);
 }
 public void RemovePhoto(FlickrPhoto photo)
 {
     Flickr.PhotosDelete(photo.PhotoId.Id);
 }
Exemplo n.º 15
0
        private string CreatePhotoUrl(FlickrPhoto photo)
        {
            var photoUrl = $"https://farm{photo.Farm}.staticflickr.com/{photo.Server}/{photo.Id}_{photo.Secret}.jpg";

            return(photoUrl);
        }