using System; using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; using Azure.Cosmos; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Microsoft.Extensions.Logging; using TEAMModelOS.SDK.DI; using TEAMModelOS.SDK.Extension; namespace TEAMModelFunction { public class ServiceBusTopic { private readonly AzureCosmosFactory _azureCosmos; public ServiceBusTopic( AzureCosmosFactory azureCosmos) { _azureCosmos = azureCosmos; } [FunctionName("ServiceBusTopic")] public async Task Run([ServiceBusTrigger("test_topic_ActiveTask", "test_topic_ReciveTask", Connection = "ConnectionBusName")]string mySbMsg, ILogger log) { log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}"); var client = _azureCosmos.GetCosmosClient(); List classes = new List(); await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c",requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-hbcn") })) { using var json = await JsonDocument.ParseAsync(item.ContentStream); if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0) { foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray()) { classes.Add(obj.ToObject()); } } } } } }