Skip to content

Commit

Permalink
Fixes (#774)
Browse files Browse the repository at this point in the history
* Fix

* Null checks

* Cleanup

* Is or is not null checks

* Update nuget

* Fix concurency bug in older dotnet

* Fix buffer bug in older dotnet

* More null checks

* New name

* Disable analyzer again

* Move more to extensions

* Invert checks

* Fix
  • Loading branch information
martijn00 committed Apr 26, 2023
1 parent 5054421 commit 66cef4f
Show file tree
Hide file tree
Showing 103 changed files with 498 additions and 343 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<!--
<PackageReference Include="Roslynator.Analyzers" Version="4.2.0">
<PackageReference Include="Roslynator.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="AsyncFixer" Version="1.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="IDisposableAnalyzers" Version="4.0.4">
<PackageReference Include="IDisposableAnalyzers" Version="4.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ReflectionAnalyzers" Version="0.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.29">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.37">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ try
Console.WriteLine("Bytes scanned:" + resp.Stats.BytesScanned);
Console.WriteLine("Bytes returned:" + resp.Stats.BytesReturned);
Console.WriteLine("Bytes processed:" + resp.Stats.BytesProcessed);
if (resp.Progress != null)
if (resp.Progress is not null)
{
Console.WriteLine("Progress :" + resp.Progress.BytesProcessed);
}
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/ClearObjectRetention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class ClearObjectRetention
string objectName = "my-object-name",
string versionId = null)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: ClearObjectRetention");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/CustomRequestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class CustomRequestLogger
// Check if a bucket exists
public static async Task Run(IMinioClient minio)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for: set custom request logger");
Expand Down
4 changes: 3 additions & 1 deletion Minio.Examples/Cases/GetBucketEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class GetBucketEncryption
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: GetBucketEncryptionAsync");
Expand All @@ -30,7 +32,7 @@ public static class GetBucketEncryption
.WithBucket(bucketName)
).ConfigureAwait(false);
Console.WriteLine($"Got encryption configuration for bucket {bucketName}.");
if (config != null && config.Rule?.Apply != null)
if (config is not null && config.Rule?.Apply is not null)
Console.WriteLine("Server Side Encryption Algorithm: " + config.Rule.Apply.SSEAlgorithm);
Console.WriteLine();
}
Expand Down
4 changes: 3 additions & 1 deletion Minio.Examples/Cases/GetBucketLifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ public static class GetBucketLifecycle
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: GetBucketLifecycle");
var lfc = await minio.GetBucketLifecycleAsync(
new GetBucketLifecycleArgs()
.WithBucket(bucketName)
).ConfigureAwait(false);
if (lfc != null && lfc.Rules?.Count > 0)
if (lfc is not null && lfc.Rules?.Count > 0)
{
Console.WriteLine($"Got Bucket Lifecycle set for bucket {bucketName}.");
Console.WriteLine(lfc.MarshalXML());
Expand Down
4 changes: 3 additions & 1 deletion Minio.Examples/Cases/GetBucketReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ public static class GetBucketReplication
string bucketName = "my-bucket-name",
string replicationRuleID = "my-replication-rule-ID")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: GetBucketReplicationConfiguration");
var repl = await minio.GetBucketReplicationAsync(
new GetBucketReplicationArgs()
.WithBucket(bucketName)
).ConfigureAwait(false);
if (repl != null && repl.Rules?.Count > 0)
if (repl is not null && repl.Rules?.Count > 0)
{
Console.WriteLine($"Got Bucket Replication Configuration set for bucket {bucketName}.");
foreach (var rule in repl.Rules)
Expand Down
4 changes: 3 additions & 1 deletion Minio.Examples/Cases/GetBucketTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ public static class GetBucketTags
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: GetBucketTags");
var tags = await minio.GetBucketTagsAsync(
new GetBucketTagsArgs()
.WithBucket(bucketName)
).ConfigureAwait(false);
if (tags != null && tags.Tags?.Count > 0)
if (tags is not null && tags.Tags?.Count > 0)
{
Console.WriteLine($"Got Bucket Tags set for bucket {bucketName}.");
foreach (var tag in tags.Tags) Console.WriteLine(tag.Key + " : " + tag.Value);
Expand Down
6 changes: 4 additions & 2 deletions Minio.Examples/Cases/GetObjectLockConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ public static class GetObjectLockConfiguration
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: GetObjectLockConfiguration");
var config = await minio.GetObjectLockConfigurationAsync(
new GetObjectLockConfigurationArgs()
.WithBucket(bucketName)
).ConfigureAwait(false);
if (config != null)
if (config is not null)
{
Console.WriteLine($"Object lock configuration on bucket {bucketName} is : " + config.ObjectLockEnabled);
if (config.Rule?.DefaultRetention != null)
if (config.Rule?.DefaultRetention is not null)
{
var mode = config.Rule.DefaultRetention.Mode == RetentionMode.GOVERNANCE
? "GOVERNANCE"
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/GetObjectRetention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public static class GetObjectRetention
string objectName = "my-object-name",
string versionId = null)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: GetObjectRetentionAsync");
Expand Down
4 changes: 3 additions & 1 deletion Minio.Examples/Cases/GetObjectTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class GetObjectTags
string objectName = "my-object-name",
string versionId = null)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: GetObjectTags");
Expand All @@ -33,7 +35,7 @@ public static class GetObjectTags
.WithObject(objectName)
.WithVersionId(versionId)
).ConfigureAwait(false);
if (tags != null && tags.Tags?.Count > 0)
if (tags is not null && tags.Tags?.Count > 0)
{
Console.WriteLine($"Got tags set for object {bucketName}/{objectName}.");
foreach (var tag in tags.Tags) Console.WriteLine(tag.Key + " : " + tag.Value);
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/GetVersioning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static class GetVersioning
{
Console.WriteLine("Running example for API: GetVersioning, ");
var config = await minio.GetVersioningAsync(args).ConfigureAwait(false);
if (config == null)
if (config is null)
{
Console.WriteLine("Versioning Configuration not available for bucket " + bucketName);
Console.WriteLine();
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/MakeBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class MakeBucket
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name", string loc = "us-east-1")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: MakeBucketAsync");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/MakeBucketWithLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class MakeBucketWithLock
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name", string loc = "us-east-1")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: MakeBucketAsync");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/PresignedGetObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class PresignedGetObject
string bucketName = "my-bucket-name",
string objectName = "my-object-name")
{
if (client is null) throw new ArgumentNullException(nameof(client));

var reqParams = new Dictionary<string, string> { { "response-content-type", "application/json" } };
var args = new PresignedGetObjectArgs()
.WithBucket(bucketName)
Expand Down
1 change: 1 addition & 0 deletions Minio.Examples/Cases/PresignedPostPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class PresignedPostPolicy
string bucketName = "my-bucketname",
string objectName = "my-objectname")
{
if (client is null) throw new ArgumentNullException(nameof(client));
// default value for expiration is 2 minutes
var expiration = DateTime.UtcNow.AddMinutes(2);

Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/PresignedPutObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class PresignedPutObject
string bucketName = "my-bucket-name",
string objectName = "my-object-name")
{
if (client is null) throw new ArgumentNullException(nameof(client));

try
{
var args = new PresignedPutObjectArgs()
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/PutObjectWithTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal static class PutObjectWithTags
string objectName = "my-object-name",
string fileName = "location-of-file")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: PutObjectAsync with Tags");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveAllBucketNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ internal static class RemoveAllBucketNotifications
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: RemoveAllBucketNotificationAsync");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveBucketEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class RemoveBucketEncryption
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: RemoveBucketEncryptionAsync");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveBucketLifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class RemoveBucketLifecycle
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: RemoveBucketLifecycle");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveBucketReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class RemoveBucketReplication
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: RemoveBucketReplication");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveBucketTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class RemoveBucketTags
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: RemoveBucketTags");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal static class RemoveObject
string objectName = "my-object-name",
string versionId = null)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
var args = new RemoveObjectArgs()
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveObjectLockConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class RemoveObjectLockConfiguration
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: RemoveObjectLockConfiguration");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/RemoveObjectTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class RemoveObjectTags
string objectName = "my-object-name",
string versionId = null)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: RemoveObjectTags");
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/RemoveObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static class RemoveObjects
try
{
Console.WriteLine("Running example for API: RemoveObjectsAsync");
if (objectsList != null)
if (objectsList is not null)
{
var objArgs = new RemoveObjectsArgs()
.WithBucket(bucketName)
Expand Down
4 changes: 3 additions & 1 deletion Minio.Examples/Cases/RetryPolicyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static AsyncPolicy<ResponseResult> GetDefaultRetryPolicy()

public static RetryPolicyHandlingDelegate AsRetryDelegate(this AsyncPolicy<ResponseResult> policy)
{
return policy == null
return policy is null
? null
: async executeCallback => await policy.ExecuteAsync(executeCallback).ConfigureAwait(false);
}
Expand All @@ -82,6 +82,8 @@ internal static class RetryPolicyObject
string bucketName = "my-bucket-name",
string bucketObject = "my-object-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
var customPolicy = RetryPolicyHelper
Expand Down
7 changes: 5 additions & 2 deletions Minio.Examples/Cases/SelectObjectContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal static class SelectObjectContent
string objectName = "my-object-name",
string fileName = "my-file-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

var newObjectName = "new" + objectName;
try
{
Expand Down Expand Up @@ -77,11 +79,12 @@ internal static class SelectObjectContent
.WithInputSerialization(inputSerialization)
.WithOutputSerialization(outputSerialization);
var resp = await minio.SelectObjectContentAsync(args).ConfigureAwait(false);
await resp.Payload.CopyToAsync(Console.OpenStandardOutput()).ConfigureAwait(false);
using var standardOutput = Console.OpenStandardOutput();
await resp.Payload.CopyToAsync(standardOutput).ConfigureAwait(false);
Console.WriteLine("Bytes scanned:" + resp.Stats.BytesScanned);
Console.WriteLine("Bytes returned:" + resp.Stats.BytesReturned);
Console.WriteLine("Bytes processed:" + resp.Stats.BytesProcessed);
if (resp.Progress != null) Console.WriteLine("Progress :" + resp.Progress.BytesProcessed);
if (resp.Progress is not null) Console.WriteLine("Progress :" + resp.Progress.BytesProcessed);
}
catch (Exception e)
{
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/SetBucketEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static class SetBucketEncryption
string bucketName = "my-bucket-name",
ServerSideEncryptionConfiguration config = null)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: SetBucketEncryptionAsync");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/SetBucketLifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static class SetBucketLifecycle
string bucketName = "my-bucket-name",
LifecycleConfiguration lfc = null)
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: SetBucketLifecycle");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/SetBucketNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal static class SetBucketNotification
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: SetBucketNotificationAsync");
Expand Down
2 changes: 2 additions & 0 deletions Minio.Examples/Cases/SetBucketPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ internal static class SetBucketPolicy
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name")
{
if (minio is null) throw new ArgumentNullException(nameof(minio));

try
{
Console.WriteLine("Running example for API: SetPolicyAsync");
Expand Down

0 comments on commit 66cef4f

Please sign in to comment.