|
@@ -12,6 +12,7 @@ using TEAMModelOS.SDK.Helper.Security.AESCrypt;
|
|
using TEAMModelOS.SDK.Context.Exception;
|
|
using TEAMModelOS.SDK.Context.Exception;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
using TEAMModelOS.SDK.Context.Attributes.Table;
|
|
using TEAMModelOS.SDK.Context.Attributes.Table;
|
|
|
|
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
|
|
|
namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
{
|
|
{
|
|
@@ -75,12 +76,12 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
|
|
|
|
public async Task<List<T>> FindAll<T>() where T : TableEntity, new()
|
|
public async Task<List<T>> FindAll<T>() where T : TableEntity, new()
|
|
{
|
|
{
|
|
- string TableName= await InitializeTable<T>();
|
|
|
|
|
|
+ string TableName = await InitializeTable<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
- return await QueryList<T>(exQuery , TableName);
|
|
|
|
|
|
+ return await QueryList<T>(exQuery, TableName);
|
|
}
|
|
}
|
|
|
|
|
|
- private async Task<List<T>> QueryList<T>(TableQuery<T> exQuery ,string TableName) where T : TableEntity, new()
|
|
|
|
|
|
+ private async Task<List<T>> QueryList<T>(TableQuery<T> exQuery, string TableName) where T : TableEntity, new()
|
|
{
|
|
{
|
|
TableContinuationToken continuationToken = null;
|
|
TableContinuationToken continuationToken = null;
|
|
List<T> entitys = new List<T>();
|
|
List<T> entitys = new List<T>();
|
|
@@ -95,9 +96,9 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
} while (continuationToken != null);
|
|
} while (continuationToken != null);
|
|
return entitys;
|
|
return entitys;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
|
|
- private async Task<T> QueryObject<T>(TableQuery<T> exQuery ,string TableName) where T : TableEntity, new()
|
|
|
|
|
|
+
|
|
|
|
+ private async Task<T> QueryObject<T>(TableQuery<T> exQuery, string TableName) where T : TableEntity, new()
|
|
{
|
|
{
|
|
TableContinuationToken continuationToken = null;
|
|
TableContinuationToken continuationToken = null;
|
|
T entity = new T();
|
|
T entity = new T();
|
|
@@ -113,7 +114,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
return entity;
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<int> Count<T>(TableContinuationToken continuationToken ) where T : TableEntity, new()
|
|
|
|
|
|
+ public async Task<int> Count<T>(TableContinuationToken continuationToken) where T : TableEntity, new()
|
|
{
|
|
{
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
@@ -132,7 +133,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
|
|
|
|
public async Task<int> Count<T>() where T : TableEntity, new()
|
|
public async Task<int> Count<T>() where T : TableEntity, new()
|
|
{
|
|
{
|
|
- string TableName = await InitializeTable<T>();
|
|
|
|
|
|
+ string TableName = await InitializeTable<T>();
|
|
TableContinuationToken continuationToken = null;
|
|
TableContinuationToken continuationToken = null;
|
|
var exQuery = new TableQuery<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
List<T> entitys = new List<T>();
|
|
List<T> entitys = new List<T>();
|
|
@@ -148,13 +149,13 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
return entitys.Count;
|
|
return entitys.Count;
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<T> FindByRowKey<T>(string RowKey) where T : TableEntity, new()
|
|
|
|
|
|
+ public async Task<T> FindByRowKey<T>(string id) where T : TableEntity, new()
|
|
{
|
|
{
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
- if (!string.IsNullOrEmpty(RowKey))
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(id))
|
|
{
|
|
{
|
|
- string typeStr = SwitchType(RowKey, "RowKey");
|
|
|
|
|
|
+ string typeStr = SwitchType(id, "RowKey");
|
|
exQuery.Where(typeStr);
|
|
exQuery.Where(typeStr);
|
|
// exQuery.Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, id));
|
|
// exQuery.Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, id));
|
|
return await QueryObject<T>(exQuery, TableName);
|
|
return await QueryObject<T>(exQuery, TableName);
|
|
@@ -212,7 +213,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
|
|
|
|
var exQuery = new TableQuery<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
- if (!string.IsNullOrEmpty(key) &&null!= value && !string.IsNullOrEmpty(value.ToString()))
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(key) && value != null && !string.IsNullOrEmpty(value.ToString()))
|
|
{
|
|
{
|
|
|
|
|
|
string typeStr = SwitchType(value, key);
|
|
string typeStr = SwitchType(value, key);
|
|
@@ -291,7 +292,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
{
|
|
{
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
var exQuery = new TableQuery<T>();
|
|
- if (!string.IsNullOrEmpty(key) && null != value && !string.IsNullOrEmpty(value.ToString()))
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(key) && value != null && !string.IsNullOrEmpty(value.ToString()))
|
|
{
|
|
{
|
|
|
|
|
|
string typeStr = SwitchType(value, key);
|
|
string typeStr = SwitchType(value, key);
|
|
@@ -352,6 +353,10 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
|
|
|
|
public async Task<List<T>> SaveAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
public async Task<List<T>> SaveAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
{
|
|
{
|
|
|
|
+ if (entitys.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
IList<TableResult> result = null;
|
|
IList<TableResult> result = null;
|
|
Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
|
|
Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
|
|
@@ -367,6 +372,10 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
|
|
|
|
public async Task<List<T>> UpdateAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
public async Task<List<T>> UpdateAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
{
|
|
{
|
|
|
|
+ if (entitys.IsEmpty()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
IList<TableResult> result = null;
|
|
IList<TableResult> result = null;
|
|
Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
|
|
Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
|
|
@@ -382,35 +391,28 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
|
|
|
|
public async Task<List<T>> SaveOrUpdateAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
public async Task<List<T>> SaveOrUpdateAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
{
|
|
{
|
|
- string TableName = await InitializeTable<T>();
|
|
|
|
- IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
|
|
|
|
- foreach (IGrouping<string, T> group in entitys.GroupBy(c =>c.PartitionKey))
|
|
|
|
|
|
+ if (entitys.IsEmpty())
|
|
{
|
|
{
|
|
- Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>();
|
|
|
|
-
|
|
|
|
- dictInfo.Add(group.Key, group.ToList());
|
|
|
|
- listInfo.Add(dictInfo);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- foreach (Dictionary<string ,List<T>> dict in listInfo) {
|
|
|
|
- IList<TableResult> result = null;
|
|
|
|
- foreach (string key in dict.Keys) {
|
|
|
|
- List<T> values = dict[key];
|
|
|
|
- Parallel.ForEach(Partitioner.Create(0, values.Count, 100),
|
|
|
|
- async range =>
|
|
|
|
- {
|
|
|
|
- TableBatchOperation batchOperation = new TableBatchOperation();
|
|
|
|
- for (Int32 i = range.Item1; i < range.Item2; i++)
|
|
|
|
- batchOperation.InsertOrReplace(values[i]);
|
|
|
|
- result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
+ string TableName = await InitializeTable<T>();
|
|
|
|
+ IList<TableResult> result = null;
|
|
|
|
+ Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
|
|
|
|
+ async range =>
|
|
|
|
+ {
|
|
|
|
+ TableBatchOperation batchOperation = new TableBatchOperation();
|
|
|
|
+ for (Int32 i = range.Item1; i < range.Item2; i++)
|
|
|
|
+ batchOperation.InsertOrReplace(entitys[i]);
|
|
|
|
+ result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
+ });
|
|
return entitys;
|
|
return entitys;
|
|
}
|
|
}
|
|
public async Task<List<T>> DeleteAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
public async Task<List<T>> DeleteAll<T>(List<T> entitys) where T : TableEntity, new()
|
|
{
|
|
{
|
|
|
|
+ if (entitys.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
IList<TableResult> result = null;
|
|
IList<TableResult> result = null;
|
|
Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
|
|
Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
|