using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.Cosmos; using System.Net; using System.Text.Json; using TEAMModelOS.SDK.DI; using TEAMModelOS.SDK.Extension; namespace AzureCosmosDBEmulator.Controllers { [ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { private readonly AzureCosmosFactory _azureCosmos; private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; private readonly ILogger _logger; public WeatherForecastController(ILogger logger, AzureCosmosFactory azureCosmos) { _logger = logger; _azureCosmos = azureCosmos; } [HttpGet] public async Task Get() { //https://cosmosdb.teammodel.cn/_explorer/index.html //var result= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList("select value c from c where 1=1"); //return Ok(new { result.list }); CosmosClient client = null ; Database database = null; Container container = null ; try { CosmosClientOptions options = new() { HttpClientFactory = () => new HttpClient(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }), ConnectionMode = ConnectionMode.Gateway, }; client = new CosmosClient("AccountEndpoint=https://163.228.141.122:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", options); database = client.GetDatabase(Constant.TEAMModelOS); // await database.CreateContainerIfNotExistsAsync(new ContainerProperties() { Id="School", PartitionKeyPath="/code"}); container=database.GetContainer(Constant.Common); } catch (Exception ex) { Console.WriteLine(ex); } try { var items = container.GetItemQueryStreamIterator( queryText: "select value c from c where 1=1", continuationToken: null, requestOptions: null); while (items.HasMoreResults) { var response = await items.ReadNextAsync(); if (response.Content!=null) { return Ok(new {json= JsonDocument.Parse(response.Content).RootElement }); } } } catch (Exception ex) { Console.WriteLine(ex); } return Ok(); } } }