Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmEmanuel committed Dec 30, 2023
1 parent abbcd8a commit ad3882d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions Source/AzBobbyTables.Core/AzDataTableService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace PipeHow.AzBobbyTables.Core;

public class AzDataTableService
{
private TableClient tableClient { get; set; }
private TableClient TableClient { get; set; }

/// <summary>
/// Cancellation token used within the AzDataTableService.
/// </summary>
private CancellationToken cancellationToken { get; }
private CancellationToken CancellationToken { get; }

/// <summary>
/// List of supported data types for the table.
Expand All @@ -36,7 +36,7 @@ public class AzDataTableService
"string"
};

private AzDataTableService(CancellationToken cancellationToken) => this.cancellationToken = cancellationToken;
private AzDataTableService(CancellationToken cancellationToken) => CancellationToken = cancellationToken;

private static void CreateIfNotExists(TableClient client, CancellationToken cancellationToken)
{
Expand All @@ -56,14 +56,14 @@ public static AzDataTableService CreateWithConnectionString(string connectionStr
{
var dataTableService = new AzDataTableService(cancellationToken);

TableClient client = new TableClient(connectionString, tableName);
TableClient client = new(connectionString, tableName);

if (createIfNotExists)
{
CreateIfNotExists(client, cancellationToken);
}

dataTableService.tableClient = client;
dataTableService.TableClient = client;
return dataTableService;
}
catch (Exception ex)
Expand All @@ -79,14 +79,14 @@ public static AzDataTableService CreateWithStorageKey(string storageAccountName,
var bobbyService = new AzDataTableService(cancellationToken);
var tableEndpoint = new Uri($"https://{storageAccountName}.table.core.windows.net/{tableName}");

TableClient client = new TableClient(tableEndpoint, tableName, new TableSharedKeyCredential(storageAccountName, storageAccountKey));
TableClient client = new(tableEndpoint, tableName, new TableSharedKeyCredential(storageAccountName, storageAccountKey));

if (createIfNotExists)
{
CreateIfNotExists(client, cancellationToken);
}

bobbyService.tableClient = client;
bobbyService.TableClient = client;
return bobbyService;
}
catch (Exception ex)
Expand All @@ -102,14 +102,14 @@ public static AzDataTableService CreateWithToken(string storageAccountName, stri
var bobbyService = new AzDataTableService(cancellationToken);
var tableEndpoint = new Uri($"https://{storageAccountName}.table.core.windows.net/{tableName}");

TableClient client = new TableClient(tableEndpoint, tableName, new ExternalTokenCredential(token, DateTimeOffset.Now.Add(TimeSpan.FromHours(1))));
TableClient client = new(tableEndpoint, tableName, new ExternalTokenCredential(token, DateTimeOffset.Now.Add(TimeSpan.FromHours(1))));

if (createIfNotExists)
{
CreateIfNotExists(client, cancellationToken);
}

bobbyService.tableClient = client;
bobbyService.TableClient = client;
return bobbyService;
}
catch (Exception ex)
Expand All @@ -134,14 +134,14 @@ public static AzDataTableService CreateWithSAS(Uri sasUrl, string tableName, boo
sasUrl = new Uri($"{urlParts.First()}{tableName}?{urlParts.Last()}");
}

TableClient client = new TableClient(sasUrl, sasCredential);
TableClient client = new(sasUrl, sasCredential);

if (createIfNotExists)
{
CreateIfNotExists(client, cancellationToken);
}

dataTableService.tableClient = client;
dataTableService.TableClient = client;
return dataTableService;
}
catch (Exception ex)
Expand All @@ -154,7 +154,7 @@ public void RemoveTable()
{
try
{
tableClient.Delete();
TableClient.Delete();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -368,7 +368,7 @@ public IEnumerable<PSObject> GetEntitiesFromTable(string query, string[] propert
try
{
// Declare type as IAsyncEnumerable to be able to overwrite it with LINQ results further down
IAsyncEnumerable<TableEntity> entities = tableClient.QueryAsync<TableEntity>(query, null, properties, cancellationToken);
IAsyncEnumerable<TableEntity> entities = TableClient.QueryAsync<TableEntity>(query, null, properties, CancellationToken);

// If user specified one or more properties to sort list by
// This may slow the query down a lot with a lot of results
Expand Down Expand Up @@ -422,7 +422,7 @@ public void ClearTable()
{
try
{
var entities = tableClient.Query<TableEntity>((string)null, null, new[] { "PartitionKey", "RowKey" });
var entities = TableClient.Query<TableEntity>((string)null, null, new[] { "PartitionKey", "RowKey" });

var transactions = new List<TableTransactionAction>();

Expand All @@ -448,7 +448,11 @@ private void SubmitTransaction(IList<TableTransactionAction> transactions)
// Loop through each group and submit up to 100 at a time
for (int i = 0; i < group.Count(); i += 100)
{
tableClient.SubmitTransaction(group.Skip(i).Take(100), cancellationToken);
var response = TableClient.SubmitTransaction(group.Skip(i).Take(100), CancellationToken);
foreach (var transactionResult in response.Value)
{
Console.WriteLine(transactionResult.Content.ToString());
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Module.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Describe "$ModuleName" {
}

It 'has no help file with empty documentation sections' {
Get-ChildItem "$RootDirectory\Docs\Help\*.md" | Select-String '{{|}}' | Should -BeNullOrEmpty
Get-ChildItem "$RootDirectory\Docs\Help\*.md" | Select-String '{{ Fill \w+ Description }}' | Should -BeNullOrEmpty
}

It 'has command <Command> defined in file in the correct directory' -TestCases $CommandTestCases {
Expand Down

0 comments on commit ad3882d

Please sign in to comment.