Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analyzer update #974

Merged
merged 6 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,7 @@ internal static async Task TearDown(IMinioClient minio, string bucketName)
ObjectLockConfiguration lockConfig = null;
try
{
VersioningConfiguration versioningConfig = null;
versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
var versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
.WithBucket(bucketName)
.WithVersions(true)).ConfigureAwait(false);
if (versioningConfig is not null &&
Expand Down Expand Up @@ -831,7 +830,7 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
.WithServerSideEncryption(ssec)
.WithCallbackStream(async (stream, cancellationToken) =>
{
Stream fileStream;
FileStream fileStream;
await using ((fileStream = File.Create(tempFileName)).ConfigureAwait(false))
{
await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion Minio.Tests/ReuseTcpConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private async Task<double> GetObjectLength(string bucket, string objectName)
var getObjectArgs = new GetObjectArgs()
.WithBucket(bucket)
.WithObject(objectName)
.WithCallbackStream(stream => stream.Dispose());
.WithCallbackStream(async (stream, _) => await stream.DisposeAsync().ConfigureAwait(false));
_ = await minioClient.GetObjectAsync(getObjectArgs).ConfigureAwait(false);

return objectLength;
Expand Down
30 changes: 23 additions & 7 deletions Minio/DataModel/Args/GetObjectArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public GetObjectArgs()
OffsetLengthSet = false;
}

internal Action<Stream> CallBack { get; private set; }
internal Func<Stream, CancellationToken, Task> FuncCallBack { get; private set; }
internal Func<Stream, CancellationToken, Task> CallBack { get; private set; }
internal long ObjectOffset { get; private set; }
internal long ObjectLength { get; private set; }
internal string FileName { get; private set; }
Expand All @@ -38,7 +37,7 @@ public GetObjectArgs()
internal override void Validate()
{
base.Validate();
if (CallBack is null && FuncCallBack is null && string.IsNullOrEmpty(FileName))
if (CallBack is null && string.IsNullOrEmpty(FileName))
throw new MinioException("Atleast one of " + nameof(CallBack) + ", CallBack method or " + nameof(FileName) +
" file path to save need to be set for GetObject operation.");

Expand Down Expand Up @@ -76,8 +75,7 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild
{
if (!string.IsNullOrEmpty(VersionId)) requestMessageBuilder.AddQueryParameter("versionId", $"{VersionId}");

if (CallBack is not null) requestMessageBuilder.ResponseWriter = CallBack;
else requestMessageBuilder.FunctionResponseWriter = FuncCallBack;
requestMessageBuilder.ResponseWriter = CallBack;

if (Headers.TryGetValue(S3ZipExtractKey, out var value))
requestMessageBuilder.AddQueryParameter(S3ZipExtractKey, value);
Expand All @@ -87,13 +85,31 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild

public GetObjectArgs WithCallbackStream(Action<Stream> cb)
{
CallBack = cb;
CallBack = (stream, cancellationToken) =>
{
var taskCompletionSource = new TaskCompletionSource<bool>();

if (cancellationToken.IsCancellationRequested)
taskCompletionSource.SetCanceled();
else
try
{
cb(stream);
taskCompletionSource.SetResult(true);
}
catch (Exception ex)
{
taskCompletionSource.SetException(ex);
}

return taskCompletionSource.Task;
};
return this;
}

public GetObjectArgs WithCallbackStream(Func<Stream, CancellationToken, Task> cb)
{
FuncCallBack = cb;
CallBack = cb;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Args/ListenBucketNotificationsArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild
requestMessageBuilder.AddQueryParameter("prefix", Prefix);
requestMessageBuilder.AddQueryParameter("suffix", Suffix);

requestMessageBuilder.FunctionResponseWriter = async (responseStream, cancellationToken) =>
requestMessageBuilder.ResponseWriter = async (responseStream, cancellationToken) =>
{
using var sr = new StreamReader(responseStream);
while (!sr.EndOfStream)
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/DeleteObjectsRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Replication/AndOperator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions Minio/HttpRequestMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public HttpRequestMessageBuilder(HttpMethod method, Uri requestUri)
}

public Uri RequestUri { get; set; }
public Action<Stream> ResponseWriter { get; set; }
public Func<Stream, CancellationToken, Task> FunctionResponseWriter { get; set; }
public Func<Stream, CancellationToken, Task> ResponseWriter { get; set; }
public HttpMethod Method { get; }

public HttpRequestMessage Request
Expand Down
2 changes: 1 addition & 1 deletion Minio/MinioClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static IMinioClient WithEndpoint(this IMinioClient minioClient, string en
{
if (minioClient is null) throw new ArgumentNullException(nameof(minioClient));

if (port < 1 || port > 65535)
if (port is < 1 or > 65535)
throw new ArgumentException(
string.Format(CultureInfo.InvariantCulture, "Port {0} is not a number between 1 and 65535", port),
nameof(port));
Expand Down
4 changes: 1 addition & 3 deletions Minio/RequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ private static async Task<ResponseResult> ExecuteTaskCoreAsync(this IMinioClient
.ConfigureAwait(false);
responseResult = new ResponseResult(request, response);
if (requestMessageBuilder.ResponseWriter is not null)
requestMessageBuilder.ResponseWriter(responseResult.ContentStream);
if (requestMessageBuilder.FunctionResponseWriter is not null)
await requestMessageBuilder.FunctionResponseWriter(responseResult.ContentStream, cancellationToken)
await requestMessageBuilder.ResponseWriter(responseResult.ContentStream, cancellationToken)
.ConfigureAwait(false);

var path = request.RequestUri.LocalPath.TrimStart('/').TrimEnd('/').Split('/');
Expand Down
Loading