Skip to content

Commit

Permalink
ran dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Mar 27, 2024
1 parent cf6712a commit 0391c5d
Show file tree
Hide file tree
Showing 24 changed files with 2,346 additions and 2,368 deletions.
12 changes: 8 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ csharp_indent_labels = one_less_than_current
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion

# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error

# Types: use keywords instead of BCL types, and permit var only when the type is clear
csharp_style_var_for_built_in_types = false:suggestion
Expand Down Expand Up @@ -154,6 +154,10 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

# Custom
csharp_style_namespace_declarations = file_scoped:error
dotnet_diagnostic.IDE0005.severity = error # Using directive is unnecessary.

# C++ Files
[*.{cpp,h,in}]
curly_bracket_next_line = true
Expand Down
161 changes: 80 additions & 81 deletions src/Foundatio.AWS/AmazonConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,105 +3,104 @@
using Amazon;
using Amazon.Runtime;

namespace Foundatio
namespace Foundatio;

public abstract class AmazonConnectionStringBuilder
{
public abstract class AmazonConnectionStringBuilder
{
public string AccessKey { get; set; }
public string AccessKey { get; set; }

public string SecretKey { get; set; }
public string SecretKey { get; set; }

public string Region { get; set; }
public string Region { get; set; }

public string ServiceUrl { get; set; }
public string ServiceUrl { get; set; }

protected AmazonConnectionStringBuilder() { }
protected AmazonConnectionStringBuilder() { }

protected AmazonConnectionStringBuilder(string connectionString)
{
if (String.IsNullOrEmpty(connectionString))
throw new ArgumentNullException(nameof(connectionString));
protected AmazonConnectionStringBuilder(string connectionString)
{
if (String.IsNullOrEmpty(connectionString))
throw new ArgumentNullException(nameof(connectionString));

Parse(connectionString);
}
Parse(connectionString);
}

private void Parse(string connectionString)
private void Parse(string connectionString)
{
foreach (var option in connectionString
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Where(kvp => kvp.Contains('='))
.Select(kvp => kvp.Split(new[] { '=' }, 2)))
{
foreach (var option in connectionString
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Where(kvp => kvp.Contains('='))
.Select(kvp => kvp.Split(new[] { '=' }, 2)))
{
string optionKey = option[0].Trim();
string optionValue = option[1].Trim();
if (!ParseItem(optionKey, optionValue))
throw new ArgumentException($"The option '{optionKey}' cannot be recognized in connection string.", nameof(connectionString));
}
string optionKey = option[0].Trim();
string optionValue = option[1].Trim();
if (!ParseItem(optionKey, optionValue))
throw new ArgumentException($"The option '{optionKey}' cannot be recognized in connection string.", nameof(connectionString));
}
}

public AWSCredentials GetCredentials()
{
return !String.IsNullOrEmpty(AccessKey)
? new BasicAWSCredentials(AccessKey, SecretKey)
: null;
}

public AWSCredentials GetCredentials()
public RegionEndpoint GetRegion()
{
return !String.IsNullOrEmpty(Region)
? RegionEndpoint.GetBySystemName(Region)
: null;
}

protected virtual bool ParseItem(string key, string value)
{
if (String.Equals(key, "AccessKey", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Access Key", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "AccessKeyId", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Access Key Id", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Id", StringComparison.OrdinalIgnoreCase))
{
return !String.IsNullOrEmpty(AccessKey)
? new BasicAWSCredentials(AccessKey, SecretKey)
: null;
AccessKey = value;
return true;
}

public RegionEndpoint GetRegion()
if (String.Equals(key, "SecretKey", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Secret Key", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "SecretAccessKey", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Secret Access Key", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Secret", StringComparison.OrdinalIgnoreCase))
{
return !String.IsNullOrEmpty(Region)
? RegionEndpoint.GetBySystemName(Region)
: null;
SecretKey = value;
return true;
}

protected virtual bool ParseItem(string key, string value)
if (String.Equals(key, "EndPoint", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "End Point", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Region", StringComparison.OrdinalIgnoreCase))
{
if (String.Equals(key, "AccessKey", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Access Key", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "AccessKeyId", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Access Key Id", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Id", StringComparison.OrdinalIgnoreCase))
{
AccessKey = value;
return true;
}
if (String.Equals(key, "SecretKey", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Secret Key", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "SecretAccessKey", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Secret Access Key", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Secret", StringComparison.OrdinalIgnoreCase))
{
SecretKey = value;
return true;
}
if (String.Equals(key, "EndPoint", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "End Point", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Region", StringComparison.OrdinalIgnoreCase))
{
Region = value;
return true;
}
if (String.Equals(key, "Service", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Service Url", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "ServiceUrl", StringComparison.OrdinalIgnoreCase))
{
ServiceUrl = value;
return true;
}
return false;
Region = value;
return true;
}

public override string ToString()
if (String.Equals(key, "Service", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "Service Url", StringComparison.OrdinalIgnoreCase) ||
String.Equals(key, "ServiceUrl", StringComparison.OrdinalIgnoreCase))
{
string connectionString = String.Empty;
if (!String.IsNullOrEmpty(AccessKey))
connectionString += "AccessKey=" + AccessKey + ";";
if (!String.IsNullOrEmpty(SecretKey))
connectionString += "SecretKey=" + SecretKey + ";";
if (!String.IsNullOrEmpty(Region))
connectionString += "Region=" + Region + ";";
if (!String.IsNullOrEmpty(ServiceUrl))
connectionString += "ServiceUrl=" + ServiceUrl + ";";
return connectionString;
ServiceUrl = value;
return true;
}
return false;
}

public override string ToString()
{
string connectionString = String.Empty;
if (!String.IsNullOrEmpty(AccessKey))
connectionString += "AccessKey=" + AccessKey + ";";
if (!String.IsNullOrEmpty(SecretKey))
connectionString += "SecretKey=" + SecretKey + ";";
if (!String.IsNullOrEmpty(Region))
connectionString += "Region=" + Region + ";";
if (!String.IsNullOrEmpty(ServiceUrl))
connectionString += "ServiceUrl=" + ServiceUrl + ";";
return connectionString;
}
}
61 changes: 30 additions & 31 deletions src/Foundatio.AWS/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,43 @@
using Amazon.S3.Model;
using Foundatio.Storage;

namespace Foundatio.AWS.Extensions
namespace Foundatio.AWS.Extensions;

internal static class Extensions
{
internal static class Extensions
internal static bool IsSuccessful(this HttpStatusCode code)
{
internal static bool IsSuccessful(this HttpStatusCode code)
{
return (int)code < 400;
}
return (int)code < 400;
}

internal static FileSpec ToFileInfo(this S3Object blob)
{
if (blob == null)
return null;
internal static FileSpec ToFileInfo(this S3Object blob)
{
if (blob == null)
return null;

return new FileSpec
{
Path = blob.Key,
Size = blob.Size,
Modified = blob.LastModified.ToUniversalTime(),
Created = blob.LastModified.ToUniversalTime() // TODO: Need to fix this
};
}
return new FileSpec
{
Path = blob.Key,
Size = blob.Size,
Modified = blob.LastModified.ToUniversalTime(),
Created = blob.LastModified.ToUniversalTime() // TODO: Need to fix this
};
}

internal static IEnumerable<S3Object> MatchesPattern(this IEnumerable<S3Object> blobs, Regex patternRegex)
internal static IEnumerable<S3Object> MatchesPattern(this IEnumerable<S3Object> blobs, Regex patternRegex)
{
return blobs.Where(blob =>
{
return blobs.Where(blob =>
{
var info = blob.ToFileInfo();
if (info?.Path is null)
return false;
var info = blob.ToFileInfo();
if (info?.Path is null)
return false;

return patternRegex == null || patternRegex.IsMatch(info.Path);
});
}
return patternRegex == null || patternRegex.IsMatch(info.Path);
});
}

internal static bool IsDirectory(this FileSpec file)
{
return file.Path is not null && file.Size is 0 && file.Path.EndsWith("/");
}
internal static bool IsDirectory(this FileSpec file)
{
return file.Path is not null && file.Size is 0 && file.Path.EndsWith("/");
}
}
35 changes: 17 additions & 18 deletions src/Foundatio.AWS/Extensions/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@
using System.Threading.Tasks;
using Foundatio.AsyncEx;

namespace Foundatio.Extensions
namespace Foundatio.Extensions;

internal static class TaskExtensions
{
internal static class TaskExtensions
{

[DebuggerStepThrough]
public static ConfiguredTaskAwaitable<TResult> AnyContext<TResult>(this Task<TResult> task)
{
return task.ConfigureAwait(continueOnCapturedContext: false);
}
[DebuggerStepThrough]
public static ConfiguredTaskAwaitable<TResult> AnyContext<TResult>(this Task<TResult> task)
{
return task.ConfigureAwait(continueOnCapturedContext: false);
}

[DebuggerStepThrough]
public static ConfiguredTaskAwaitable AnyContext(this Task task)
{
return task.ConfigureAwait(continueOnCapturedContext: false);
}
[DebuggerStepThrough]
public static ConfiguredTaskAwaitable AnyContext(this Task task)
{
return task.ConfigureAwait(continueOnCapturedContext: false);
}

[DebuggerStepThrough]
public static ConfiguredTaskAwaitable<TResult> AnyContext<TResult>(this AwaitableDisposable<TResult> task) where TResult : IDisposable
{
return task.ConfigureAwait(continueOnCapturedContext: false);
}
[DebuggerStepThrough]
public static ConfiguredTaskAwaitable<TResult> AnyContext<TResult>(this AwaitableDisposable<TResult> task) where TResult : IDisposable
{
return task.ConfigureAwait(continueOnCapturedContext: false);
}
}
Loading

0 comments on commit 0391c5d

Please sign in to comment.