/// <summary>
        /// Draw the rectangle of the given celebrity.
        /// </summary>
        /// <param name="celebrity">The celebrity to draw the rectangle for.</param>
        private void DrawFaceRectangle(Celebrity celebrity)
        {
            // calculate scaling factor - ONLY WORKS FOR LANDSCAPE IMAGES
            var scaleX = MainCanvas.ActualWidth / image.PixelWidth;
            var scaleY = MainCanvas.ActualHeight / image.PixelHeight;

            // create face rectangle
            var rectangle = new System.Windows.Shapes.Rectangle
            {
                Stroke          = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 0)),
                Fill            = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 255, 255, 255)),
                StrokeThickness = 2,
                Width           = celebrity.FaceRectangle.Width * scaleX,
                Height          = celebrity.FaceRectangle.Height * scaleY,
                Tag             = celebrity.Name
            };

            Canvas.SetLeft(rectangle, celebrity.FaceRectangle.Left * scaleX);
            Canvas.SetTop(rectangle, celebrity.FaceRectangle.Top * scaleY);

            // add handlers
            rectangle.MouseEnter += (sender, e) => {
                ((System.Windows.Shapes.Rectangle)sender).Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 0, 0));
            };
            rectangle.MouseLeave += (sender, e) => {
                ((System.Windows.Shapes.Rectangle)sender).Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 0));
            };
            rectangle.MouseLeftButtonDown += Rectangle_MouseLeftButtonDown;

            MainCanvas.Children.Add(rectangle);

            // ******************
            // ADD YOUR CODE HERE
            // ******************
        }
Exemplo n.º 2
0
        /// <summary>
        /// Perform an entity search on the celebrity and return the description.
        /// </summary>
        /// <param name="celebrity">The celebrity to search for.</param>
        /// <returns>The description of the celebrity.</returns>
        private async Task <Thing> EntitySearch(Celebrity celebrity)
        {
            var client = new EntitySearchAPI(new ApiKeyServiceClientCredentials(ENTITY_KEY));
            var data   = await client.Entities.SearchAsync(query : celebrity.Name);

            if (data?.Entities?.Value?.Count > 0)
            {
                return((from v in data.Entities.Value
                        where v.EntityPresentationInfo.EntityScenario == EntityScenario.DominantEntity
                        select v).FirstOrDefault());
            }
            else
            {
                return(null);
            }
        }