Browse Source

更新源代码,监听,数据处理

CrazyIter 5 years ago
parent
commit
289b450a93

+ 66 - 54
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -21,8 +21,9 @@ using TEAMModelOS.SDK.Module.AzureCosmosDB.Configuration;
 
 namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 {
-    public class CosmosModelInfo {
-        public Container container{ get; set; }
+    public class CosmosModelInfo
+    {
+        public Container container { get; set; }
         public bool cache { get; set; }
         public bool monitor { get; set; } = false;
         public Type type { get; set; }
@@ -45,7 +46,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         private string[] ScanModel { get; set; }
         private const int timeoutSeconds = 86400;
 
-        private string leaseId = "leaseContainer";
+        private string leaseId = "AleaseContainer";
         public AzureCosmosDBV3Repository(AzureCosmosDBOptions options, CosmosSerializer cosmosSerializer)
         {
             try
@@ -105,7 +106,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 {
                     foreach (ContainerProperties container in await resultSetIterator.ReadNextAsync())
                     {
-                            DocumentCollectionDict.TryAdd(container.Id, new CosmosModelInfo { container = database.GetContainer(container.Id), cache = false,monitor=false });
+                        DocumentCollectionDict.TryAdd(container.Id, new CosmosModelInfo { container = database.GetContainer(container.Id), cache = false, monitor = false });
                     }
                 }
                 bool isMonitor = false;
@@ -127,14 +128,15 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     {
                         CollectionName = type.Name;
                     }
-                    if ( attributes.First<CosmosDBAttribute>().Cache)
+                    if (attributes.First<CosmosDBAttribute>().Cache)
                     {
                         cache = attributes.First<CosmosDBAttribute>().Cache;
                     }
                     if (attributes.First<CosmosDBAttribute>().Monitor)
                     {
                         monitor = attributes.First<CosmosDBAttribute>().Monitor;
-                        if (monitor) {
+                        if (monitor)
+                        {
                             isMonitor = true;
                         }
                     }
@@ -155,13 +157,13 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     { //更新RU
 
                         cosmosModelInfo.cache = cache;
-                        Container container =   CosmosClient.GetDatabase(DatabaseId).GetContainer(cosmosModelInfo.container.Id);
+                        Container container = CosmosClient.GetDatabase(DatabaseId).GetContainer(cosmosModelInfo.container.Id);
                         int? throughputResponse = await container.ReadThroughputAsync();
                         if (throughputResponse < RU)
                         {
                             await CosmosClient.GetDatabase(DatabaseId).GetContainer(cosmosModelInfo.container.Id).ReplaceThroughputAsync(RU);
                         }
-                        DocumentCollectionDict[CollectionName] = new CosmosModelInfo { container = container, cache = cache,monitor= monitor ,type= type } ;
+                        DocumentCollectionDict[CollectionName] = new CosmosModelInfo { container = container, cache = cache, monitor = monitor, type = type };
                     }
                     else
                     {
@@ -176,10 +178,11 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                             CollectionThroughput = RU;
                         }
                         Container containerWithConsistentIndexing = await database.CreateContainerIfNotExistsAsync(containerProperties, throughput: CollectionThroughput);
-                        DocumentCollectionDict.TryAdd(CollectionName, new CosmosModelInfo { container= containerWithConsistentIndexing ,cache=cache  , monitor = monitor ,type=type });
+                        DocumentCollectionDict.TryAdd(CollectionName, new CosmosModelInfo { container = containerWithConsistentIndexing, cache = cache, monitor = monitor, type = type });
                     }
                 }
-                if (isMonitor) {
+                if (isMonitor)
+                {
                     ContainerProperties leaseProperties = new ContainerProperties { Id = leaseId, PartitionKeyPath = "/id" };
                     Container leaseContainer = await database.CreateContainerIfNotExistsAsync(leaseProperties, throughput: CollectionThroughput);
                     DocumentCollectionDict.TryAdd(leaseId, new CosmosModelInfo { container = leaseContainer, cache = false, monitor = false });
@@ -191,10 +194,11 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             }
         }
 
-        public Dictionary<string, CosmosModelInfo> GetCosmosModelInfo() {
+        public Dictionary<string, CosmosModelInfo> GetCosmosModelInfo()
+        {
             return this.DocumentCollectionDict;
         }
- 
+
 
 
         private string GetPartitionKey<T>()
@@ -297,8 +301,8 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     tasks.Add(container.container.DeleteItemStreamAsync(item.id, new PartitionKey(item.pk))
                         .ContinueWith((Task<ResponseMessage> task) =>
                         {
-                             using (ResponseMessage response = task.Result)
-                           {
+                            using (ResponseMessage response = task.Result)
+                            {
                                 idPks.Add(new IdPk { id = item.id, pk = item.pk.ToString(), StatusCode = response.StatusCode });
                                 //    if (!response.IsSuccessStatusCode)
                                 //    {
@@ -307,21 +311,21 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                         }
                         ));
                 });
-                await Task.WhenAll(tasks); 
+                await Task.WhenAll(tasks);
                 if (container.cache && RedisHelper.Instance != null)
                 {
                     lists.ForEach(async x => {
-                        await RedisHelper.HDelAsync(CacheCosmosPrefix + container.container.Id,x.id );
+                        await RedisHelper.HDelAsync(CacheCosmosPrefix + container.container.Id, x.id);
                     });
                 }
             }
             stopwatch.Stop();
             return idPks;
         }
-        public async Task<List<IdPk>> DeleteAll<T>(Dictionary<string,object> dict) where T : ID
+        public async Task<List<IdPk>> DeleteAll<T>(Dictionary<string, object> dict) where T : ID
         {
-            List<T> list=   await FindByDict<T>(dict);
-            return await DeleteAll(list); 
+            List<T> list = await FindByDict<T>(dict);
+            return await DeleteAll(list);
         }
         public async Task<List<IdPk>> DeleteAll<T>(List<T> enyites) where T : ID
         {
@@ -348,14 +352,14 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 {
                     tasks.Add(container.container.DeleteItemStreamAsync(item.Value, item.Key)
                     .ContinueWith((Task<ResponseMessage> task) =>
+                    {
+                        using (ResponseMessage response = task.Result)
                         {
-                            using (ResponseMessage response = task.Result)
-                            {
-                                
-                                idPks.Add(new IdPk { id = item.Value, pk = item.Key.ToString(), StatusCode = response.StatusCode });
-                                 
-                            }
+
+                            idPks.Add(new IdPk { id = item.Value, pk = item.Key.ToString(), StatusCode = response.StatusCode });
+
                         }
+                    }
                     ));
                 });
                 await Task.WhenAll(tasks); if (container.cache && RedisHelper.Instance != null)
@@ -369,18 +373,19 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             return idPks;
         }
 
-        public async Task<IdPk> DeleteAsync<T>(IdPk idPk) where T : ID {
+        public async Task<IdPk> DeleteAsync<T>(IdPk idPk) where T : ID
+        {
             return await DeleteAsync<T>(idPk.id, idPk.pk);
         }
         public async Task<IdPk> DeleteAsync<T>(string id, string pk) where T : ID
         {
             CosmosModelInfo container = await InitializeCollection<T>();
-            ResponseMessage  response = await container.container.DeleteItemStreamAsync(id: id, partitionKey: new PartitionKey(pk));
+            ResponseMessage response = await container.container.DeleteItemStreamAsync(id: id, partitionKey: new PartitionKey(pk));
             if (container.cache && RedisHelper.Instance != null)
             {
                 await RedisHelper.HDelAsync(CacheCosmosPrefix + container.container.Id, id);
             }
-            return new IdPk { id =id, pk = pk, StatusCode = response.StatusCode };
+            return new IdPk { id = id, pk = pk, StatusCode = response.StatusCode };
         }
 
         public async Task<IdPk> DeleteAsync<T>(T entity) where T : ID
@@ -389,7 +394,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             string partitionKey = GetPartitionKey<T>();
             Type type = typeof(T);
             object o = type.GetProperty(partitionKey).GetValue(entity, null);
-            ResponseMessage  response = await container.container.DeleteItemStreamAsync (id: entity.id, partitionKey: new PartitionKey(o.ToString()));
+            ResponseMessage response = await container.container.DeleteItemStreamAsync(id: entity.id, partitionKey: new PartitionKey(o.ToString()));
             if (container.cache && RedisHelper.Instance != null)
             {
                 await RedisHelper.HDelAsync(CacheCosmosPrefix + container.container.Id, entity.id);
@@ -409,7 +414,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             CosmosModelInfo container = await InitializeCollection<T>();
             StringBuilder sql;
             sql = SQLHelperParametric.GetSQLSelect(propertys);
-            CosmosDbQuery cosmosDbQuery = new CosmosDbQuery {QueryText = sql.ToString() };
+            CosmosDbQuery cosmosDbQuery = new CosmosDbQuery { QueryText = sql.ToString() };
             FeedIterator<T> query = container.container.GetItemQueryIterator<T>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition);
             return await ResultsFromFeedIterator(query);
 
@@ -466,7 +471,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 StringBuilder sql;
                 sql = SQLHelperParametric.GetSQLSelect(propertys);
                 CosmosDbQuery cosmosDbQuery = SQLHelperParametric.GetSQL(dict, sql);
-                QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1,null));
+                QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
                 FeedIterator<dynamic> query = container.container.GetItemQueryIterator<dynamic>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
                 return await ResultsFromFeedIterator(query);
             }
