1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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.Models.SchoolInfo;
- 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}");
- Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
- var client = _azureCosmos.GetCosmosClient();
- keyValuePairs.TryGetValue("id", out object id);
- keyValuePairs.TryGetValue("name", out object name);
- keyValuePairs.TryGetValue("code", out object code);
- keyValuePairs.TryGetValue("status", out object progress);
- if (name.ToString().Equals("ExamInfo")) {
- ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
- exam.progress = progress.ToString();
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
- /*List<object> classes = new List<object>();
- 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<object>());
- }
- }
- }*/
- }
-
- }
- }
- }
|