Example #1
0
        public VisionMedia Merge(VisionMedia visionMedia, IVisionResponse response)
        {
            var tags = visionMedia.Tags;

            tags.AddRange(response.Tags);

            var categories = visionMedia.Categories;

            categories.AddRange(response.Categories);

            var descriptions = visionMedia.Descriptions;

            descriptions.AddRange(response.Description);

            var json = visionMedia.Json + "\r\n" + response.Json;

            return(new VisionMedia
            {
                Tags = tags,
                Categories = categories,
                Descriptions = descriptions,
                NumberOfFaces = Math.Max(visionMedia.NumberOfFaces ?? 0, response.NumberOfFaces ?? 0),             // TODO : Strategy for this
                PrimaryColour = visionMedia.PrimaryColour ?? response.PrimaryColour,
                BackgroundColour = visionMedia.BackgroundColour ?? response.BackgroundColour,
                Json = json
            });
        }
Example #2
0
        public async void MediaServiceSaved(IMediaService sender, SaveEventArgs <IMedia> e)
        {
            var service = new IntelligentMediaService();

            foreach (var mediaItem in e.SavedEntities)
            {
                if (!string.IsNullOrEmpty(mediaItem.GetValue <string>("json")))
                {
                    continue;
                }

                var visionMedia = new VisionMedia();
                foreach (var api in service.VisionApis())
                {
                    try
                    {
                        var visionResponse = await api.MakeRequest(mediaItem).ConfigureAwait(false);

                        visionMedia = Merge(visionMedia, visionResponse);
                    }
                    catch (Exception)                     // TODO : Make this better
                    {
                        // Ignore for now
                    }
                }
                UpdateMediaItem(mediaItem, visionMedia);
            }
        }
Example #3
0
 public void UpdateMediaItem(IMedia mediaItem, VisionMedia visionMedia)
 {
     // TODO : Configurable which are set and whether to override name
     mediaItem.Name = visionMedia.Name;
     mediaItem.SetValue("tags",
                        String.Join(",", visionMedia.Tags
                                    .Select(t => t.Tag)
                                    .Distinct()));
     mediaItem.SetValue("description",
                        visionMedia.Descriptions
                        .OrderByDescending(d => d.Confidence)
                        .First().Tag);
     mediaItem.SetValue("categories",
                        String.Join(",", visionMedia.Categories
                                    .Select(t => t.Tag.Replace("_", " ").TrimEnd())));
     mediaItem.SetValue("numberOfFaces", visionMedia.NumberOfFaces);
     mediaItem.SetValue("primaryColour", visionMedia.PrimaryColour);
     mediaItem.SetValue("backgroundColour", visionMedia.BackgroundColour);
     mediaItem.SetValue("json", visionMedia.Json);
     ApplicationContext.Current.Services.MediaService.Save(mediaItem);
 }