Exemple #1
0
        public async Task Enrich(Photo photo, SourceDataDto sourceData)
        {
            await Task.Run(() =>
            {
                photo.PhotoTags = new List <PhotoTag>();

                // Workaround for bug, when service returns the same tags
                var tags = sourceData.ImageAnalysis.Tags.GroupBy(t => t.Name.ToLower()).Select(t =>
                                                                                               new
                {
                    Name       = t.Key,
                    Confidence = t.Max(v => v.Confidence)
                });

                foreach (var tag in tags)
                {
                    var tagModel = _tagRepository.GetByCondition(t => t.Name == tag.Name).FirstOrDefault() ?? new Tag
                    {
                        Name = tag.Name,
                    };

                    var photoTag = new PhotoTag
                    {
                        Photo      = photo,
                        Tag        = tagModel,
                        Confidence = tag.Confidence
                    };

                    photo.PhotoTags.Add(photoTag);
                }
            });
        }
Exemple #2
0
 public void AddTag(PhotoTag tag)
 {
     if (!HasTag(tag))
     {
         Tags += "," + tag.ToString();
     }
 }
Exemple #3
0
 public PhotoBatchResult(IReadOnlyCollection <Photo> items, PhotoTag tag, Func <UInt32, UInt32, Task <PhotosSearchResult> > action, UInt16 batchSize)
 {
     Items         = items;
     ReadyElements = batchSize;
     Action        = action;
     BatchSize     = batchSize;
     StartGettingResultAsync(tag);
 }
Exemple #4
0
 public ProgressivePhotoSearch(IPhotoProvider provider, PhotoTag photoTag, GeoPoint location, DateTime startDate, DateTime endDate, UInt16 radius)
 {
     Provider  = provider;
     PhotoTag  = photoTag;
     Location  = location;
     StartDate = startDate;
     EndDate   = endDate;
     Radius    = radius;
 }
        public IActionResult Post([FromBody] PhotoTag ptag)
        {
            string userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            this._context.PhotoTags.Add(ptag);
            _context.SaveChanges();

            return(Created(ptag));
        }
Exemple #6
0
        public Task StartProgressiveSearchAsync(MapViewSettings viewSettings, PhotoTag tag) => Task.Run(() =>
        {
            if (ProgressiveSearch != null)
            {
                ProgressiveSearch.Cancel = true;
            }

            ProgressiveSearch         = App.Model.Photos.CreateProgressiveSearch(tag, viewSettings.Location, viewSettings.FromDate, viewSettings.ToDate);
            ActiveProgressiveSearchId = ProgressiveSearch.Id;
            ProgressiveSearch.ChunkSearchingStarted   += OnProgressiveChunkSearchingStarted;
            ProgressiveSearch.ChunkSearchingCompleted += OnProgressiveChunkSearchingCompleted;
            ProgressiveSearch.ChunkSearchingFailed    += OnProgressiveChunkSearchingFailed;
            ProgressiveSearch.SearchingFinished       += OnProgressiveSearchingFinished;
            return(ProgressiveSearch.PerformAsync());
        });
Exemple #7
0
        private void collectUsersFromTag(PhotoTag i_Tag, UserData i_UserData)
        {
            string currUserNameAsKey = string.Empty;

            currUserNameAsKey = getUserFullName(i_Tag.User);
            if (checkIfFriendIsNotLocalUser(i_UserData.LocalUser, i_Tag.User))
            {
                return;
            }

            if (i_UserData.BestFriendsDict.ContainsKey(currUserNameAsKey))
            {
                i_UserData.BestFriendsDict[currUserNameAsKey] += 1;
            }
            else
            {
                i_UserData.BestFriendsDict.Add(currUserNameAsKey, 1);
            }
        }
Exemple #8
0
        /// <summary>
        /// Associates a photo with a tag.
        /// </summary>
        /// <param name="photoId">The photo identifier.</param>
        /// <param name="tagId">The tag identifier.</param>
        /// <returns>A new photo-tag entity.</returns>
        public async Task <PhotoTag> AssociatePhotoTag(int photoId, int tagId)
        {
            var existingTags = await GetPhotoTagAssociations(photoId, tagId);

            if (existingTags.Any())
            {
                return(existingTags.First());
            }

            var photoTag = new PhotoTag
            {
                PhotoId = photoId,
                TagId   = tagId
            };

            await InsertAsync(photoTag);

            return(photoTag);
        }
