From 4bbdb4f6faf3b1750465c5e4f6a7262019be0188 Mon Sep 17 00:00:00 2001 From: Salih Date: Mon, 29 May 2023 10:06:43 +0300 Subject: [PATCH] Add [NotNull] and Check.NotNull for the ImageResizer/ImageCompressor --- .../Volo/Abp/Imaging/ImageCompressor.cs | 15 +++++++++++++-- .../Volo/Abp/Imaging/ImageResizer.cs | 8 ++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageCompressor.cs b/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageCompressor.cs index a4d6fd1aa4..c68c7e3773 100644 --- a/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageCompressor.cs +++ b/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageCompressor.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using Volo.Abp.DependencyInjection; using Volo.Abp.Threading; @@ -19,8 +20,13 @@ public class ImageCompressor : IImageCompressor, ITransientDependency CancellationTokenProvider = cancellationTokenProvider; } - public virtual async Task> CompressAsync(Stream stream, string mimeType = null, CancellationToken cancellationToken = default) + public virtual async Task> CompressAsync( + [NotNull] Stream stream, + [CanBeNull] string mimeType = null, + CancellationToken cancellationToken = default) { + Check.NotNull(stream, nameof(stream)); + foreach (var imageCompressorContributor in ImageCompressorContributors) { var result = await imageCompressorContributor.TryCompressAsync(stream, mimeType, CancellationTokenProvider.FallbackToProvider(cancellationToken)); @@ -36,8 +42,13 @@ public class ImageCompressor : IImageCompressor, ITransientDependency return new ImageCompressResult(stream, ImageProcessState.Unsupported); } - public virtual async Task> CompressAsync(byte[] bytes, string mimeType = null, CancellationToken cancellationToken = default) + public virtual async Task> CompressAsync( + [NotNull] byte[] bytes, + [CanBeNull] string mimeType = null, + CancellationToken cancellationToken = default) { + Check.NotNull(bytes, nameof(bytes)); + foreach (var imageCompressorContributor in ImageCompressorContributors) { var result = await imageCompressorContributor.TryCompressAsync(bytes, mimeType, CancellationTokenProvider.FallbackToProvider(cancellationToken)); diff --git a/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageResizer.cs b/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageResizer.cs index c16eae19b9..5576197797 100644 --- a/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageResizer.cs +++ b/framework/src/Volo.Abp.Imaging.Abstractions/Volo/Abp/Imaging/ImageResizer.cs @@ -28,11 +28,13 @@ public class ImageResizer : IImageResizer, ITransientDependency } public virtual async Task> ResizeAsync( - Stream stream, + [NotNull] Stream stream, ImageResizeArgs resizeArgs, [CanBeNull] string mimeType = null, CancellationToken cancellationToken = default) { + Check.NotNull(stream, nameof(stream)); + ChangeDefaultResizeMode(resizeArgs); foreach (var imageResizerContributor in ImageResizerContributors) @@ -51,11 +53,13 @@ public class ImageResizer : IImageResizer, ITransientDependency } public virtual async Task> ResizeAsync( - byte[] bytes, + [NotNull] byte[] bytes, ImageResizeArgs resizeArgs, [CanBeNull] string mimeType = null, CancellationToken cancellationToken = default) { + Check.NotNull(bytes, nameof(bytes)); + ChangeDefaultResizeMode(resizeArgs); foreach (var imageResizerContributor in ImageResizerContributors)