Skip to content

Commit

Permalink
Merge pull request #17561 from abpframework/liangshiwei/group15
Browse files Browse the repository at this point in the history
Group15 Enable nullable annotations
  • Loading branch information
maliming committed Sep 5, 2023
2 parents 8a32bfc + abeb0ec commit 0c8b0fb
Show file tree
Hide file tree
Showing 63 changed files with 179 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AbpSubscribeOptions
/// <summary>
/// An optional delegate used to configure the subscriptions.
/// </summary>
public Func<List<AbpSubscription>, Task> SubscriptionsCallback { get; set; }
public Func<List<AbpSubscription>, Task>? SubscriptionsCallback { get; set; }
}

/// <summary>
Expand All @@ -41,32 +41,32 @@ public class AbpSubscription
/// <summary>
/// Gets or sets the topic name.
/// </summary>
public string Topic { get; set; }
public string Topic { get; set; } = default!;

/// <summary>
/// Gets or sets the pubsub name
/// </summary>
public string PubsubName { get; set; }
public string PubsubName { get; set; } = default!;

/// <summary>
/// Gets or sets the route
/// </summary>
public string Route { get; set; }
public string? Route { get; set; }

/// <summary>
/// Gets or sets the routes
/// </summary>
public AbpRoutes Routes { get; set; }
public AbpRoutes? Routes { get; set; }

/// <summary>
/// Gets or sets the metadata.
/// </summary>
public AbpMetadata Metadata { get; set; }
public AbpMetadata? Metadata { get; set; }

/// <summary>
/// Gets or sets the deadletter topic.
/// </summary>
public string DeadLetterTopic { get; set; }
public string? DeadLetterTopic { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -99,12 +99,12 @@ public class AbpRoutes
/// <summary>
/// Gets or sets the default route
/// </summary>
public string Default { get; set; }
public string? Default { get; set; }

/// <summary>
/// Gets or sets the routing rules
/// </summary>
public List<AbpRule> Rules { get; set; }
public List<AbpRule>? Rules { get; set; }
}

/// <summary>
Expand All @@ -115,12 +115,12 @@ public class AbpRule
/// <summary>
/// Gets or sets the CEL expression to match this route.
/// </summary>
public string Match { get; set; }
public string Match { get; set; } = default!;

/// <summary>
/// Gets or sets the path of the route.
/// </summary>
public string Path { get; set; }
public string Path { get; set; } = default!;
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public static IEndpointConventionBuilder MapAbpSubscribeHandler(this IEndpointRo
return CreateSubscribeEndPoint(endpoints, options);
}