@@ -487,7 +492,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 dict.Remove("@DESC");
                 StringBuilder sql = new StringBuilder("select  value count(c)  from c");
                 CosmosDbQuery cosmosDbQuery = SQLHelperParametric.GetSQL(dict, sql);
-                QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1,null));
+                QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
                 FeedIterator<dynamic> query = container.container.GetItemQueryIterator<dynamic>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
                 return await ResultsFromFeedIterator(query);
             }
@@ -499,9 +504,9 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
         public async Task<List<T>> FindByParams<T>(Dictionary<string, object> dict, string partitionKey = null, List<string> propertys = null) where T : ID
         {
-            return await FindByDict<T>(dict,partitionKey, propertys);
+            return await FindByDict<T>(dict, partitionKey, propertys);
         }
-        public async Task<List<T>> FindByDict<T>(Dictionary<string, object> dict, string partitionKey = null,List<string> propertys = null) where T : ID
+        public async Task<List<T>> FindByDict<T>(Dictionary<string, object> dict, string partitionKey = null, List<string> propertys = null) where T : ID
         {
             StringBuilder sql;
             sql = SQLHelperParametric.GetSQLSelect(propertys);
@@ -510,7 +515,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
             return await ResultsFromQueryAndOptions<T>(cosmosDbQuery, queryRequestOptions);
         }
