|
@@ -65,9 +65,8 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
object[] attributes = type.GetCustomAttributes(true);
|
|
object[] attributes = type.GetCustomAttributes(true);
|
|
foreach (object attribute in attributes) //2.通过映射,找到成员属性上关联的特性类实例,
|
|
foreach (object attribute in attributes) //2.通过映射,找到成员属性上关联的特性类实例,
|
|
{
|
|
{
|
|
- if (attribute is TableSpaceAttribute)
|
|
|
|
|
|
+ if (attribute is TableSpaceAttribute tableSpace)
|
|
{
|
|
{
|
|
- TableSpaceAttribute tableSpace = (TableSpaceAttribute)attribute;
|
|
|
|
Name = tableSpace.Name + Name;
|
|
Name = tableSpace.Name + Name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -358,34 +357,68 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
string TableName = await InitializeTable<T>();
|
|
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.Insert(entitys[i]);
|
|
|
|
- result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
- });
|
|
|
|
|
|
+ IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
|
|
|
|
+ foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
|
|
|
|
+ {
|
|
|
|
+ { 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.Insert(values[i]);
|
|
|
|
+ result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return entitys;
|
|
return entitys;
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
+ if (entitys.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
string TableName = await InitializeTable<T>();
|
|
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.Replace(entitys[i]);
|
|
|
|
- result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
- });
|
|
|
|
|
|
+ IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
|
|
|
|
+ foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
|
|
|
|
+ {
|
|
|
|
+ { 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.Replace(values[i]);
|
|
|
|
+ result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return entitys;
|
|
return entitys;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -396,15 +429,32 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
string TableName = await InitializeTable<T>();
|
|
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);
|
|
|
|
- });
|
|
|
|
|
|
+ IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
|
|
|
|
+ foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
|
|
|
|
+ {
|
|
|
|
+ { 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 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()
|
|
@@ -414,17 +464,33 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
string TableName = await InitializeTable<T>();
|
|
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.Delete(entitys[i]);
|
|
|
|
-
|
|
|
|
- result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
- });
|
|
|
|
- return (List<T>)result;
|
|
|
|
|
|
+ IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
|
|
|
|
+ foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
|
|
|
|
+ {
|
|
|
|
+ { 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.Delete(values[i]);
|
|
|
|
+ result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return entitys;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<T> Save<T>(TableEntity entity) where T : TableEntity, new()
|
|
public async Task<T> Save<T>(TableEntity entity) where T : TableEntity, new()
|
|
@@ -452,7 +518,6 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
|
|
|
|
|
|
public async Task<T> Delete<T>(TableEntity entity) where T : TableEntity, new()
|
|
public async Task<T> Delete<T>(TableEntity entity) where T : TableEntity, new()
|
|
{
|
|
{
|
|
-
|
|
|
|
string TableName = await InitializeTable<T>();
|
|
string TableName = await InitializeTable<T>();
|
|
TableOperation operation = TableOperation.Delete(entity);
|
|
TableOperation operation = TableOperation.Delete(entity);
|
|
TableResult result = await tableClient.GetTableReference(TableName).ExecuteAsync(operation);
|
|
TableResult result = await tableClient.GetTableReference(TableName).ExecuteAsync(operation);
|