|
@@ -1,165 +0,0 @@
|
|
|
-using Azure.Storage.Blobs;
|
|
|
-using Azure.Storage.Blobs.Models;
|
|
|
-using HTEXLib.COMM.Helpers;
|
|
|
-using Microsoft.AspNetCore.Http;
|
|
|
-using Microsoft.Azure.Cosmos.Table;
|
|
|
-using System;
|
|
|
-using System.IO;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using TEAMModelOS.Models;
|
|
|
-using TEAMModelOS.SDK.DI;
|
|
|
-using TEAMModelOS.SDK.Extension;
|
|
|
-using TEAMModelOS.SDK.Models.Table;
|
|
|
-
|
|
|
-namespace TEAMModelBI.DI.BIAzureStorage
|
|
|
-{
|
|
|
- public static class BIAzureStorageBlobExtensions
|
|
|
- {
|
|
|
- /// <summary>
|
|
|
- /// 系统管理员 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
|
|
|
- /// "system": [ "res", "item", "htex", "task", "info", "room", "exam" ],
|
|
|
- /// 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
|
|
|
- /// "school": [ "res", "item", "htex", "task", "info", "room", "exam" ],
|
|
|
- /// 资源,题目关联,htex关联,学习活动关联,教师基本信息关联
|
|
|
- /// "teacher": [ "res", "item", "htex", "task", "info" ],
|
|
|
- /// 答案及学习活动上传的文件,学生基本信息关联
|
|
|
- ///"student": [ "stu/{studentId}/ans", "stu/{studentId}/task" ]
|
|
|
- /// </summary>
|
|
|
- /// <param name="name">容器名称</param>
|
|
|
- /// <param name="json">文件内容的流</param>
|
|
|
- /// <param name="folder">业务文件夹</param>
|
|
|
- /// <param name="fileName">文件名</param>
|
|
|
- /// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
|
|
|
- /// <returns></returns>
|
|
|
- public static async Task<string> UploadFileByContainer(BlobContainerClient blobContainer, string json, string root, string blobpath, bool contentTypeDefault = true)
|
|
|
- {
|
|
|
- // string groupName =folder;
|
|
|
- //BlobContainerClient blobContainer1 = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);
|
|
|
-
|
|
|
- var blockBlob = blobContainer.GetBlobClient($"{root}/{blobpath}");
|
|
|
- string content_type = "application/octet-stream";
|
|
|
- if (!contentTypeDefault)
|
|
|
- {
|
|
|
- string fileext = blobpath.Substring(blobpath.LastIndexOf(".") > 0 ? blobpath.LastIndexOf(".") : 0);
|
|
|
- ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
|
|
|
- if (!string.IsNullOrEmpty(contenttype))
|
|
|
- {
|
|
|
- content_type = contenttype;
|
|
|
- }
|
|
|
- }
|
|
|
- byte[] bytes = System.Text.Encoding.Default.GetBytes(json);
|
|
|
- Stream streamBlob = new MemoryStream(bytes);
|
|
|
- await blockBlob.UploadAsync(streamBlob, true);
|
|
|
- blockBlob.SetHttpHeaders(new BlobHttpHeaders { ContentType = content_type });
|
|
|
-
|
|
|
- return blockBlob.Uri.ToString();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 系统管理员 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
|
|
|
- /// "system": [ "res", "item", "htex", "task", "info", "room", "exam" ],
|
|
|
- /// 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
|
|
|
- /// "school": [ "res", "item", "htex", "task", "info", "room", "exam" ],
|
|
|
- /// 资源,题目关联,htex关联,学习活动关联,教师基本信息关联
|
|
|
- /// "teacher": [ "res", "item", "htex", "task", "info" ],
|
|
|
- /// 答案及学习活动上传的文件,学生基本信息关联
|
|
|
- ///"student": [ "stu/{studentId}/ans", "stu/{studentId}/task" ]
|
|
|
- /// </summary>
|
|
|
- /// <param name="blobContainer">Blob连接信息</param>
|
|
|
- /// <param name="stream">文件内容的流</param>
|
|
|
- /// <param name="root">跟目录</param>
|
|
|
- /// <param name="blobpath">路径</param>
|
|
|
- /// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
|
|
|
- /// <returns></returns>
|
|
|
- public static async Task<string> UploadFileByContainer(BlobContainerClient blobContainer, Stream stream, string root, string blobpath, bool contentTypeDefault = true)
|
|
|
- {
|
|
|
- //BlobContainerClient blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);
|
|
|
- //if (clientName != null)
|
|
|
- //{
|
|
|
- // blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", ""),name:clientName); //blobClient.GetContainerReference(groupName);
|
|
|
- //}
|
|
|
- Uri url = blobContainer.Uri;
|
|
|
- var blockBlob = blobContainer.GetBlobClient($"{root}/{blobpath}");
|
|
|
- string content_type = "application/octet-stream";
|
|
|
- if (!contentTypeDefault)
|
|
|
- {
|
|
|
- string fileext = blobpath.Substring(blobpath.LastIndexOf(".") > 0 ? blobpath.LastIndexOf(".") : 0);
|
|
|
- ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
|
|
|
- if (!string.IsNullOrEmpty(contenttype))
|
|
|
- {
|
|
|
- content_type = contenttype;
|
|
|
- }
|
|
|
- }
|
|
|
- await blockBlob.UploadAsync(stream, true);
|
|
|
- blockBlob.SetHttpHeaders(new BlobHttpHeaders { ContentType = content_type });
|
|
|
- return blockBlob.Uri.ToString();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- ///
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureStorage"></param>
|
|
|
- /// <param name="type"></param>
|
|
|
- /// <param name="msg"></param>
|
|
|
- /// <param name="dingDing"></param>
|
|
|
- /// <param name="scope"></param>
|
|
|
- /// <param name="option"></param>
|
|
|
- /// <param name="httpContext"></param>
|
|
|
- /// <returns></returns>
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// BI保存操作记录
|
|
|
- /// </summary>
|
|
|
- /// <param name="blobContainer">Blob连接信息</param>
|
|
|
- /// <param name="tableClient">table连接信息</param>
|
|
|
- /// <param name="type">日志类型</param>
|
|
|
- /// <param name="msg">日志内容</param>
|
|
|
- /// <param name="dingDing"></param>
|
|
|
- /// <param name="tid">账户ID</param>
|
|
|
- /// <param name="tname">账户名称</param>
|
|
|
- /// <param name="twebsite">站点</param>
|
|
|
- /// <param name="scope">范围</param>
|
|
|
- /// <param name="option"></param>
|
|
|
- /// <param name="httpContext"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public static async Task SaveBILog(BlobContainerClient blobContainer, CloudTableClient tableClient, string type, string msg, DingDing dingDing, string tid = null, string tname = null, string twebsite = null, string scope = null, Option option = null, HttpContext httpContext = null)
|
|
|
- {
|
|
|
- var table = tableClient.GetTableReference("BIOptLog");
|
|
|
- BIOptLog biLog = new() { RowKey = Guid.NewGuid().ToString() };
|
|
|
- try
|
|
|
- {
|
|
|
- object id = null, name = null, ddid = null, ddname = null, website = null;
|
|
|
- httpContext?.Items.TryGetValue("ID", out id);
|
|
|
- httpContext?.Items.TryGetValue("Name", out name);
|
|
|
- httpContext?.Items.TryGetValue("DDId", out ddid);
|
|
|
- httpContext?.Items.TryGetValue("DDName", out ddname);
|
|
|
- httpContext?.Items.TryGetValue("Website", out website);
|
|
|
- string site = twebsite != null ? twebsite : $"{website}";
|
|
|
- biLog.tmdId = id != null ? $"{id}" : tid;
|
|
|
- biLog.name = name != null ? $"{name}" : tname;
|
|
|
- biLog.PartitionKey = type != null ? $"{site}-Log-{type}" : $"{site}-Log-Default";
|
|
|
- biLog.platform = site != null ? site : "Default";
|
|
|
- biLog.msg = msg;
|
|
|
- biLog.type = type;
|
|
|
- biLog.scope = scope;
|
|
|
- string host = httpContext?.Request?.Host.Value;
|
|
|
- host = !string.IsNullOrWhiteSpace($"{host}") ? $"{host}" : option?.Location != null ? $"{host}" : "Default";
|
|
|
- biLog.url = $"{host}{httpContext?.Request.Path}";
|
|
|
- if (!string.IsNullOrWhiteSpace(msg) && msg.Length > 255)
|
|
|
- {
|
|
|
- biLog.saveMod = 1;
|
|
|
- biLog.jsonfile = $"/0-public/BIOptLog/{biLog.PartitionKey}-{biLog.RowKey}.json";
|
|
|
- await UploadFileByContainer(blobContainer,biLog.ToJsonString(), "BIOptLog", $"{biLog.PartitionKey}-{biLog.RowKey}.json");
|
|
|
- biLog.msg = null;
|
|
|
- await table.SaveOrUpdate<BIOptLog>(biLog);
|
|
|
- }
|
|
|
- else await table.SaveOrUpdate<BIOptLog>(biLog);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- _ = dingDing.SendBotMsg($"BI日志保存失败:{ex.Message}\n{ex.StackTrace},,{biLog.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|