-        
+
 
         private async Task<List<T>> ResultsFromQueryAndOptions<T>(CosmosDbQuery cosmosDbQuery, QueryRequestOptions queryOptions)
         {
@@ -562,7 +567,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
         public async Task<List<T>> FindLinq<T>(Expression<Func<T, bool>> query = null, Expression<Func<T, object>> order = null, bool isDesc = false) where T : ID
         {
             //QueryRequestOptions queryRequestOptions = GetQueryRequestOptions(itemsPerPage);
-            QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1,null));
+            QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
             FeedIterator<T> feedIterator;
             CosmosModelInfo container = await InitializeCollection<T>();
 
@@ -650,16 +655,18 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             {
                 CosmosModelInfo container = await InitializeCollection<T>();
                 ItemResponse<T> response = await container.container.CreateItemAsync<T>(entity);
-                if (container.cache && RedisHelper.Instance!=null) {
+                if (container.cache && RedisHelper.Instance != null)
+                {
                     if (!RedisHelper.Exists(CacheCosmosPrefix + container.container.Id))
                     {
                         await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
                     }
-                    else {
+                    else
+                    {
                         await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, entity.id, entity);
                         await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
                     }
-                    
+
                 }
                 return response.Resource;
             }
@@ -688,7 +695,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 lists.ForEach(async x =>
                 {
                     MemoryStream stream = new MemoryStream();
-                    await JsonSerializer.SerializeAsync(stream, x ,new JsonSerializerOptions { IgnoreNullValues=true});
+                    await JsonSerializer.SerializeAsync(stream, x, new JsonSerializerOptions { IgnoreNullValues = true });
                     object o = type.GetProperty(pk).GetValue(x, null);
                     KeyValuePair<PartitionKey, Stream> keyValue = new KeyValuePair<PartitionKey, Stream>(new PartitionKey(o.ToString()), stream);
                     itemsToInsert.Add(keyValue);
@@ -712,11 +719,12 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 if (container.cache && RedisHelper.Instance != null)
                 {
                     lists.ForEach(async x => {
-                        await RedisHelper.HSetAsync(CacheCosmosPrefix+container.container.Id, x.id, x);
+                        await RedisHelper.HSetAsync(CacheCosmosPrefix + container.container.Id, x.id, x);
                     });
                 }
             }
-            if (container.cache && RedisHelper.Instance != null&&!flag) {
+            if (container.cache && RedisHelper.Instance != null && !flag)
+            {
                 await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
             }
             stopwatch.Stop();
@@ -792,7 +800,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     });
                 }
             }
