Ejemplo n.º 1
0
        private void GraphApiPhotos()
        {
            var fb = new FacebookClient(_accessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }
                count =count+ 8;
                var result = (IDictionary<string, object>)e.GetResultData();

                Dispatcher.BeginInvoke(() =>
                {
                    int i;
                    panel_count++;
                    Grid grid = new Grid();
                    grid.Name = "Grid" + panel_count;
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    stackPanel1.Children.Add(grid);
                    IList data = (IList)result["data"];
                    for (i = 0; i < data.Count; i++)
                    {
                        IDictionary<string, object> entry = (IDictionary<string, object>)data[i];
                        HubTile hubTile = new HubTile();
                        try
                        {
                            hubTile.Title = (string)entry["name"];
                        }
                        catch
                        {
                            hubTile.Title = "No caption";
                        }
                        //hubTile.Title = "Title";
                        hubTile.Source = new BitmapImage(new Uri((string)entry["picture"]));
                        hubTile.Name = (string)entry["link"];
                        GetComments((string)entry["id"], (string)entry["link"]);
                        hubTile.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(hubTile_Tap);
                        hubTile.SetValue(Grid.RowProperty, i / 2);
                        hubTile.SetValue(Grid.ColumnProperty, i % 2);
                        grid.Children.Add(hubTile);
                        if (i == data.Count - 1)
                        {
                            int newCount = 0;
                            String imageURL = (string)entry["picture"];
                            String imageURI = imageURL.Replace("https://", "http://");
                            // Application Tile is always the first Tile, even if it is not pinned to Start.
                            ShellTile TileToFind = ShellTile.ActiveTiles.First();
                            // Application should always be found
                            if (TileToFind != null)
                            {
                                // Set the properties to update for the Application Tile.
                                // Empty strings for the text values and URIs will result in the property being cleared.
                                StandardTileData NewTileData = new StandardTileData
                                {
                                    Title = "Fhotos-On-Tiles",
                                    //BackgroundImage = new Uri(imageURL, UriKind.Absolute),
                                    BackgroundImage = new Uri(imageURI),
                                    Count = newCount,
                                    BackTitle = "What is This?",
                                    BackContent = "View your Facebook photos on tiles."
                                };

                                // Update the Application Tile
                                TileToFind.Update(NewTileData);
                            }
                        }
                    }
                    if (i == 8)
                    {
                        Button more_btn = new Button();
                        more_btn.Content = "More...";
                        more_btn.Name = "MoreButton";
                        more_btn.Click += PhoneApplicationPage_Loaded;
                        stackPanel1.Children.Add(more_btn);
                    }

                });
            };

            fb.GetAsync("me/photos?limit=8&offset=" + count + "&fields=name,picture,link");
        }
