|
@@ -2,10 +2,12 @@ using Azure.Cosmos;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Newtonsoft.Json;
|
|
|
+using StackExchange.Redis;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
@@ -23,22 +25,44 @@ namespace TEAMModelOS.Controllers.XTest
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
- public TestController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage) {
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+
|
|
|
+ public TestController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, DingDing dingDing) {
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_azureRedis = azureRedis;
|
|
|
_azureStorage = azureStorage;
|
|
|
+ _dingDing = dingDing;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 测试blob多线程写入同一个文件
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpGet("multiple-blob")]
|
|
|
- public async Task<IActionResult> MultipleBlob() {
|
|
|
- await _azureStorage.GetBlobContainerClient("hbcn").List("other");
|
|
|
- var dn=await _azureStorage.GetBlobContainerClient("hbcn").GetBlobClient("survey/2e44ee33-ba65-34b6-7e0f-b7e627c70a54/record.json").DownloadAsync();
|
|
|
- var jsonc = await JsonDocument.ParseAsync( dn.Value.Content);
|
|
|
- var Recordc = jsonc.RootElement.ToObject<JsonElement>();
|
|
|
+ [HttpPost("blobroot")]
|
|
|
+ public async Task<IActionResult> MultipleBlob(JsonElement jsonMsg) {
|
|
|
+ if (jsonMsg.TryGetProperty("name", out JsonElement name) && name.ValueKind == JsonValueKind.String
|
|
|
+ && jsonMsg.TryGetProperty("root", out JsonElement root) && root.ValueKind == JsonValueKind.String)
|
|
|
+ {
|
|
|
+ List<Dictionary<string, double?>> list = new List<Dictionary<string, double?>>();
|
|
|
+ string u = System.Web.HttpUtility.UrlDecode($"{root}", Encoding.UTF8).Split("/")[0];
|
|
|
+ var client = _azureStorage.GetBlobContainerClient($"{name}");
|
|
|
+ var size = await client.GetBlobsSize(u);
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, size.HasValue ? size.Value : 0);
|
|
|
+ var scores = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{name}");
|
|
|
+ double blobsize = 0;
|
|
|
+ if (scores != default && scores != null)
|
|
|
+ {
|
|
|
+ foreach (var score in scores)
|
|
|
+ {
|
|
|
+ blobsize = blobsize + score.Score;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue($"{name}"), new RedisValue($"{blobsize}"));
|
|
|
+
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob() 容器:{name}使用:{root},文件分类:{list.ToJsonString()}",
|
|
|
+ GroupNames.成都开发測試群組);
|
|
|
+ }
|
|
|
return Ok();
|
|
|
}
|
|
|
|