浏览代码

代碼調整

JAELYS 4 年之前
父节点
当前提交
4b5e454d2c

+ 2 - 2
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -52,12 +52,12 @@ namespace TEAMModelOS.SDK.DI
         /// <param name="fileName">文件名</param>
         /// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
         /// <returns></returns>
-        public static async Task<AzureBlobModel> UploadFileByContainer(this AzureStorageFactory azureStorageFactory, string name, string text, string folder, string fileName, bool contentTypeDefault = true)
+        public static async Task<AzureBlobModel> UploadFileByContainer(this AzureStorageFactory azureStorage, string name, string text, string folder, string fileName, bool contentTypeDefault = true)
         {
 
             // string groupName =folder;
 
-            BlobContainerClient blobContainer =  azureStorageFactory.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName); 
+            BlobContainerClient blobContainer =  azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName); 
             Uri url = blobContainer.Uri;
 
             var blockBlob = blobContainer.GetBlobClient(folder + "/" + fileName);

+ 16 - 16
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageTableExtensions.cs

@@ -226,44 +226,44 @@ namespace TEAMModelOS.SDK.DI
         }
         #endregion
 
-        public static async Task<T> Save<T>(this AzureStorageFactory azureStorageFactory, TableEntity entity) where T : TableEntity, new()
+        public static async Task<T> Save<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
         {
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             TableOperation operation = TableOperation.Insert(entity);
             TableResult result = await TableName.ExecuteAsync(operation);
             return (T)result.Result;
         }
-        public static async Task<T> SaveOrUpdate<T>(this AzureStorageFactory azureStorageFactory, TableEntity entity) where T : TableEntity, new()
+        public static async Task<T> SaveOrUpdate<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
         {
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             TableOperation operation = TableOperation.InsertOrReplace(entity);
             TableResult result = await TableName.ExecuteAsync(operation);
             return (T)result.Result;
         }
 
-        public static async Task<T> Update<T>(this AzureStorageFactory azureStorageFactory, TableEntity entity) where T : TableEntity, new()
+        public static async Task<T> Update<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
         {
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             TableOperation operation = TableOperation.Replace(entity);
             TableResult result = await TableName.ExecuteAsync(operation);
             return (T)result.Result;
         }
 
-        public static async Task<T> Delete<T>(this AzureStorageFactory azureStorageFactory, TableEntity entity) where T : TableEntity, new()
+        public static async Task<T> Delete<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
         {
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             TableOperation operation = TableOperation.Delete(entity);
             TableResult result = await TableName.ExecuteAsync(operation);
             return (T)result.Result;
         }
 
