Ejemplo n.º 1
0
        /// <summary>
        /// Updates the square rectangle of the media.
        /// </summary>
        public async Task UpdateThumbnailAsync(string key, RectVM vm)
        {
            Validate(vm, "thumbnail rectangle");

            var media = await _db.Media
                        .Include(x => x.Tags)
                        .FirstOrDefaultAsync(x => x.Key == key);

            if (media == null)
            {
                throw new OperationException($"Media '{key}' does not exist.");
            }

            var rect = _mapper.Map <Rect>(vm);

            if (media.ThumbnailRect.Equals(rect))
            {
                return;
            }

            media.ThumbnailRect = rect;
            await _db.SaveChangesAsync();

            await _jobSvc.RunAsync(JobBuilder.For <UpdateThumbnailJob>().WithArgs(media.Key));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates a rectangle.
        /// </summary>
        private void Validate(RectVM vm, string descr)
        {
            if (vm == null)
            {
                throw new OperationException("Rect is not specified for " + descr);
            }

            vm.X      = Clamp(vm.X);
            vm.Y      = Clamp(vm.Y);
            vm.Width  = Clamp(vm.Width);
            vm.Height = Clamp(vm.Height);

            if (vm.X + vm.Width > 1)
            {
                vm.Width = Clamp(1 - vm.X);
            }

            if (vm.Y + vm.Height > 1)
            {
                vm.Height = Clamp(1 - vm.Y);
            }

            double Clamp(double value)
            {
                if (value < 0)
                {
                    return(0);
                }
                if (value > 1)
                {
                    return(1);
                }
                return(value);
            }
        }
Ejemplo n.º 3
0
 public Task UpdateThumbnail(string key, [FromBody] RectVM rect)
 {
     return(_mediaMgr.UpdateThumbnailAsync(key, rect));
 }