private static IEndpointConventionBuilder CreateSubscribeEndPoint(IEndpointRouteBuilder endpoints, AbpSubscribeOptions options = null)
private static IEndpointConventionBuilder CreateSubscribeEndPoint(IEndpointRouteBuilder endpoints, AbpSubscribeOptions? options = null)
{
if (endpoints is null)
{
Expand All @@ -175,7 +175,7 @@ private static IEndpointConventionBuilder CreateSubscribeEndPoint(IEndpointRoute

return endpoints.MapGet("dapr/subscribe", async context =>
{
var logger = context.RequestServices.GetRequiredService<ILoggerFactory>().CreateLogger("DaprTopicSubscription");
var logger = context.RequestServices.GetService<ILoggerFactory>()?.CreateLogger("DaprTopicSubscription");
var dataSource = context.RequestServices.GetRequiredService<EndpointDataSource>();
var subscriptions = dataSource.Endpoints
.OfType<RouteEndpoint>()
Expand All @@ -185,7 +185,7 @@ private static IEndpointConventionBuilder CreateSubscribeEndPoint(IEndpointRoute
var topicMetadata = e.Metadata.GetOrderedMetadata<ITopicMetadata>();
var originalTopicMetadata = e.Metadata.GetOrderedMetadata<IOriginalTopicMetadata>();
var subs = new List<(string PubsubName, string Name, string DeadLetterTopic, bool? EnableRawPayload, string Match, int Priority, Dictionary<string, string[]> OriginalTopicMetadata, string MetadataSeparator, RoutePattern RoutePattern)>();
var subs = new List<(string PubsubName, string Name, string? DeadLetterTopic, bool? EnableRawPayload, string Match, int Priority, Dictionary<string, string[]> OriginalTopicMetadata, string? MetadataSeparator, RoutePattern RoutePattern)>();
for (int i = 0; i < topicMetadata.Count(); i++)
{
Expand All @@ -211,7 +211,7 @@ private static IEndpointConventionBuilder CreateSubscribeEndPoint(IEndpointRoute
{
var first = e.First();
var rawPayload = e.Any(e => e.EnableRawPayload.GetValueOrDefault());
var metadataSeparator = e.FirstOrDefault(e => !string.IsNullOrEmpty(e.MetadataSeparator)).MetadataSeparator ?? ",";
var metadataSeparator = e.FirstOrDefault(e => !string.IsNullOrEmpty(e.MetadataSeparator)).MetadataSeparator?.ToString() ?? ",";
var rules = e.Where(e => !string.IsNullOrEmpty(e.Match)).ToList();
var defaultRoutes = e.Where(e => string.IsNullOrEmpty(e.Match)).Select(e => RoutePatternToString(e.RoutePattern)).ToList();
var defaultRoute = defaultRoutes.FirstOrDefault();
Expand Down Expand Up @@ -276,7 +276,7 @@ private static IEndpointConventionBuilder CreateSubscribeEndPoint(IEndpointRoute
.OrderBy(e => (e.PubsubName, e.Topic))
.ToList();
await options?.SubscriptionsCallback(subscriptions);
await options?.SubscriptionsCallback!(subscriptions)!;
await context.Response.WriteAsync(JsonSerializer.Serialize(subscriptions,
new JsonSerializerOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<RootNamespace />
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public virtual async Task<IActionResult> EventAsync()
}
else
{
var eventData = daprSerializer.Deserialize(data, distributedEventBus.GetEventType(topic));
await distributedEventBus.TriggerHandlersAsync(distributedEventBus.GetEventType(topic), eventData);
var eventData = daprSerializer.Deserialize(data, distributedEventBus.GetEventType(topic!));
await distributedEventBus.TriggerHandlersAsync(distributedEventBus.GetEventType(topic!), eventData);
}

return Ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<RootNamespace />
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public virtual bool IsValidDaprAppApiToken()
return expectedAppApiToken == headerAppApiToken;
}

public virtual string GetDaprAppApiTokenOrNull()
public virtual string? GetDaprAppApiTokenOrNull()
{
string apiTokenHeader = HttpContext.Request.Headers["dapr-api-token"];
string? apiTokenHeader = HttpContext.Request.Headers["dapr-api-token"];
if (string.IsNullOrEmpty(apiTokenHeader) || apiTokenHeader.Length < 1)
{
return null;
Expand All @@ -61,7 +61,7 @@ public virtual string GetDaprAppApiTokenOrNull()
return apiTokenHeader;
}

protected virtual string GetConfiguredAppApiTokenOrNull()
protected virtual string? GetConfiguredAppApiTokenOrNull()
{
return HttpContext
.RequestServices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static bool IsValidDaprAppApiToken(this HttpContext httpContext)
.IsValidDaprAppApiToken();
}

public static string GetDaprAppApiTokenOrNull(HttpContext httpContext)
public static string? GetDaprAppApiTokenOrNull(HttpContext httpContext)
{
return httpContext
.RequestServices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface IDaprAppApiTokenValidator

bool IsValidDaprAppApiToken();

string GetDaprAppApiTokenOrNull();
string? GetDaprAppApiTokenOrNull();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<PackageId>Volo.Abp.Imaging.Abstractions</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public interface IImageCompressor
{
Task<ImageCompressResult<Stream>> CompressAsync(
Stream stream,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default
);

Task<ImageCompressResult<byte[]>> CompressAsync(
byte[] bytes,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public interface IImageCompressorContributor
{
Task<ImageCompressResult<Stream>> TryCompressAsync(
Stream stream,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default);
Task<ImageCompressResult<byte[]>> TryCompressAsync(
byte[] bytes,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public interface IImageResizer
Task<ImageResizeResult<Stream>> ResizeAsync(
Stream stream,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default
);

Task<ImageResizeResult<byte[]>> ResizeAsync(
byte[] bytes,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public interface IImageResizerContributor
Task<ImageResizeResult<Stream>> TryResizeAsync(
Stream stream,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default);

Task<ImageResizeResult<byte[]>> TryResizeAsync(
byte[] bytes,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ImageCompressor(IEnumerable<IImageCompressorContributor> imageCompressorC

public virtual async Task<ImageCompressResult<Stream>> CompressAsync(
[NotNull] Stream stream,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
Check.NotNull(stream, nameof(stream));
Expand All @@ -45,7 +45,7 @@ public virtual async Task<ImageCompressResult<Stream>> CompressAsync(

public virtual async Task<ImageCompressResult<byte[]>> CompressAsync(
[NotNull] byte[] bytes,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
Check.NotNull(bytes, nameof(bytes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ImageResizer(
public virtual async Task<ImageResizeResult<Stream>> ResizeAsync(
[NotNull] Stream stream,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
Check.NotNull(stream, nameof(stream));
Expand All @@ -56,7 +56,7 @@ public virtual async Task<ImageResizeResult<Stream>> ResizeAsync(
public virtual async Task<ImageResizeResult<byte[]>> ResizeAsync(
[NotNull] byte[] bytes,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
Check.NotNull(bytes, nameof(bytes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<PackageId>Volo.Abp.Imaging.AspNetCore</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async override Task OnActionExecutionAsync(ActionExecutingContext context

foreach (var (key, value) in parameters)
{
object compressedValue = value switch {
object? compressedValue = value switch {
IFormFile file => await CompressImageAsync(file, imageCompressor),
IRemoteStreamContent remoteStreamContent => await CompressImageAsync(remoteStreamContent, imageCompressor),
Stream stream => await CompressImageAsync(stream, imageCompressor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async override Task OnActionExecutionAsync(ActionExecutingContext context

foreach (var (key, value) in parameters)
{
object resizedValue = value switch {
object? resizedValue = value switch {
IFormFile file => await ResizeImageAsync(file, imageResizer),
IRemoteStreamContent remoteStreamContent => await ResizeImageAsync(remoteStreamContent, imageResizer),
Stream stream => await ResizeImageAsync(stream, imageResizer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<PackageId>Volo.Abp.Imaging.ImageSharp</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ImageSharpImageCompressorContributor(IOptions<ImageSharpCompressOptions>

public virtual async Task<ImageCompressResult<Stream>> TryCompressAsync(
Stream stream,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
if (!string.IsNullOrWhiteSpace(mimeType) && !CanCompress(mimeType))
Expand Down Expand Up @@ -54,7 +54,7 @@ public virtual async Task<ImageCompressResult<Stream>> TryCompressAsync(

public virtual async Task<ImageCompressResult<byte[]>> TryCompressAsync(
byte[] bytes,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
if (!string.IsNullOrWhiteSpace(mimeType) && !CanCompress(mimeType))
Expand All @@ -75,7 +75,7 @@ public virtual async Task<ImageCompressResult<byte[]>> TryCompressAsync(
return new ImageCompressResult<byte[]>(newBytes, result.State);
}

protected virtual bool CanCompress(string mimeType)
protected virtual bool CanCompress(string? mimeType)
{
return mimeType switch {
MimeTypes.Image.Jpeg => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ImageSharpImageResizerContributor : IImageResizerContributor, ITran
public virtual async Task<ImageResizeResult<Stream>> TryResizeAsync(
Stream stream,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
if (!string.IsNullOrWhiteSpace(mimeType) && !CanResize(mimeType))
Expand Down Expand Up @@ -58,7 +58,7 @@ public virtual async Task<ImageResizeResult<Stream>> TryResizeAsync(
public virtual async Task<ImageResizeResult<byte[]>> TryResizeAsync(
byte[] bytes,
ImageResizeArgs resizeArgs,
[CanBeNull] string mimeType = null,
string? mimeType = null,
CancellationToken cancellationToken = default)
{
if (!string.IsNullOrWhiteSpace(mimeType) && !CanResize(mimeType))
Expand All @@ -82,7 +82,7 @@ public virtual async Task<ImageResizeResult<byte[]>> TryResizeAsync(
return new ImageResizeResult<byte[]>(newBytes, result.State);
}

protected virtual bool CanResize(string mimeType)
protected virtual bool CanResize(string? mimeType)
{
return mimeType switch {
MimeTypes.Image.Jpeg => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<PackageId>Volo.Abp.Imaging.MagicNet</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand Down
Loading

0 comments on commit 0c8b0fb

Please sign in to comment.