public virtual void DeletePicture(MediaFile picture) { Guard.NotNull(picture, nameof(picture)); // delete thumbs _imageCache.Delete(picture); // delete from url cache _cacheManager.Remove(MEDIACACHE_LOOKUP_KEY.FormatInvariant(picture.Id)); HasChanges = true; // delete from storage _storageProvider.Value.Remove(picture); // delete entity _pictureRepository.Delete(picture); }
public void DeleteFile(MediaFile file, bool permanent, bool force = false) { Guard.NotNull(file, nameof(file)); // Delete thumb _imageCache.Delete(file); if (!permanent) { file.Deleted = true; _fileRepo.Update(file); } else { try { if (!force && file.Tracks.Any()) { throw _exceptionFactory.DeleteTrackedFile(file, null); } // Delete entity _fileRepo.Delete(file); // Delete from storage _storageProvider.Remove(file); } catch (DbUpdateException ex) { if (ex.IsUniquenessViolationException()) { throw _exceptionFactory.DeleteTrackedFile(file, ex); } else { throw; } } catch (Exception) { throw; } } }
/// <summary> /// Creates a cacheable counterpart for a Picture object instance /// </summary> /// <param name="picture"></param> /// <returns></returns> protected virtual PictureInfo CreatePictureInfo(Picture picture) { if (picture == null) { return(null); } var extension = MimeTypes.MapMimeTypeToExtension(picture.MimeType); // Build virtual path with pattern "media/image/{id}/{SeoFileName}.{extension}" var path = "{0}{1}/{2}.{3}".FormatInvariant( _processedImagesRootPath, picture.Id, picture.SeoFilename.NullEmpty() ?? picture.Id.ToString(ImageCache.IdFormatString), extension); // Do some maintenance stuff EnsurePictureSizeResolved(picture, true); if (picture.IsNew) { _imageCache.Delete(picture); // We do not validate picture binary here to ensure that no exception ("Parameter is not valid") will be thrown UpdatePicture( picture, null, picture.MimeType, picture.SeoFilename, false, false); } return(new PictureInfo { Id = picture.Id, MimeType = picture.MimeType, Extension = extension, Path = path, Width = picture?.Width, Height = picture?.Height, }); }