-            if (container.cache && RedisHelper.Instance != null&&!flag)
+            if (container.cache && RedisHelper.Instance != null && !flag)
             {
                 await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
             }
@@ -881,7 +889,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     });
                 }
             }
-            if (container.cache && RedisHelper.Instance != null&&!flag)
+            if (container.cache && RedisHelper.Instance != null && !flag)
             {
                 await RedisHelper.ExpireAsync(CacheCosmosPrefix + container.container.Id, timeoutSeconds);
             }
@@ -933,33 +941,37 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             if (container.cache && RedisHelper.Instance != null)
             {
 
-                return await RedisHelper.CacheShellAsync(CacheCosmosPrefix + container.container.Id , id , timeoutSeconds, () => { return FindByIdAsSql<T>(id); }) ;
-                
+                return await RedisHelper.CacheShellAsync(CacheCosmosPrefix + container.container.Id, id, timeoutSeconds, () => { return FindByIdAsSql<T>(id); });
+
             }
-            else {
+            else
+            {
                 return await FindByIdAsSql<T>(id);
             }
-            
+
         }
 
-        public async  Task<List<T>> FindByIds<T>(List<string> ids) where T : ID
+        public async Task<List<T>> FindByIds<T>(List<string> ids) where T : ID
         {
             CosmosModelInfo container = await InitializeCollection<T>();
-          
+
             if (container.cache && RedisHelper.Instance != null)
             {
                 List<T> list = new List<T>();
                 List<string> NotIn = new List<string>();
-                foreach (string id in ids) {
+                foreach (string id in ids)
+                {
                     if (!await RedisHelper.HExistsAsync(CacheCosmosPrefix + container.container.Id, id))
                     {
                         NotIn.Add(id);
                     }
-                    else {
+                    else
+                    {
                         list.Add(await RedisHelper.HGetAsync<T>(CacheCosmosPrefix + container.container.Id, id));
                     }
                 }
-                if (NotIn.IsNotEmpty()) {
+                if (NotIn.IsNotEmpty())
+                {
                     List<T> noInList = await FindByDict<T>(new Dictionary<string, object> { { "id", NotIn.ToArray() } });
                     noInList.ForEach(x => { RedisHelper.HSet(CacheCosmosPrefix + container.container.Id, x.id, x); RedisHelper.Expire(CacheCosmosPrefix + container.container.Id, timeoutSeconds); });
                     list.AddRange(noInList);
@@ -979,7 +991,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                 if (container.cache && RedisHelper.Instance != null)
                 {
 
-                    return await RedisHelper.CacheShellAsync(CacheCosmosPrefix + container.container.Id,id, timeoutSeconds, () => { return FindByDict(CollectionName, new Dictionary<string, object> { { "id", id } }); });
+                    return await RedisHelper.CacheShellAsync(CacheCosmosPrefix + container.container.Id, id, timeoutSeconds, () => { return FindByDict(CollectionName, new Dictionary<string, object> { { "id", id } }); });
 
                 }
                 else

+ 3 - 3
TEAMModelOS.Service/Services/ChangeFeed/ChangeFeedInvoke.cs

@@ -24,7 +24,7 @@ namespace TEAMModelOS.Service.Services.ChangeFeed
            Dictionary<string,CosmosModelInfo> dict =  azureCosmosDBV3Repository.GetCosmosModelInfo();
             foreach (string CollectionName in dict.Keys)
             {
-                if (CollectionName.Equals("leaseContainer")) 
+                if (CollectionName.Equals("AleaseContainer")) 
                 { 
                     continue; 
                 }
@@ -33,9 +33,9 @@ namespace TEAMModelOS.Service.Services.ChangeFeed
                         .container
                         .GetChangeFeedProcessorBuilder<object>(CollectionName, async (changes, token) => await ProcessChanges(changes, CollectionName, dict[CollectionName].type))
                         .WithInstanceName(CollectionName)
-                        .WithLeaseContainer(dict["leaseContainer"].container)
+                        .WithLeaseContainer(dict["AleaseContainer"].container)
                         .Build();
-                    await changeFeedProcessor.StartAsync();
+                     await changeFeedProcessor.StartAsync();
                 }
                
             }

+ 1 - 1
TEAMModelOS.Service/Services/ChangeFeed/IChangeFeedInvoke.cs

@@ -6,7 +6,7 @@ using TEAMModelOS.SDK.Context.Configuration;
 
 namespace TEAMModelOS.Service.Services.ChangeFeed
 {
-   public interface IChangeFeedInvoke //:IBusinessService
+   public interface IChangeFeedInvoke :IBusinessService
     {
           Task MonitorChangeFeed();
     }

+ 10 - 12
TEAMModelOS/Startup.cs

@@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Http.Features;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.SpaServices;
-using Microsoft.Azure.Cosmos;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
@@ -25,7 +24,6 @@ using TEAMModelOS.SDK.Module.AzureCosmosDB.Configuration;
 using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
 using TEAMModelOS.SDK.Module.AzureTable.Implements;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
-using TEAMModelOS.Service.Models.Syllabus;
 using TEAMModelOS.Service.Services.ChangeFeed;
 using VueCliMiddleware;
 
@@ -33,7 +31,7 @@ namespace TEAMModelOS
 {
     public class Startup
     {
-       
+
         public Startup(IConfiguration configuration, IWebHostEnvironment env)
         {
             Configuration = configuration;
@@ -46,7 +44,7 @@ namespace TEAMModelOS
         public void ConfigureServices(IServiceCollection services)
         {
 
-           
+
             // true,默認情況下,聲明映射將以舊格式映射聲明名稱,以適應較早的SAML應用程序,RoleClaimType = 'http://schemas.microsoft.com/ws/2008/06/identity/claims/role'
             // false,RoleClaimType = 'roles' 
             /*
@@ -103,7 +101,8 @@ namespace TEAMModelOS
             //.AddNewtonsoftJson().AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; });
             //上传文件最大处理
             services.Configure<FormOptions>(x =>
-            {   x.BufferBodyLengthLimit= long.MaxValue;
+            {
+                x.BufferBodyLengthLimit = long.MaxValue;
                 x.ValueLengthLimit = int.MaxValue;
                 x.MultipartBodyLengthLimit = long.MaxValue; // In case of multipart
                 x.MultipartHeadersLengthLimit = int.MaxValue;
@@ -115,7 +114,7 @@ namespace TEAMModelOS
             services.AddAzureBlobStorage().AddConnection(Configuration.GetSection("Azure:Blob").Get<AzureBlobOptions>());
             //使用CosmosDB
             services.AddAzureCosmosDBV3().AddCosmosDBV3Connection(Configuration.GetSection("Azure:CosmosDB").Get<AzureCosmosDBOptions>())
-                .AddCosmosSerializer(new SystemTextJsonCosmosSerializer(new JsonSerializerOptions() { IgnoreNullValues=true}));
+                .AddCosmosSerializer(new SystemTextJsonCosmosSerializer(new JsonSerializerOptions() { IgnoreNullValues = true }));
             //HttpContextAccessor,并用来访问HttpContext。
             services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
             //引入Jwt配置
@@ -134,28 +133,27 @@ namespace TEAMModelOS
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
-        public async void Configure(IApplicationBuilder app, IWebHostEnvironment env, IAzureCosmosDBV3Repository cosmosDBV3Repository)
+        public   void Configure(IApplicationBuilder app, IWebHostEnvironment env, IAzureCosmosDBV3Repository cosmosDBV3Repository, IChangeFeedInvoke changeFeedInvoke)
         {
             if (env.IsDevelopment())
             {
                 app.UseDeveloperExceptionPage();
             }
-
-            await cosmosDBV3Repository.InitializeDatabase();
-         //   await changeFeedInvoke.MonitorChangeFeed();
+            cosmosDBV3Repository.InitializeDatabase().GetAwaiter();
+            changeFeedInvoke.MonitorChangeFeed().GetAwaiter();
             app.UseMiddleware<HttpGlobalExceptionInvoke>();
             //以下需要按照順序載入中間件  如果应用调用 UseStaticFiles,请将 UseStaticFiles 置于 UseRouting之前。
             app.UseStaticFiles();
             //app.UseSpaStaticFiles(); //使用中間件不開
             app.UseRouting();
-           
+
             //app.UseCors(MyAllowSpecificOrigins); //使用跨域設定
             //app.UseHttpsRedirection(); //開發中暫時關掉
             //如果应用使用身份验证/授权功能(如 AuthorizePage 或 [Authorize]),请将对 UseAuthentication 和 UseAuthorization的
             //调用放在之后、UseRouting 和 UseCors,但在 UseEndpoints之前
             app.UseAuthentication();
             app.UseAuthorization();
-          //  app.UseJsonRpc();
+            //  app.UseJsonRpc();
             app.UseEndpoints(endpoints =>
             {
                 endpoints.MapControllers();