-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
1 parent
4b50e1e
commit d809f1a
Showing
17 changed files
with
325 additions
and
246 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,27 +1,9 @@ | ||
identityazuretable | ||
ElCamino.Azure.Data.Tables | ||
================== | ||
|
||
This project provides a high performance cloud solution for ASP.NET Identity Core using Azure Table storage replacing the Entity Framework / MSSQL provider. | ||
Azure Table Storage odata query building and operators from the older Azure Storage SDKs and some other async, mapping, and batch helpers and/or extensions. | ||
|
||
[![Build Status](https://dev.azure.com/elcamino/Azure%20OpenSource/_apis/build/status/IdentityAzureTableCore?branchName=master)](https://dev.azure.com/elcamino/Azure%20OpenSource/_build/latest?definitionId=4&branchName=master) | ||
[![NuGet Badge](https://buildstats.info/nuget/ElCamino.AspNetCore.Identity.AzureTable)](https://www.nuget.org/packages/ElCamino.AspNetCore.Identity.AzureTable/) | ||
[![NuGet Badge](https://buildstats.info/nuget/ElCamino.AspNet.Identity.AzureTable)](https://www.nuget.org/packages/ElCamino.AspNet.Identity.AzureTable/) | ||
[![NuGet Badge](https://buildstats.info/nuget/ElCamino.Azure.Data.Tables)](https://www.nuget.org/packages/ElCamino.Azure.Data.Tables/) | ||
|
||
Project site at https://dlmelendez.github.io/identityazuretable/. | ||
|
||
Identity Core latest template | ||
``` | ||
dotnet new --install ElCamino.AspNetCore.Identity.AzureTable.Templates | ||
#MVC Template | ||
dotnet new mvc-id-azure-tables | ||
#Razor Pages Template | ||
dotnet new rzp-id-azure-tables | ||
``` | ||
|
||
Identity Core 3.x (uses PageModel - latest) - Use ElCamino.AspNetCore.Identity.AzureTable, sample mvc app: https://github.com/dlmelendez/identityazuretable/tree/master/sample/samplemvccore4 | ||
|
||
Identity Core 2.x (uses PageModel - latest) - Use ElCamino.AspNetCore.Identity.AzureTable, sample mvc app: https://github.com/dlmelendez/identityazuretable/tree/master/sample/samplemvccore3 | ||
|
||
Identity Core 2.x (uses MVC - older) - Use ElCamino.AspNetCore.Identity.AzureTable, sample mvc app: https://github.com/dlmelendez/identityazuretable/tree/master/sample/samplemvccore2 |
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
37 changes: 0 additions & 37 deletions
37
src/ElCamino.AspNetCore.Identity.AzureTable/Helpers/AzureSdkHelper.cs
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
src/ElCamino.AspNetCore.Identity.AzureTable/Helpers/Odata/EdmType.cs
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
src/ElCamino.AspNetCore.Identity.AzureTable/Helpers/Odata/QueryComparisons.cs
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/ElCamino.AspNetCore.Identity.AzureTable/Helpers/Odata/TableOperators.cs
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/ElCamino.AspNetCore.Identity.AzureTable/IdentityCloudContext.cs
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
172 changes: 83 additions & 89 deletions
172
...zureTable/Helpers/BatchOperationHelper.cs → ...Azure.Data.Tables/BatchOperationHelper.cs
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,89 +1,83 @@ | ||
// MIT License Copyright 2020 (c) David Melendez. All rights reserved. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Azure; | ||
using Azure.Data.Tables; | ||
|
||
namespace ElCamino.AspNetCore.Identity.AzureTable.Helpers | ||
{ | ||
/// <summary> | ||
/// Used to instantiate multiple TableBatchOperations when the | ||
/// TableOperation maximum is reached on a single TableBatchOperation | ||
/// </summary> | ||
public class BatchOperationHelper | ||
{ | ||
|
||
private readonly Dictionary<string, List<TableTransactionAction>> _batches = new(); | ||
|
||
private readonly TableClient _table; | ||
public BatchOperationHelper(TableClient table) | ||
{ | ||
_table = table; | ||
} | ||
|
||
public virtual void AddEntities<T>(IEnumerable<T> entities) where T : class, ITableEntity, new() | ||
{ | ||
foreach(T entity in entities) | ||
{ | ||
AddEntity<T>(entity); | ||
} | ||
} | ||
public virtual void AddEntity<T>(T entity) where T : class, ITableEntity, new() | ||
{ | ||
GetCurrent(entity.PartitionKey).Add(new TableTransactionAction(TableTransactionActionType.Add, entity)); | ||
} | ||
public virtual void DeleteEntity(string partitionKey, string rowKey, ETag ifMatch = default) | ||
{ | ||
GetCurrent(partitionKey).Add(new TableTransactionAction(TableTransactionActionType.Delete, new TableEntity(partitionKey, rowKey),ifMatch)); | ||
} | ||
|
||
public virtual async Task<IEnumerable<Response>> SubmitBatchAsync(CancellationToken cancellationToken = default) | ||
{ | ||
ConcurrentBag<Response> bag = new ConcurrentBag<Response>(); | ||
List<Task> batches = new List<Task>(_batches.Count); | ||
foreach(KeyValuePair<string, List<TableTransactionAction>> kv in _batches) | ||
{ | ||
batches.Add(_table.SubmitTransactionAsync(kv.Value, cancellationToken) | ||
.ContinueWith((result) => | ||
{ | ||
foreach (var r in result.Result.Value) | ||
{ | ||
bag.Add(r); | ||
} | ||
}, cancellationToken)); | ||
} | ||
await Task.WhenAll(batches).ConfigureAwait(false); | ||
Clear(); | ||
return bag; | ||
} | ||
|
||
public virtual void UpdateEntity<T>(T entity, ETag ifMatch, TableUpdateMode mode = TableUpdateMode.Merge) where T : class, ITableEntity, new() | ||
{ | ||
GetCurrent(entity.PartitionKey).Add(new TableTransactionAction(mode == TableUpdateMode.Merge? TableTransactionActionType.UpdateMerge : TableTransactionActionType.UpdateReplace, entity, ifMatch)); | ||
} | ||
|
||
public virtual void UpsertEntity<T>(T entity, TableUpdateMode mode = TableUpdateMode.Merge) where T : class, ITableEntity, new() | ||
{ | ||
GetCurrent(entity.PartitionKey).Add(new TableTransactionAction(mode == TableUpdateMode.Merge ? TableTransactionActionType.UpsertMerge : TableTransactionActionType.UpsertReplace, entity)); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
_batches.Clear(); | ||
} | ||
|
||
private List<TableTransactionAction> GetCurrent(string partitionKey) | ||
{ | ||
if(!_batches.ContainsKey(partitionKey)) | ||
{ | ||
_batches.Add(partitionKey, new List<TableTransactionAction>()); | ||
} | ||
|
||
return _batches[partitionKey]; | ||
} | ||
} | ||
} | ||
// MIT License Copyright 2020 (c) David Melendez. All rights reserved. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Concurrent; | ||
|
||
namespace Azure.Data.Tables | ||
{ | ||
/// <summary> | ||
/// Used to instantiate multiple TableBatchOperations when the | ||
/// TableOperation maximum is reached on a single TableBatchOperation | ||
/// </summary> | ||
public class BatchOperationHelper | ||
{ | ||
private readonly Dictionary<string, List<TableTransactionAction>> _batches = new(); | ||
|
||
private readonly TableClient _table; | ||
|
||
public BatchOperationHelper(TableClient table) | ||
{ | ||
_table = table; | ||
} | ||
|
||
public virtual void AddEntities<T>(IEnumerable<T> entities) where T : class, ITableEntity, new() | ||
{ | ||
foreach(T entity in entities) | ||
{ | ||
AddEntity<T>(entity); | ||
} | ||
} | ||
public virtual void AddEntity<T>(T entity) where T : class, ITableEntity, new() | ||
{ | ||
GetCurrent(entity.PartitionKey).Add(new TableTransactionAction(TableTransactionActionType.Add, entity)); | ||
} | ||
public virtual void DeleteEntity(string partitionKey, string rowKey, ETag ifMatch = default) | ||
{ | ||
GetCurrent(partitionKey).Add(new TableTransactionAction(TableTransactionActionType.Delete, new TableEntity(partitionKey, rowKey),ifMatch)); | ||
} | ||
|
||
public virtual async Task<IEnumerable<Response>> SubmitBatchAsync(CancellationToken cancellationToken = default) | ||
{ | ||
ConcurrentBag<Response> bag = new ConcurrentBag<Response>(); | ||
List<Task> batches = new List<Task>(_batches.Count); | ||
foreach(KeyValuePair<string, List<TableTransactionAction>> kv in _batches) | ||
{ | ||
batches.Add(_table.SubmitTransactionAsync(kv.Value, cancellationToken) | ||
.ContinueWith((result) => | ||
{ | ||
foreach (var r in result.Result.Value) | ||
{ | ||
bag.Add(r); | ||
} | ||
}, cancellationToken)); | ||
} | ||
await Task.WhenAll(batches).ConfigureAwait(false); | ||
Clear(); | ||
return bag; | ||
} | ||
|
||
public virtual void UpdateEntity<T>(T entity, ETag ifMatch, TableUpdateMode mode = TableUpdateMode.Merge) where T : class, ITableEntity, new() | ||
{ | ||
GetCurrent(entity.PartitionKey).Add(new TableTransactionAction(mode == TableUpdateMode.Merge? TableTransactionActionType.UpdateMerge : TableTransactionActionType.UpdateReplace, entity, ifMatch)); | ||
} | ||
|
||
public virtual void UpsertEntity<T>(T entity, TableUpdateMode mode = TableUpdateMode.Merge) where T : class, ITableEntity, new() | ||
{ | ||
GetCurrent(entity.PartitionKey).Add(new TableTransactionAction(mode == TableUpdateMode.Merge ? TableTransactionActionType.UpsertMerge : TableTransactionActionType.UpsertReplace, entity)); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
_batches.Clear(); | ||
} | ||
|
||
private List<TableTransactionAction> GetCurrent(string partitionKey) | ||
{ | ||
if(!_batches.ContainsKey(partitionKey)) | ||
{ | ||
_batches.Add(partitionKey, new List<TableTransactionAction>()); | ||
} | ||
|
||
return _batches[partitionKey]; | ||
} | ||
} | ||
} |
Oops, something went wrong.