-        public static async Task<List<T>> DeleteAll<T>(this AzureStorageFactory azureStorageFactory,  List<T> entitys) where T : TableEntity, new()
+        public static async Task<List<T>> DeleteAll<T>(this AzureStorageFactory azureStorage,  List<T> entitys) where T : TableEntity, new()
         {
             if (entitys.IsEmpty())
             {
                 return null;
             }
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
             foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
             {
@@ -298,13 +298,13 @@ namespace TEAMModelOS.SDK.DI
             return entitys;
         }
 
-        public static async Task<List<T>> SaveOrUpdateAll<T>(this AzureStorageFactory azureStorageFactory, List<T> entitys) where T : TableEntity, new()
+        public static async Task<List<T>> SaveOrUpdateAll<T>(this AzureStorageFactory azureStorage, List<T> entitys) where T : TableEntity, new()
         {
             if (entitys.IsEmpty())
             {
                 return null;
             }
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
             foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
             {
@@ -378,13 +378,13 @@ namespace TEAMModelOS.SDK.DI
             }
             return entitys;
         }
-        public static async Task<List<T>> SaveAll<T>(this AzureStorageFactory azureStorageFactory, List<T> entitys) where T : TableEntity, new()
+        public static async Task<List<T>> SaveAll<T>(this AzureStorageFactory azureStorage, List<T> entitys) where T : TableEntity, new()
         {
             if (entitys.IsEmpty())
             {
                 return null;
             }
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
             foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
             {
@@ -419,9 +419,9 @@ namespace TEAMModelOS.SDK.DI
             return entitys;
         }
 
-        public static async Task<List<T>> FindListByDict<T>(this AzureStorageFactory azureStorageFactory, Dictionary<string, object> dict) where T : TableEntity, new()
+        public static async Task<List<T>> FindListByDict<T>(this AzureStorageFactory azureStorage, Dictionary<string, object> dict) where T : TableEntity, new()
         {
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            CloudTable TableName = await azureStorage.InitializeTable<T>();
             var exQuery = new TableQuery<T>();
             StringBuilder builder = new StringBuilder();
             if (null != dict && dict.Count > 0)

+ 5 - 5
TEAMModelOS/Controllers/Core/FileController.cs

@@ -21,12 +21,12 @@ namespace TEAMModelOS.Controllers
     [ApiController]
     public class FileController:BaseController
     {
-        private readonly AzureStorageFactory azureTableDBRepository;
+        private readonly AzureStorageFactory _azureStorage;
        // private readonly IAzureBlobDBRepository _azureBlobDBRepository;
-        public FileController(AzureStorageFactory _azureTableDBRepository 
+        public FileController(AzureStorageFactory azureStorage
         )
         {
-            azureTableDBRepository = _azureTableDBRepository;
+            _azureStorage = azureStorage;
            // _azureBlobDBRepository = azureBlobDBRepository;
         }
 
@@ -99,7 +99,7 @@ namespace TEAMModelOS.Controllers
         public async Task<BaseResponse> uploaded(JosnRequest<Dictionary<string, object>> request)
         {
             ResponseBuilder responseBuilder = new ResponseBuilder();
-            List<AzureBlobModel> models = await azureTableDBRepository.FindListByDict<AzureBlobModel>(request.@params);
+            List<AzureBlobModel> models = await _azureStorage.FindListByDict<AzureBlobModel>(request.@params);
             if (models.IsNotEmpty())
             {
                 return responseBuilder.Data(models.First()).build();
@@ -120,7 +120,7 @@ namespace TEAMModelOS.Controllers
         public async Task<BaseResponse> saveBlob(JosnRequest<AzureBlobModel> request)
         {
             ResponseBuilder responseBuilder = new ResponseBuilder();
-            AzureBlobModel model = await azureTableDBRepository.SaveOrUpdate<AzureBlobModel>(request.@params);
+            AzureBlobModel model = await _azureStorage.SaveOrUpdate<AzureBlobModel>(request.@params);
             if (model != null && !string.IsNullOrEmpty(model.RowKey))
             {
                 return responseBuilder.Data(model).build();

+ 12 - 12
TEAMModelOS/Controllers/Exam/ImportExerciseController.cs

@@ -25,17 +25,17 @@ namespace TEAMModelOS.Controllers
     [Route("api/[controller]")]
     [ApiController]
     public class ImportExerciseController : BaseController
-    { 
-        
-      //  private readonly IHtexService htexService;
-        private  AzureStorageFactory azureBlobDBRepository { get; set; }
-        private  IWebHostEnvironment webHostEnvironment { get; set; }
+    {
+
+        //  private readonly IHtexService htexService;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly IWebHostEnvironment _webHostEnvironment;
         private  List<LangConfig> langConfigs { get; set; }
-        public ImportExerciseController(   AzureStorageFactory _azureBlobDBRepository, IWebHostEnvironment _webHostEnvironment)
+        public ImportExerciseController(   AzureStorageFactory azureStorage, IWebHostEnvironment webHostEnvironment)
         {
-            webHostEnvironment = _webHostEnvironment;
-            azureBlobDBRepository = _azureBlobDBRepository;
-            string path = webHostEnvironment.ContentRootPath + "/JsonFile/Core/LangConfig.json";
+            _webHostEnvironment = webHostEnvironment;
+            _azureStorage = azureStorage;
+            string path = _webHostEnvironment.ContentRootPath + "/JsonFile/Core/LangConfig.json";
             FileStream fs = new FileStream(path, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
             StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);
             String line;
@@ -59,7 +59,7 @@ namespace TEAMModelOS.Controllers
         {
             ResponseBuilder responseBuilder = new ResponseBuilder();
 
-            Dictionary<string, object> model = await HtexService.LoadDoc(azureBlobDBRepository, file);
+            Dictionary<string, object> model = await HtexService.LoadDoc(_azureStorage, file);
             return responseBuilder.Data(model).build();
         }
         /// <summary>
@@ -78,7 +78,7 @@ namespace TEAMModelOS.Controllers
             {
                 return responseBuilder.Error(ResponseCode.FAILED, "type is not docx!").build();
             }
-           Dictionary<string, object> model = await ImportExerciseService.UploadWord(azureBlobDBRepository, file);
+           Dictionary<string, object> model = await ImportExerciseService.UploadWord(_azureStorage, file);
 
             return responseBuilder.Data(model).build();
         }
@@ -133,7 +133,7 @@ namespace TEAMModelOS.Controllers
             {
                 LangConfig langConfig = langConfigs.Where(x => x.Lang == lang.ToString()).FirstOrDefault();
                 HtmlAnalyzeService htmlAnalyzeService = new HtmlAnalyzeService(langConfig);
-                Htex exercises = await HtexService.AnalyzeHtmlToHtex(azureBlobDBRepository, htmlString.ToString(), lang.ToString(), htmlAnalyzeService);
+                Htex exercises = await HtexService.AnalyzeHtmlToHtex(_azureStorage, htmlString.ToString(), lang.ToString(), htmlAnalyzeService);
                 return builder.Data(exercises).build();
             }
             else

TEAMModelOS/Controllers/Core/AuthController.cs → TEAMModelOS/Controllers/xTest/AuthController.cs


TEAMModelOS/Controllers/Core/BlobController.cs → TEAMModelOS/Controllers/xTest/BlobController.cs


+ 4 - 4
TEAMModelOS/Service/Evaluation/ImportExerciseService.cs

@@ -33,14 +33,14 @@ namespace TEAMModelOS.Service.Services.Exam.Implements
         //   // azureBlobDBRepository = _azureBlobDBRepository;
         //    azureTableDBRepository = _azureTableDBRepository;
         //}
-        public static async Task<Dictionary<string, object>> UploadWord(this AzureStorageFactory azureBlobDBRepository, IFormFile file)
+        public static async Task<Dictionary<string, object>> UploadWord(this AzureStorageFactory azureStorage, IFormFile file)
         {
 
             Dictionary<string, object> resdict = new Dictionary<string, object>();
             string shaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
             long length = file.Length;
             Dictionary<string, object> dict = new Dictionary<string, object> { { "Sha1Code", shaCode } };
-            List<AzureBlobModel> models = await azureBlobDBRepository.FindListByDict<AzureBlobModel>(dict);
+            List<AzureBlobModel> models = await azureStorage.FindListByDict<AzureBlobModel>(dict);
 
             //if (models.IsNotEmpty())
             //{
@@ -56,9 +56,9 @@ namespace TEAMModelOS.Service.Services.Exam.Implements
             //    await file.CopyToAsync(stream);
             //}
             var htmlInfo = ConvertDocxToHtml(file, folder);
-            AzureBlobModel model = await AzureStorageBlobExtensions.UploadFileByContainer(azureBlobDBRepository, "teammodelos", htmlInfo.htmlString, "exercise", htmlInfo.blobPath, false);
+            AzureBlobModel model = await AzureStorageBlobExtensions.UploadFileByContainer(azureStorage, "teammodelos", htmlInfo.htmlString, "exercise", htmlInfo.blobPath, false);
             model.Sha1Code = shaCode;
-            await azureBlobDBRepository.Save<AzureBlobModel>(model);
+            await azureStorage.Save<AzureBlobModel>(model);
            // FileHelper.DeleteDirAndFiles(BaseConfigModel.ContentRootPath + "/Upload");
             resdict.Add("HtmlString", htmlInfo.htmlString);
             resdict.Add("Sha1Code", shaCode);

+ 9 - 9
TEAMModelOS/Service/PowerPoint/HtexService.cs

@@ -39,7 +39,7 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
         //    azureBlobDBRepository = _azureBlobDBRepository;
         //   // htmlAnalyzeService = _htmlAnalyzeService;
         //}
-        public static async Task<Htex> AnalyzeHtmlToHtex(this AzureStorageFactory azureBlobDBRepository, string htmlString, string Lang, HtmlAnalyzeService htmlAnalyzeService)
+        public static async Task<Htex> AnalyzeHtmlToHtex(this AzureStorageFactory azureStorage, string htmlString, string Lang, HtmlAnalyzeService htmlAnalyzeService)
         {
 
            
@@ -52,20 +52,20 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
             {
                 Slide slide = new Slide { exercise = item, index = index, source = 2, flag = 2 };
                 index++;
-                AzureBlobModel model =  await azureBlobDBRepository.UploadFileByContainer("teammodelos", slide.ToJsonString(), "htex/"+sha, index+".json",false);
+                AzureBlobModel model =  await azureStorage.UploadFileByContainer("teammodelos", slide.ToJsonString(), "htex/"+sha, index+".json",false);
                 htex.slides.Add(model.BlobUrl);
             }
             htex.page = items.Count;
             return htex;
         }
-        public static async Task<Dictionary<string, object>> LoadDoc(this AzureStorageFactory azureBlobDBRepository, IFormFile file)
+        public static async Task<Dictionary<string, object>> LoadDoc(this AzureStorageFactory azureStorage, IFormFile file)
         {
             Dictionary<string, object> resdict = new Dictionary<string, object>();
 
             if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx"))
             {
                 
-                return await ConvertPPTX(azureBlobDBRepository, file, resdict);
+                return await ConvertPPTX(azureStorage, file, resdict);
             }
             else if (FileType.GetExtention(file.FileName).ToLower().Equals("pdf"))
             {
@@ -85,7 +85,7 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
                 sr.Close();
                 xmlDocument.LoadXml(builder.ToString());
                 string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
-                var rslt_ary = await ProcessPPTX(azureBlobDBRepository, xmlDocument, shaCode);
+                var rslt_ary = await ProcessPPTX(azureStorage, xmlDocument, shaCode);
                 //TODO
                 Dictionary<string, object> data = new Dictionary<string, object> { { "htexl", rslt_ary } };
                 return data;
@@ -96,7 +96,7 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
             }
         }
 
-        public static async Task<Dictionary<string, object>> ConvertPPTX(this AzureStorageFactory azureBlobDBRepository, IFormFile file, Dictionary<string, object> resdict)
+        public static async Task<Dictionary<string, object>> ConvertPPTX(this AzureStorageFactory azureStorage, IFormFile file, Dictionary<string, object> resdict)
         {
             string shaCode = fileShaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
 
@@ -110,7 +110,7 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
             XmlDocument xmlDocument = new XmlDocument();
             xmlDocument.LoadXml(xdoc.ToString());
 
-            var rslt_ary = await ProcessPPTX(azureBlobDBRepository, xmlDocument, shaCode);
+            var rslt_ary = await ProcessPPTX(azureStorage, xmlDocument, shaCode);
             //TODO
             Dictionary<string, object> data = new Dictionary<string, object> { { "pptx",rslt_ary} };
             return data;
@@ -122,7 +122,7 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
         /// <param name="xdoc"></param>
         /// <param name="shaCode"></param>
         /// <returns></returns>
-        public static async Task<Htex> ProcessPPTX(this AzureStorageFactory azureBlobDBRepository, XmlDocument xdoc, string shaCode)
+        public static async Task<Htex> ProcessPPTX(this AzureStorageFactory azureStorage, XmlDocument xdoc, string shaCode)
         {
             Htex pptx = new Htex();
           //  List<Dictionary<string, object>> post_ary = new List<Dictionary<string, object>>();
@@ -157,7 +157,7 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
                
                 slide.source = 1;
                 slide.flag = 1;
-                AzureBlobModel model = await azureBlobDBRepository.UploadFileByContainer("teammodelos", slide.ToJsonString(), "htex/" + shaCode, (i + 1) + ".json", false);
+                AzureBlobModel model = await azureStorage.UploadFileByContainer("teammodelos", slide.ToJsonString(), "htex/" + shaCode, (i + 1) + ".json", false);
                 pptx.slides.Add(model.BlobUrl);
                 slides.Add(slide);
                 //  post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });