Ver código fonte

更新批量条数

CrazyIter 5 anos atrás
pai
commit
68cc186afd

+ 37 - 35
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -30,7 +30,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         private string DatabaseId { get; set; }
         private int CollectionThroughput { get; set; }
         private Database database { get; set; }
-        int pageSize =200;
+        int pageSize = 200;
         private string[] ScanModel { get; set; }
 
         public AzureCosmosDBV3Repository(AzureCosmosDBOptions options, CosmosSerializer cosmosSerializer)
@@ -39,6 +39,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             {
                 if (!string.IsNullOrEmpty(options.ConnectionString))
                 {
+
                     CosmosClient = CosmosDBV3ClientSingleton.getInstance(options.ConnectionString, options.ConnectionKey, cosmosSerializer).GetCosmosDBClient();
 
                 }
@@ -53,7 +54,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
             catch (CosmosException e)
             {
-               // Dispose(true);
+                // Dispose(true);
                 throw new BizException(e.Message, 500, e.StackTrace);
             }
         }
@@ -77,7 +78,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
             catch (CosmosException e)
             {
-             //   Dispose(true);
+                //   Dispose(true);
                 throw new BizException(e.Message, 500, e.StackTrace);
             }
         }
@@ -243,7 +244,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             //    Task.WaitAll(DeleteAsync<T>(item.Value, item.Key));
             //}));
 
-            
+
             int pages = (int)Math.Ceiling((double)ids.Count / pageSize);
             Stopwatch stopwatch = Stopwatch.StartNew();
             for (int i = 0; i < pages; i++)
@@ -255,13 +256,13 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     tasks.Add(container.DeleteItemStreamAsync(item.Value, new PartitionKey(item.Key))
                         .ContinueWith((Task<ResponseMessage> task) =>
                         {
-                        //using (ResponseMessage response = task.Result)
-                        //{
-                        //    if (!response.IsSuccessStatusCode)
-                        //    {
-                        //    }
-                        //}
-                    }
+                            //using (ResponseMessage response = task.Result)
+                            //{
+                            //    if (!response.IsSuccessStatusCode)
+                            //    {
+                            //    }
+                            //}
+                        }
                         ));
                 });
                 await Task.WhenAll(tasks);
@@ -293,13 +294,13 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     tasks.Add(container.DeleteItemStreamAsync(item.Value, item.Key)
                         .ContinueWith((Task<ResponseMessage> task) =>
                         {
-                        //using (ResponseMessage response = task.Result)
-                        //{
-                        //    if (!response.IsSuccessStatusCode)
-                        //    {
-                        //    }
-                        //}
-                    }
+                            //using (ResponseMessage response = task.Result)
+                            //{
+                            //    if (!response.IsSuccessStatusCode)
+                            //    {
+                            //    }
+                            //}
+                        }
                         ));
                 });
                 await Task.WhenAll(tasks);
@@ -386,7 +387,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
                 //};
                 StringBuilder sql = new StringBuilder("select value(c) from c");
-                CosmosDbQuery cosmosDbQuery = SQLHelperParametric.GetSQL(dict,sql);
+                CosmosDbQuery cosmosDbQuery = SQLHelperParametric.GetSQL(dict, sql);
                 QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(itemsPerPage, maxItemCount));
                 FeedIterator<dynamic> query = container.GetItemQueryIterator<dynamic>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
                 return await ResultsFromFeedIterator(query, maxItemCount);
@@ -564,7 +565,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
         }
 
-       
+
 
         public async Task<T> Save<T>(T entity) where T : ID
         {
@@ -584,7 +585,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         {
             int pages = (int)Math.Ceiling((double)enyites.Count / pageSize);
             Container container = await InitializeCollection<T>();
-            string pk= GetPartitionKey<T>();
+            string pk = GetPartitionKey<T>();
             Type type = typeof(T);
             Stopwatch stopwatch = Stopwatch.StartNew();
             for (int i = 0; i < pages; i++)
@@ -678,15 +679,16 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         public async Task<T> Update<T>(T entity) where T : ID
         {
             Container container = await InitializeCollection<T>();
-            string pk =  GetPartitionKey<T>();
+            string pk = GetPartitionKey<T>();
             object o = typeof(T).GetProperty(pk).GetValue(entity, null);
-            ItemResponse<T> response = await container.ReplaceItemAsync(entity,entity.id,new PartitionKey(o.ToString()));
+            ItemResponse<T> response = await container.ReplaceItemAsync(entity, entity.id, new PartitionKey(o.ToString()));
             return response.Resource;
         }
 
 
-        internal class Item { 
-            public  string id { get; set; }
+        internal class Item
+        {
+            public string id { get; set; }
             public string pk { get; set; }
             public MemoryStream stream { get; set; }
         }
@@ -697,7 +699,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             //{
             //    Task.WaitAll(Update(item));
             //}));
-            
+
             int pages = (int)Math.Ceiling((double)enyites.Count / pageSize);
             Container container = await InitializeCollection<T>();
             string pk = GetPartitionKey<T>();
@@ -712,21 +714,21 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     MemoryStream stream = new MemoryStream();
                     await JsonSerializer.SerializeAsync(stream, x);
                     object o = type.GetProperty(pk).GetValue(x, null);
-                    Item keyValue = new Item { id=x.id,pk=o.ToString(),stream=stream};
+                    Item keyValue = new Item { id = x.id, pk = o.ToString(), stream = stream };
                     itemsToInsert.Add(keyValue);
                 });
                 List<Task> tasks = new List<Task>(lists.Count);
                 itemsToInsert.ForEach(item =>
                 {
-                    tasks.Add(container.ReplaceItemStreamAsync(item.stream, item.id,new PartitionKey(item.pk))
+                    tasks.Add(container.ReplaceItemStreamAsync(item.stream, item.id, new PartitionKey(item.pk))
                         .ContinueWith((Task<ResponseMessage> task) =>
                         {
-                        //using (ResponseMessage response = task.Result)
-                        //{
-                        //    if (!response.IsSuccessStatusCode)
-                        //    {
-                        //    }
-                        //}
+                            //using (ResponseMessage response = task.Result)
+                            //{
+                            //    if (!response.IsSuccessStatusCode)
+                            //    {
+                            //    }
+                            //}
                         }
                         ));
                 });
@@ -774,6 +776,6 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             return response.Resource;
         }
 
-       
+
     }
 }