-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
677 additions
and
682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,81 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Foundatio | ||
namespace Foundatio; | ||
|
||
public abstract class AliyunConnectionStringBuilder | ||
{ | ||
public abstract class AliyunConnectionStringBuilder | ||
{ | ||
public string Endpoint { get; set; } | ||
public string Endpoint { get; set; } | ||
|
||
public string AccessKey { get; set; } | ||
public string AccessKey { get; set; } | ||
|
||
public string SecretKey { get; set; } | ||
public string SecretKey { get; set; } | ||
|
||
protected AliyunConnectionStringBuilder() { } | ||
protected AliyunConnectionStringBuilder() { } | ||
|
||
protected AliyunConnectionStringBuilder(string connectionString) | ||
{ | ||
if (String.IsNullOrEmpty(connectionString)) | ||
throw new ArgumentNullException(nameof(connectionString)); | ||
Parse(connectionString); | ||
} | ||
protected AliyunConnectionStringBuilder(string connectionString) | ||
{ | ||
if (String.IsNullOrEmpty(connectionString)) | ||
throw new ArgumentNullException(nameof(connectionString)); | ||
Parse(connectionString); | ||
} | ||
|
||
private void Parse(string connectionString) | ||
private void Parse(string connectionString) | ||
{ | ||
foreach (string[] option in connectionString | ||
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Where(kvp => kvp.Contains('=')) | ||
.Select(kvp => kvp.Split(new[] { '=' }, 2))) | ||
{ | ||
foreach (string[] 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)) | ||
{ | ||
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)); | ||
} | ||
throw new ArgumentException($"The option '{optionKey}' cannot be recognized in connection string.", nameof(connectionString)); | ||
} | ||
} | ||
} | ||
|
||
protected virtual bool ParseItem(string key, string value) | ||
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)) | ||
{ | ||
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, "AccessKeySecret", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Access Key Secret", 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)) | ||
{ | ||
Endpoint = value; | ||
return true; | ||
} | ||
return false; | ||
AccessKey = value; | ||
return true; | ||
} | ||
|
||
public override string ToString() | ||
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, "AccessKeySecret", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Access Key Secret", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Secret", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
string connectionString = String.Empty; | ||
if (!String.IsNullOrEmpty(AccessKey)) | ||
connectionString += "AccessKey=" + AccessKey + ";"; | ||
if (!String.IsNullOrEmpty(SecretKey)) | ||
connectionString += "SecretKey=" + SecretKey + ";"; | ||
if (!String.IsNullOrEmpty(Endpoint)) | ||
connectionString += "EndPoint=" + Endpoint + ";"; | ||
return connectionString; | ||
SecretKey = value; | ||
return true; | ||
} | ||
if (String.Equals(key, "EndPoint", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "End Point", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Endpoint = 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(Endpoint)) | ||
connectionString += "EndPoint=" + Endpoint + ";"; | ||
return connectionString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
|
||
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) | ||
{ | ||
[DebuggerStepThrough] | ||
public static ConfiguredTaskAwaitable<TResult> AnyContext<TResult>(this Task<TResult> task) | ||
{ | ||
return task.ConfigureAwait(false); | ||
} | ||
return task.ConfigureAwait(false); | ||
} | ||
|
||
[DebuggerStepThrough] | ||
public static ConfiguredTaskAwaitable AnyContext(this Task task) | ||
{ | ||
return task.ConfigureAwait(false); | ||
} | ||
[DebuggerStepThrough] | ||
public static ConfiguredTaskAwaitable AnyContext(this Task task) | ||
{ | ||
return task.ConfigureAwait(false); | ||
} | ||
} |
Oops, something went wrong.