Ejemplo n.º 2
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            /*Button morebtn = (Button)this.FindName("moreButton");
            stackPanel1.Children.Remove(morebtn);*/
            if (app_count == 0)
            {
                Button more_btn = new Button();
                more_btn.Content = "More...";
                more_btn.Name = "MoreButton";
                more_btn.Click += PhoneApplicationPage_Loaded;
                stackPanel1.Children.Add(more_btn);
                app_count++;
            }
            Button morebtn = (Button)this.FindName("MoreButton");
            stackPanel1.Children.Remove(morebtn);
            if (FlickrManager.OAuthToken == null || FlickrManager.OAuthTokenSecret == null)
                return;
            else
            {
                int count=0;
                Grid grid = new Grid();
                grid.Name = "Grid" + panel_count;
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(200)});
                grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                stackPanel1.Children.Add(grid);
                //scrollViewer1.Content = grid;
                Button btn = (Button)this.FindName("flickrAuthenticate");
                btn.Content = "Not your Account?";
                Flickr f = FlickrManager.GetAuthInstance();

                f.PeopleGetPhotosAsync(FlickrManager.OAuthUserID, page, perPage, r => 
                {
                    if (r.Error != null)
                    {
                        Dispatcher.BeginInvoke(() =>
                        {
                            MessageBox.Show("An error occurred talking to Flickr: " + r.Error.Message);
                        });
                        return;
                    }

                    PhotoCollection photos = r.Result;

                    Dispatcher.BeginInvoke(() =>
                    {
                        //ResultsListBox.ItemsSource = photos;
                        while (count != photos.Count)
                        {
                            int comments_count=0;
                            String full_comment = "";

                            HubTile hubTile = new HubTile();
                            hubTile.Title = photos[count].Title;
                            hubTile.Source = new BitmapImage(new Uri(photos[count].SquareThumbnailUrl));
                            hubTile.Name = photos[count].WebUrl;
                            hubTile.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(hubTile_Tap);
                            Flickr flickr = FlickrManager.GetAuthInstance();
                            flickr.PhotosCommentsGetListAsync(photos[count].PhotoId, res => 
                            {
                                if (res.Error != null)
                                {
                                    Dispatcher.BeginInvoke(() =>
                                    {
                                        MessageBox.Show("An error occurred talking to Flickr: " + res.Error.Message);
                                    });
                                    return;
                                }
                                PhotoCommentCollection comments = res.Result;
                                if (comments.Count == 0)
                                    full_comment = "No comments";
                                else
                                {
                                    while (comments_count != comments.Count)
                                    {
                                        full_comment = full_comment + comments[comments_count].AuthorUserName + ":" + comments[comments_count].CommentHtml + " ";
                                        comments_count++;
                                    }
                                }
                                hubTile.Message = full_comment;
                            });
                            //stackPanel1.Children.Add(comment);
                            //stackPanel1.Children.Add(hubTile);
                            hubTile.SetValue(Grid.RowProperty, count / 2);
                            hubTile.SetValue(Grid.ColumnProperty, count % 2);
                            grid.Children.Add(hubTile);
                            count++;
                            if (count == photos.Count)
                            {
                                int newCount = 0;
                                String imageURL = photos[count-1].SquareThumbnailUrl;
                                // Application Tile is always the first Tile, even if it is not pinned to Start.
                                ShellTile TileToFind = ShellTile.ActiveTiles.First();
                                // Application should always be found
                                if (TileToFind != null)
                                {
                                    // Set the properties to update for the Application Tile.
                                    // Empty strings for the text values and URIs will result in the property being cleared.
                                    StandardTileData NewTileData = new StandardTileData
                                    {
                                        Title = "Flickr-On-Tiles",
                                        BackgroundImage = new Uri(imageURL),
                                        Count = newCount,
                                        BackTitle = "What is This?",
                                        BackContent = "Flickr-on-Tiles. An app for photofreaks"
                                    };

                                    // Update the Application Tile
                                    TileToFind.Update(NewTileData);
                                }
                            }
                        }
                        if (photos.Pages != page)
                        {
                            page++;
                            stackPanel1.Children.Add(morebtn);
                        }
                    });
                    return;
                });
            }
        }
        public void ImagesDownloaded(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (e.Result == null || e.Error != null)
                {
                    MessageBox.Show("Cannot get albums data from Picasa server!");
                    return;
                }
                else
                {
                    panel_count++;
                    Grid grid = new Grid();
                    grid.Name = "Grid" + panel_count;
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(200)});
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(200) });
                    stackPanel1.Children.Add(grid);
                    // Deserialize JSON string to dynamic object
                    IDictionary<string, object> json = (IDictionary<string, object>)SimpleJson.DeserializeObject(e.Result);
                    // Feed object
                    IDictionary<string, object> feed = (IDictionary<string, object>)json["feed"];
                    // Image entries
                    IList entries = (IList)feed["entry"];
                    // Delete previous albums from albums list
                    //albumImages.Clear();
                    // Find album details
                    for (int i = 0; i < entries.Count; i++)
                    {
                        // Create a new Album
                        AlbumImage albumImage = new AlbumImage();
                        // Album entry object
                        IDictionary<string, object> entry = (IDictionary<string, object>)entries[i];
                        // Published object
                        IDictionary<string, object> summary = (IDictionary<string, object>)entry["summary"];
                        // Image Caption
                        if ((string)summary["$t"] == "")
                        {
                            albumImage.title = "No caption";
                        }
                        else
                        {
                            albumImage.title = (string)summary["$t"];
                        }
                        // Link List
                        IList link = (IList)entry["link"];
                        // First link is Image URL in Picasa
                        IDictionary<string, object> href = (IDictionary<string, object>)link[0];
                        // Get image webURL
                        albumImage.webUrl = (string)href["href"];
                        // Media group object
                        IDictionary<string, object> mediagroup = (IDictionary<string, object>)entry["media$group"];
                        // Media thumbnail object list
                        IList mediathumbnailList = (IList)mediagroup["media$thumbnail"];
                        // First thumbnail object (smallest)
                        IDictionary<string, object> mediathumbnail = (IDictionary<string, object>)mediathumbnailList[0];
                        // Get thumbnail url
                        albumImage.thumbnail = (string)mediathumbnail["url"];
                        IDictionary<string, object> photoid = (IDictionary<string, object>)entry["gphoto$id"];
                        IDictionary<string, object> photoalbumid = (IDictionary<string, object>)entry["gphoto$albumid"];
                        albumImage.content = GetComments((string)photoid["$t"], (string)photoalbumid["$t"]);
                        HubTile hubtile = new HubTile();
                        hubtile.Title = albumImage.title;
                        hubtile.Source = new BitmapImage(new Uri(albumImage.thumbnail));
                        hubtile.Name = albumImage.webUrl;// +":" + (string)photoid["$t"];
                        hubtile.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(hubtile_Tap);
                        hubtile.Message = albumImage.content;
                        hubtile.SetValue(Grid.RowProperty, i / 2);
                        hubtile.SetValue(Grid.ColumnProperty, i % 2);
                        grid.Children.Add(hubtile);
                        /*if (i == entries.Count - 1)
                        {
                            int newCount = 0;
                            String imageURL = albumImage.thumbnail;
                            // Application Tile is always the first Tile, even if it is not pinned to Start.
                            ShellTile TileToFind = ShellTile.ActiveTiles.First();
                            // Application should always be found
                            if (TileToFind != null)
                            {
                                // Set the properties to update for the Application Tile.
                                // Empty strings for the text values and URIs will result in the property being cleared.
                                StandardTileData NewTileData = new StandardTileData
                                {
                                    Title = "Picasa-On-Tiles",
                                    BackgroundImage = new Uri(imageURL,UriKind.Absolute),
                                    //BackgroundImage = new Uri((string)mediathumbnail["url"]),
                                    //BackgroundImage = ((System.Windows.Media.Imaging.BitmapImage)hubtile.Source).UriSource,
                                    Count = newCount,
                                    BackTitle = "What is This?",
                                    BackContent = "Picasa-on-Tiles. An app for photofreaks"
                                };

                                // Update the Application Tile
                                TileToFind.Update(NewTileData);
                            }
                        }*/
                    }
                    /*if (entries.Count != 8)
                    {
 
                    }*/
                    // Add albums to AlbumListBox
                    //AlbumsListBox.ItemsSource = app.albums;
                }
            }
            catch (WebException)
            {
                MessageBox.Show("Cannot get albums data from Picasa server!");
            }
            catch (KeyNotFoundException)
            {
                //MessageBox.Show("Cannot load images from Picasa Server - JSON parsing error happened!");
            }
        }