12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using Azure.Cosmos;
- using Azure.Messaging.ServiceBus;
- using Microsoft.Extensions.Configuration;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Services;
- namespace TEAMModelOS.SDK.Models.Service
- {
- public static class HomeworkService
- {
- public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Homework work, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, AzureRedisFactory _azureRedis)
- {
- try
- {
- work.ttl = -1;
- work.code = "Homework-" + work.school;
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- work.createTime = now;
-
- string blobcntr = null;
- blobcntr = work.school;
- work.size = await _azureStorage.GetBlobContainerClient(work.school).GetBlobsSize($"homework/{work.id}");
- await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"homework", name = $"{blobcntr}" }, _serviceBus, _configuration, _azureRedis);
- work.recordUrl = $"/homework/{work.id}/record.json";
- var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
- await _azureStorage.GetBlobContainerClient(blobcntr).UploadFileByContainer(cods.ToJsonString(), "homework", $"{work.id}/record.json");
- work.id = Guid.NewGuid().ToString();
- if (string.IsNullOrEmpty(work.id))
- {
- if (work.publish == 1)
- {
- work.progress = "pending";
- }
- else {
- if (work.startTime > now)
- {
- work.progress = "pending";
- }
- else
- {
- work.progress = "going";
- }
- }
-
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(work, new PartitionKey($"{work.code}"));
- }
- else
- {
- await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(work, new PartitionKey($"{work.code}"));
- }
- return work.id;
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-HomeworkService-saveMore\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return "";
- }
- }
- }
- }
|