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

Implement ctor accepting a connection string #14674

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions sdk/core/Azure.Core/src/Shared/ConnectionString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ internal sealed class ConnectionString
return new ConnectionString(ParseSegments(connectionString, segmentSeparator, keywordValueSeparator), segmentSeparator, keywordValueSeparator);
}

public static ConnectionString Empty(string segmentSeparator = ";", string keywordValueSeparator = "=") =>
new ConnectionString(new Dictionary<string, string>(), segmentSeparator, keywordValueSeparator);


private ConnectionString(Dictionary<string, string> pairs, string pairSeparator, string keywordValueSeparator)
{
_pairs = pairs;
Expand All @@ -34,6 +38,12 @@ public string GetRequired(string keyword) =>
public string? GetNonRequired(string keyword) =>
_pairs.TryGetValue(keyword, out var value) ? value : null;

public bool TryGetSegmentValue(string keyword, out string value) =>
_pairs.TryGetValue(keyword, out value);

public bool ContainsSegmentKey(string keyword) =>
_pairs.ContainsKey(keyword);

public void Replace(string keyword, string value)
{
if (_pairs.ContainsKey(keyword))
Expand All @@ -42,8 +52,16 @@ public void Replace(string keyword, string value)
}
}

public void Add(string keyword, string value) =>
_pairs.Add(keyword, value);

