コード例 #1
0
        private void SetImageSource()
        {
            ImageFeedItem image = DataContext as ImageFeedItem;

            if (image == null)
            {
                return;
            }

            _viewport.ScatterViewItem = this.FindVisualParent <ScatterViewItem>();

            if (image.SourceType == SourceType.Twitter || image.Sizes == null)
            {
                _image.UriSource = image.ThumbnailUri;
                return;
            }

            Uri original = (from kvp in image.Sizes where kvp.Key.Width > 1024 || kvp.Key.Height > 1024 select kvp.Value).FirstOrDefault();
            Uri large    = (from kvp in image.Sizes where kvp.Key.Width == 1024 || kvp.Key.Height == 1024 select kvp.Value).FirstOrDefault();
            Uri medium   = (from kvp in image.Sizes where kvp.Key.Width == 500 || kvp.Key.Height == 500 select kvp.Value).FirstOrDefault();

            Uri chosen = null;

            if (large == null && original != null)
            {
                chosen = original;
            }
            else if (large != null)
            {
                chosen = large;
            }
            else if (medium != null)
            {
                chosen = medium;
            }

            _image.UriSource = chosen != null ? chosen : image.ThumbnailUri;
        }
コード例 #2
0
        /// <summary>
        /// Determines the size of the image to load and displays it.
        /// </summary>
        internal void RenderContent()
        {
            ImageFeedItem image = DataContext as ImageFeedItem;

            _viewport.Reset();
            if (image == null)
            {
                _image.UriSource = null;
                return;
            }

            if (image.SourceType == SourceType.Flickr)
            {
                ImageFeedItem.GetFlickrImageSizes(
                    image,
                    Settings.Default.FlickrApiKey,
                    new GetFlickrImageSizesCallback((imageFeedItem) => SetImageSource()));
            }
            else
            {
                SetImageSource();
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates an image extension.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="imageAssetId">The ID of the image asset to be used for creating image
        /// extension.</param>
        /// <returns>Resource name of the newly created image extension.</returns>
        private static string CreateImageExtension(GoogleAdsClient client, long customerId,
                                                   long imageAssetId)
        {
            // Get the ExtensionFeedItemServiceClient.
            ExtensionFeedItemServiceClient extensionFeedItemService =
                client.GetService(Services.V10.ExtensionFeedItemService);

            // Creates the image feed item using the provided image.
            ImageFeedItem imageFeedItem = new ImageFeedItem()
            {
                ImageAsset = ResourceNames.Asset(customerId, imageAssetId)
            };

            // Creates an ExtensionFeedItem from the ImageFeedItem.
            ExtensionFeedItem extensionFeedItem = new ExtensionFeedItem()
            {
                ImageFeedItem = imageFeedItem
            };

            ExtensionFeedItemOperation operation = new ExtensionFeedItemOperation()
            {
                Create = extensionFeedItem
            };

            // Adds the ExtensionFeedItem.
            MutateExtensionFeedItemsResponse response =
                extensionFeedItemService.MutateExtensionFeedItems(customerId.ToString(),
                                                                  new[] { operation });

            // Displays the result.
            string resourceName = response.Results.First().ResourceName;

            Console.WriteLine($"Created an image extension with resource name '{resourceName}'.");

            return(resourceName);
        }
コード例 #4
0
        /// <summary>
        /// Processes the response from the feed service.
        /// </summary>
        /// <param name="response">response from the feed service.</param>
        internal override void ProcessResponse(object responseObject)
        {
            string response = responseObject.ToString();

            if (response.Contains("<rsp stat=\"fail\">"))
            {
#if DEBUG
                throw new InvalidOperationException(response);
#else
                return;
#endif
            }

            XDocument document = XDocument.Parse(response);
            foreach (XElement node in document.Element("rsp").Element("photos").Elements("photo"))
            {
                _flickrUserNameCache[node.Attribute("owner").Value] = node.Attribute("ownername").Value;
                _minUploadDate = Math.Max(_minUploadDate, long.Parse(node.Attribute("dateupload").Value, CultureInfo.InvariantCulture));

                ImageFeedItem feedItem = new ImageFeedItem
                {
                    // Build the page URI with the user photo url, since that's what a user would put in the ban list.
                    Uri = new Uri(string.Format(
                                      CultureInfo.InvariantCulture,
                                      SourceUriFormatString,
                                      string.IsNullOrEmpty(node.Attribute("pathalias").Value) ? node.Attribute("owner").Value : node.Attribute("pathalias").Value,
                                      node.Attribute("id").Value)),

                    Date = FlickrSearchFeed.ConvertFromUnixTimestamp(int.Parse(node.Attribute("dateupload").Value, CultureInfo.InvariantCulture)),

                    Author = HttpUtility.HtmlDecode(_flickrUserNameCache[node.Attribute("owner").Value]),

                    AvatarUri = new Uri(string.Format(
                                            CultureInfo.InstalledUICulture,
                                            AvatarUriFormatString,
                                            node.Attribute("iconfarm").Value,
                                            node.Attribute("iconserver").Value,
                                            node.Attribute("owner").Value)),

                    SourceType = SourceType.Flickr,

                    Title = HttpUtility.HtmlDecode(node.Attribute("title").Value),

                    Caption = HttpUtility.HtmlDecode(StripHtml(node.Element("description") != null ? node.Element("description").Value : string.Empty)),

                    ThumbnailUri = new Uri(string.Format(
                                               CultureInfo.InvariantCulture,
                                               ThumbnailUriFormatString,
                                               node.Attribute("farm").Value,
                                               node.Attribute("server").Value,
                                               node.Attribute("id").Value,
                                               node.Attribute("secret").Value)),

                    ServiceId = node.Attribute("id").Value
                };

                if (feedItem.Date < MinDate)
                {
                    continue;
                }

                RaiseGotNewFeedItem(feedItem);
            }
        }
コード例 #5
0
        /// <summary>
        /// Processes the response to convert owner's posts into feed items.
        /// </summary>
        /// <param name="response">response from the feed service.</param>
        internal void ProcessResponseWithOwner(dynamic response)
        {
            #region Process Owner's Image Items

            if (response.data[_ownerPhotoDataIndex]["fql_result_set"].Count > 0)                            // ownerphotodata
            {
                foreach (dynamic photo in response.data[_ownerPhotoDataIndex]["fql_result_set"])            // ownerphotodata
                {
                    foreach (dynamic author in response.data[_ownerPhotoAuthorDataIndex]["fql_result_set"]) // ownerphotoauthordata
                    {
                        DateTime created = ConvertFromUnixTimestamp(double.Parse(photo["created"].ToString()));

                        if (created < MinDate)
                        {
                            continue;
                        }

                        // add a feed if matching author is found for the post
                        if (photo.owner == author.page_id)
                        {
                            ImageFeedItem feedItem = new ImageFeedItem
                            {
                                Author       = (string)author["name"],
                                AvatarUri    = new Uri((string)author["pic_small"]),
                                Date         = created,
                                ServiceId    = (string)photo["pid"],
                                Uri          = new Uri(string.Format(CultureInfo.InvariantCulture, (string)photo["link"])),
                                SourceType   = SourceType.Facebook,
                                Caption      = (string)photo["caption"],
                                ThumbnailUri = new Uri(string.Format(CultureInfo.InvariantCulture, (string)photo["src_big"])),
                            };

                            RaiseGotNewFeedItem(feedItem);
                        }

                        break;
                    }
                }
            }

            #endregion

            #region Process Owner's Status Items

            if (response.data[_ownerStatusStreamIndex]["fql_result_set"].Count > 0)
            {
                foreach (dynamic post in response.data[_ownerStatusStreamIndex]["fql_result_set"])           // ownerstatusstream
                {
                    foreach (dynamic author in response.data[_ownerStatusAuthorDataIndex]["fql_result_set"]) // ownerstatusauthordata
                    {
                        if (post.actor_id == author.page_id)
                        {
                            // create status feed item if matching author data is found for this post
                            DateTime created = ConvertFromUnixTimestamp(double.Parse(post["created_time"].ToString()));

                            if (created < MinDate)
                            {
                                continue;
                            }

                            StatusFeedItem feedItem = new StatusFeedItem
                            {
                                Author     = (string)author["name"],
                                AvatarUri  = new Uri((string)author["pic_small"]),
                                Date       = created,
                                ServiceId  = (string)post["post_id"],
                                Uri        = new Uri(string.Format(CultureInfo.InvariantCulture, (string)post["permalink"])),
                                Status     = (string)post["message"],
                                SourceType = SourceType.Facebook,
                            };

                            RaiseGotNewFeedItem(feedItem);

                            break;
                        }
                    }
                }
            }

            #endregion
        }