Parcourir la source

测试另外的连接方式CosmosDB

Li il y a 3 ans
Parent
commit
000ea4a6f1

+ 24 - 0
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -1263,8 +1263,32 @@ namespace TEAMModelBI.Controllers.BITest
             return Ok(new { state = 200, linqTests, set });
         }
 
+        [HttpPost("get-cosmosdb")]
+        public async Task<IActionResult> GetMany()
+        {
+            var cosmos = _configuration.GetValue<string>("Azure:Cosmos:ConnectionString");
+
+
+            var clientUrl = _configuration.GetValue<string>("Azure:CosmosUrl:ConnectionString");
+            var clientKey = _configuration.GetValue<string>("Azure:CosmosKey:ConnectionString");
 
 
+            CosmosClient cosmosClient = new(clientUrl, clientKey);
+            //var cosmosClient = _azureCosmos.GetCosmosClient(region:client,name: cosmos);
+
+            var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync("hbcn", new PartitionKey("Base"));
+            School school = new();
+            if (response.Status == 200)
+            {
+                using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                school = json.ToObject<School>();
+
+            }
+
+
+            return Ok(new { state = 200, school }); 
+        }
+
         public class linqTest
         {
             public string id{ get; set; }

+ 6 - 0
TEAMModelBI/appsettings.Development.json

@@ -26,6 +26,12 @@
     "Cosmos": {
       "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
     },
+    "CosmosUrl": {
+      "ConnectionString": "https://cdhabookdep-free.documents.azure.cn:443/"
+    },
+    "CosmosKey": {
+      "ConnectionString": "JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A=="
+    },
     "Redis": {
       "ConnectionString": "52.130.252.100:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240"
     },