public override string ToString()
{
if (_pairs.Count == 0)
{
return string.Empty;
}

var stringBuilder = new StringBuilder();
var isFirst = true;
foreach (KeyValuePair<string, string> pair in _pairs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public partial interface ITableEntity
public partial class TableClient
{
protected TableClient() { }
public TableClient(string tableName, string connectionString) { }
public TableClient(string tableName, string connectionString, Azure.Data.Tables.TableClientOptions options = null) { }
public TableClient(string tableName, System.Uri endpoint, Azure.Data.Tables.TableClientOptions options = null) { }
public TableClient(string tableName, System.Uri endpoint, Azure.Data.Tables.TableSharedKeyCredential credential) { }
public TableClient(string tableName, System.Uri endpoint, Azure.Data.Tables.TableSharedKeyCredential credential, Azure.Data.Tables.TableClientOptions options = null) { }
public TableClient(string connectionString, string tableName) { }
public TableClient(string connectionString, string tableName, Azure.Data.Tables.TableClientOptions options = null) { }
public TableClient(System.Uri endpoint, string tableName, Azure.Data.Tables.TableClientOptions options = null) { }
public TableClient(System.Uri endpoint, string tableName, Azure.Data.Tables.TableSharedKeyCredential credential) { }
public TableClient(System.Uri endpoint, string tableName, Azure.Data.Tables.TableSharedKeyCredential credential, Azure.Data.Tables.TableClientOptions options = null) { }
public virtual System.Threading.Tasks.Task<Azure.Response> AddEntityAsync<T>(T entity, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where T : class, Azure.Data.Tables.ITableEntity, new() { throw null; }
public virtual Azure.Response AddEntity<T>(T entity, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) where T : class, Azure.Data.Tables.ITableEntity, new() { throw null; }
public virtual Azure.Response<Azure.Data.Tables.Models.TableItem> Create(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var tableClient = serviceClient.GetTableClient(tableName);

```C# Snippet:TablesSample1CreateTableClient
tableClient = new TableClient(
tableName,
new Uri(storageUri),
tableName,
new TableSharedKeyCredential(accountName, storageAccountKey));
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var tableClient = serviceClient.GetTableClient(tableName);

```C# Snippet:TablesSample1CreateTableClient
tableClient = new TableClient(
tableName,
new Uri(storageUri),
tableName,
new TableSharedKeyCredential(accountName, storageAccountKey));
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var tableClient = serviceClient.GetTableClient(tableName);

```C# Snippet:TablesSample1CreateTableClient
tableClient = new TableClient(
tableName,
new Uri(storageUri),
tableName,
new TableSharedKeyCredential(accountName, storageAccountKey));
```

Expand Down
1 change: 1 addition & 0 deletions sdk/tables/Azure.Data.Tables/src/Azure.Data.Tables.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Compile Include="$(AzureCoreSharedSources)AzureKeyCredentialPolicy.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ClientDiagnostics.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ConnectionString.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)ContentTypeUtilities.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)DiagnosticScope.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)DiagnosticScopeFactory.cs" Link="Shared\Core\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand Down
31 changes: 15 additions & 16 deletions sdk/tables/Azure.Data.Tables/src/TableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public class TableClient
/// <summary>
/// Initializes a new instance of the <see cref="TableClient"/>.
/// </summary>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="endpoint">
/// A <see cref="Uri"/> referencing the table service account.
/// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}.table.cosmos.azure.com/".
/// </param>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="options">
/// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
/// </param>
/// <exception cref="ArgumentException"><paramref name="endpoint"/> is not https.</exception>
public TableClient(string tableName, Uri endpoint, TableClientOptions options = null)
: this(tableName, endpoint, default(TableSharedKeyPipelinePolicy), options)
public TableClient(Uri endpoint, string tableName, TableClientOptions options = null)
: this(endpoint, tableName, default(TableSharedKeyPipelinePolicy), options)
{
Argument.AssertNotNull(tableName, nameof(tableName));

Expand All @@ -55,15 +55,15 @@ public TableClient(string tableName, Uri endpoint, TableClientOptions options =
/// <summary>
/// Initializes a new instance of the <see cref="TableClient"/>.
/// </summary>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="endpoint">
/// A <see cref="Uri"/> referencing the table service account.
/// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}.table.cosmos.azure.com/".
/// </param>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="credential">The shared key credential used to sign requests.</param>
/// <exception cref="ArgumentNullException"><paramref name="tableName"/> or <paramref name="credential"/> is null.</exception>
public TableClient(string tableName, Uri endpoint, TableSharedKeyCredential credential)
: this(tableName, endpoint, new TableSharedKeyPipelinePolicy(credential), null)
public TableClient(Uri endpoint, string tableName, TableSharedKeyCredential credential)
: this(endpoint, tableName, new TableSharedKeyPipelinePolicy(credential), null)
{
Argument.AssertNotNull(tableName, nameof(tableName));
Argument.AssertNotNull(credential, nameof(credential));
Expand All @@ -72,18 +72,18 @@ public TableClient(string tableName, Uri endpoint, TableSharedKeyCredential cred
/// <summary>
/// Initializes a new instance of the <see cref="TableClient"/>.
/// </summary>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="endpoint">
/// A <see cref="Uri"/> referencing the table service account.
/// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}.table.cosmos.azure.com/".
/// </param>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="credential">The shared key credential used to sign requests.</param>
/// <param name="options">
/// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="tableName"/> or <paramref name="credential"/> is null.</exception>
public TableClient(string tableName, Uri endpoint, TableSharedKeyCredential credential, TableClientOptions options = null)
: this(tableName, endpoint, new TableSharedKeyPipelinePolicy(credential), options)
public TableClient(Uri endpoint, string tableName, TableSharedKeyCredential credential, TableClientOptions options = null)
: this(endpoint, tableName, new TableSharedKeyPipelinePolicy(credential), options)
{
Argument.AssertNotNull(tableName, nameof(tableName));
Argument.AssertNotNull(credential, nameof(credential));
Expand All @@ -93,7 +93,6 @@ public TableClient(string tableName, Uri endpoint, TableSharedKeyCredential cred
/// <summary>
/// Initializes a new instance of the <see cref="TableServiceClient"/>.
/// </summary>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="connectionString">
/// A connection string includes the authentication information
/// required for your application to access data in an Azure Storage
Expand All @@ -103,14 +102,14 @@ public TableClient(string tableName, Uri endpoint, TableSharedKeyCredential cred
/// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string">
/// Configure Azure Storage connection strings</see>.
/// </param>
public TableClient(string tableName, string connectionString)
: this(tableName, connectionString, default)
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
public TableClient(string connectionString, string tableName)
: this(connectionString, tableName, default)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="TableServiceClient"/>.
/// </summary>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="connectionString">
/// A connection string includes the authentication information
/// required for your application to access data in an Azure Storage
Expand All @@ -120,10 +119,11 @@ public TableClient(string tableName, string connectionString)
/// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string">
/// Configure Azure Storage connection strings</see>.
/// </param>
/// <param name="tableName">The name of the table with which this client instance will interact.</param>
/// <param name="options">
/// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
/// </param>
public TableClient(string tableName, string connectionString, TableClientOptions options = null)
public TableClient(string connectionString, string tableName, TableClientOptions options = null)
{
Argument.AssertNotNull(connectionString, nameof(connectionString));

Expand All @@ -138,7 +138,6 @@ public TableClient(string tableName, string connectionString, TableClientOptions
_ => default
};

options ??= new TableClientOptions();
HttpPipeline pipeline = HttpPipelineBuilder.Build(options, policy);

_diagnostics = new ClientDiagnostics(options);
Expand All @@ -149,7 +148,7 @@ public TableClient(string tableName, string connectionString, TableClientOptions
_isPremiumEndpoint = TableServiceClient.IsPremiumEndpoint(connString.TableStorageUri.PrimaryUri);
}

internal TableClient(string tableName, Uri endpoint, TableSharedKeyPipelinePolicy policy, TableClientOptions options)
internal TableClient(Uri endpoint, string tableName, TableSharedKeyPipelinePolicy policy, TableClientOptions options)
{
Argument.AssertNotNull(tableName, nameof(tableName));
Argument.AssertNotNull(endpoint, nameof(endpoint));
Expand Down
Loading