Exemple #9
0
        private async void StartGettingResultAsync(PhotoTag tag)
        {
            try
            {
                while (!Cancel)
                {
                    var searchResult = await Action.Invoke(ReadyElements, BatchSize).ConfigureAwait(false);

                    if (Cancel)
                    {
                        break;
                    }
                    ReadyElements += BatchSize;

                    var photos = new List <Photo>();
                    foreach (var photoMetadata in searchResult.Photos)
                    {
                        var photo = Photo.Create(photoMetadata);
                        if (photo != null)
                        {
                            photos.Add(photo);
                            photo.Tag = tag;
                        }
                    }
                    if ((MoreItemsReady == null) || (photos.Count == 0))
                    {
                        break;
                    }

                    var eventArgs = new EventArgs(photos);
                    MoreItemsReady(this, eventArgs);
                    if (eventArgs.Cancel)
                    {
                        break;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Exemple #10
0
 public ProgressivePhotoSearch CreateProgressiveSearch(PhotoTag tag, GeoPoint location, DateTime startDate, DateTime endDate) => new ProgressivePhotoSearch(Provider, tag, location, startDate, endDate, 100);
        public async Task <IActionResult> Edit(Guid?id, PhotoViewModel model)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var photo = await this.context.Photo
                        .Include(m => m.Tags)
                        .SingleOrDefaultAsync(m => m.Id == id);

            if (photo == null)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                photo.Name        = model.Name;
                photo.Description = model.Description;

                foreach (var currentTag in model.Tags.Split(',').Select(x => x.Trim()).Where(x => !String.IsNullOrEmpty(x)))
                {
                    var tag = await this.context.Tags
                              .Include(m => m.Photos)
                              .SingleOrDefaultAsync(m => m.Text == currentTag);

                    if (tag == null)
                    {
                        tag = new Tag
                        {
                            Text = currentTag
                        };

                        this.context.Tags.Add(tag);
                    }

                    if (tag.Photos == null)
                    {
                        tag.Photos = new Collection <PhotoTag>();
                    }

                    var photoTag = await this.context.PhotoTags
                                   .SingleOrDefaultAsync(m => m.PhotoId == photo.Id && m.TagId == tag.Id);

                    if (photoTag == null)
                    {
                        photoTag = new PhotoTag
                        {
                            PhotoId = photo.Id,
                            TagId   = tag.Id
                        };

                        this.context.PhotoTags.Add(photoTag);
                    }

                    photo.Tags.Add(photoTag);
                    tag.Photos.Add(photoTag);
                }

                await this.context.SaveChangesAsync();

                return(this.RedirectToAction("Details", new { id }));
            }

            return(this.View(model));
        }
        public async Task <IActionResult> Create(PhotoViewModel model)
        {
            var fileName = Path.GetFileName(ContentDispositionHeaderValue.Parse(model.File.ContentDisposition).FileName.Trim('"'));
            var fileExt  = Path.GetExtension(fileName);

            if (!AllowedExtensions.Contains(fileExt))
            {
                this.ModelState.AddModelError(nameof(model.File), "This file type is prohibited");
            }

            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

            if (this.ModelState.IsValid)
            {
                var photo = new Photo
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Likes       = 0,
                    UserId      = user.Id,
                    Tags        = new Collection <PhotoTag>()
                };

                foreach (var currentTag in model.Tags.Split(',').Select(x => x.Trim()).Where(x => !String.IsNullOrEmpty(x)))
                {
                    var tag = await this.context.Tags
                              .Include(m => m.Photos)
                              .SingleOrDefaultAsync(m => m.Text == currentTag);

                    if (tag == null)
                    {
                        tag = new Tag
                        {
                            Text = currentTag
                        };

                        this.context.Tags.Add(tag);
                    }

                    if (tag.Photos == null)
                    {
                        tag.Photos = new Collection <PhotoTag>();
                    }


                    var photoTag = new PhotoTag
                    {
                        PhotoId = photo.Id,
                        TagId   = tag.Id
                    };

                    this.context.PhotoTags.Add(photoTag);
                    photo.Tags.Add(photoTag);
                    tag.Photos.Add(photoTag);
                }

                var attachmentPath = Path.Combine(this.hostingEnvironment.WebRootPath, "attachments", photo.Id.ToString("N") + fileExt);
                photo.Path = $"/attachments/{photo.Id:N}{fileExt}";
                using (var fileStream = new FileStream(attachmentPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read))
                {
                    await model.File.CopyToAsync(fileStream);
                }

                this.context.Add(photo);
                await this.context.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }

            return(this.View(model));
        }
 public void RemoveTag(PhotoTag tag)
 {
     throw new NotImplementedException();
 }
 public void AddTag(PhotoTag newTag)
 {
     throw new NotImplementedException();
 }
Exemple #15
0
 public bool HasTag(PhotoTag tag)
 {
     return(Tags.Contains(tag.ToString()));
 }