ソースを参照

处理ServiceBus

CrazyIter 4 年 前
コミット
ecd54a2a16

+ 1 - 0
TEAMModelFunction/TEAMModelFunction.csproj

@@ -8,6 +8,7 @@
     <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.7" />
     <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.2" />
     <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
+    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.5.0" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\TEAMModelOS.SDK\TEAMModelOS.SDK.csproj" />

+ 2 - 0
TEAMModelOS.SDK/DI/AzureServiceBus/AzureServiceBusExtensions.cs

@@ -14,6 +14,8 @@ namespace TEAMModelOS.SDK.DI
 {
     public static class AzureServiceBusExtensions
     {
+
+        public static Dictionary<string, ServiceBusClient> topClients { get; set; } = new Dictionary<string, ServiceBusClient>();
         /// <summary>
         /// 發送信息至對列或主題
         /// </summary>       

+ 1 - 2
TEAMModelOS.SDK/DI/AzureServiceBus/AzureServiceBusFactoryOptions.cs

@@ -8,7 +8,6 @@ namespace TEAMModelOS.SDK.DI
     {
         public string Name { get; set; }
         public string ServiceBusConnectionString { get; set; }
+      
     }
-
-   
 }

+ 141 - 0
TEAMModelOS.SDK/DI/AzureStorage/Inner/AzureBlobModel.cs

@@ -0,0 +1,141 @@
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.Azure.Cosmos.Table;
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.IO;
+using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
+
+namespace TEAMModelOS.SDK.Module.AzureBlob.Container
+{
+
+    public class AzureBlobModel : TableEntity
+    {
+
+
+        public AzureBlobModel()
+        {
+            long time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
+            Timestamp = DateTime.UtcNow;
+        }
+
+        public AzureBlobModel(IFormFile f, string Container, string groupName, string newName)
+        {
+            long time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
+            ContentType = f.ContentType;
+            ContentDisposition = f.ContentDisposition;
+            FileName = f.FileName;
+            // Headers = f.Headers.Values;
+            RealName = groupName + "/" + newName;
+            Folder = groupName;
+            Length = f.Length;
+            Name = f.Name;
+            UploadTime = time;
+            PartitionKey = Container;
+            RowKey = Guid.NewGuid().ToString();
+            Extension = f.FileName.Substring(f.FileName.LastIndexOf(".") + 1, (f.FileName.Length - f.FileName.LastIndexOf(".") - 1)); //扩展名
+            Timestamp = DateTimeHelper.ConvertToDateTime(time);
+        }
+
+        public AzureBlobModel(FileInfo f, string Container, string groupName, string newName, string contentType)
+        {
+            long time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
+            ContentType = contentType;
+            ContentDisposition = "form-data; name=\"file\"; filename=\"" + f.Name + "\"";
+            FileName = f.Name;
+            // Headers = f.Headers.Values;
+            RealName = groupName + "/" + newName;
+            Folder = groupName;
+            Length = f.Length;
+            Name = "file";
+            UploadTime = time;
+            PartitionKey = Container;
+            RowKey = Guid.NewGuid().ToString();
+            Extension = f.Name.Substring(f.Name.LastIndexOf(".") + 1, (f.Name.Length - f.Name.LastIndexOf(".") - 1)); //扩展名
+            Timestamp = DateTimeHelper.ConvertToDateTime(time);
+        }
+
+        public AzureBlobModel(string fileName, string Container, string groupName, string newName, string contentType, long length)
+        {
+            long time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
+            ContentType = contentType;
+            ContentDisposition = "form-data; name=\"file\"; filename=\"" + fileName + "\"";
+            FileName = fileName;
+            // Headers = f.Headers.Values;
+            RealName = groupName + "/" + newName;
+            Folder = groupName;
+            Length = length;
+            Name = "file";
+            UploadTime = time;
+            PartitionKey = Container;
+            RowKey = Guid.NewGuid().ToString();
+            Extension = fileName.Substring(fileName.LastIndexOf(".") + 1, (fileName.Length - fileName.LastIndexOf(".") - 1)); //扩展名
+            Timestamp = DateTimeHelper.ConvertToDateTime(time);
+        }
+        public AzureBlobModel(string fileName, string Container, string groupName, string newName, string sha1Code, string contentType, long length)
+        {
+            long time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
+            ContentType = contentType;
+            ContentDisposition = "form-data; name=\"file\"; filename=\"" + fileName + "\"";
+            FileName = fileName;
+            // Headers = f.Headers.Values;
+            Sha1Code = sha1Code;
+            RealName = groupName + "/" + newName;
+            Folder = groupName;
+            Length = length;
+            Name = "file";
+            UploadTime = time;
+            PartitionKey = Container;
+            RowKey = Guid.NewGuid().ToString();
+            Extension = fileName.Substring(fileName.LastIndexOf(".") + 1, (fileName.Length - fileName.LastIndexOf(".") - 1)); //扩展名
+            Timestamp = DateTime.UtcNow;
+        }
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string Folder { get; set; }
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string Sha1Code { get; set; }
+        //
+        // 摘要:
+        //     Gets the raw Content-Type header of the uploaded file.
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string BlobUrl { get; set; }
+
+        //
+        // 摘要:
+        //     Gets the raw Content-Type header of the uploaded file.
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string ContentType { get; set; }
+        //
+        // 摘要:
+        //     Gets the raw Content-Disposition header of the uploaded file.
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string ContentDisposition { get; set; }
+        //
+        // 摘要:
+        //     Gets the header dictionary of the uploaded file.
+        //  public IHeaderDictionary Headers { get; set; }
+        //
+        // 摘要:
+        //     Gets the file length in bytes.
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public long Length { get; set; }
+        //
+        // 摘要:
+        //     Gets the form field name from the Content-Disposition header.
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string Name { get; set; }
+        //
+        // 摘要:
+        //     Gets the file name from the Content-Disposition header.
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string FileName { get; set; }
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string RealName { get; set; }
+        //上传时间戳
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public long UploadTime { get; set; }
+        //上传扩展文件
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string Extension { get; set; }
+    }
+}

+ 14 - 0
TEAMModelOS.SDK/DI/AzureStorage/Inner/BlobAuth.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Module.AzureBlob.Configuration
+{
+    public class BlobAuth
+    {
+        public string url { get; set; }
+        public string sas { get; set; }
+        public long timeout { get; set; }
+        public string name { get; set; }
+    }
+}

+ 26 - 0
TEAMModelOS.SDK/DI/AzureStorage/Inner/BlobSas.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Module.AzureBlob.Configuration
+{
+    public class BlobSas
+    {
+        /// <summary>
+        /// 容器 学校编码,教师编码
+        /// </summary>
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string name { get; set; }
+        /// <summary>
+        /// 角色 student,teacher,school,system
+        /// </summary>
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string role { get; set; }
+        /// <summary>
+        ///如果是学生则有值
+        /// </summary>
+
+        public string code { get; set; }
+    }
+}

+ 1 - 1
TEAMModelOS.SDK/Module/OpenXmlTool/WmlToHtmlConverter.cs

@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft. All rights reserved.
+// Copyright (c) Microsoft. All rights reserved.
 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
 
 using System;

+ 4 - 0
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -53,4 +53,8 @@
     <PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="2.0.0-preview" /> 
     <PackageReference Include="Caching.CSRedis" Version="3.5.5" />
   </ItemGroup>
+
+  <ItemGroup>
+    <Folder Include="DI\AzureServiceBus\Inner\" />
+  </ItemGroup>
 </Project>

+ 0 - 1
TEAMModelOS/Controllers/Analysis/ChangeController.cs

@@ -12,7 +12,6 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
-using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.Service.Models;
 

+ 0 - 1
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -11,7 +11,6 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Helper.Network.HttpHelper;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
-using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
 using TEAMModelOS.SDK.DI;
 
 namespace TEAMModelOS.Controllers.Core

+ 0 - 1
TEAMModelOS/Controllers/Core/FileController.cs

@@ -12,7 +12,6 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Security.AESCrypt;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
 using TEAMModelOS.SDK.Module.AzureBlob.Container;
-using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
 
 using TEAMModelOS.SDK.DI;
 

+ 3 - 4
TEAMModelOS/Controllers/Exam/ExamController.cs

@@ -11,8 +11,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.Service.Models; 
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.Service.Services.Learn.Implements;
-using TEAMModelOS.SDK.Module.AzureServiceBus;
-
+ 
 namespace TEAMModelOS.Controllers
 {
     [Route("api/[controller]")]
@@ -20,8 +19,8 @@ namespace TEAMModelOS.Controllers
     public class ExamController : BaseController
     {
         private readonly AzureCosmosFactory cosmosDBV3Repository;
-        private readonly IAzureServiceBusService _serviceBus;
-        public ExamController(AzureCosmosFactory _cosmosDBV3Repository, IAzureServiceBusService serviceBus)
+        private readonly AzureServiceBusFactory _serviceBus;
+        public ExamController(AzureCosmosFactory _cosmosDBV3Repository, AzureServiceBusFactory serviceBus)
         {
             
             cosmosDBV3Repository = _cosmosDBV3Repository;

+ 0 - 1
TEAMModelOS/Controllers/Syllabus/ResourceController.cs

@@ -6,7 +6,6 @@ using System.Threading.Tasks;
 using TEAMModelOS.SDK.Context.Exception;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
-using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
 using TEAMModelOS.SDK.DI;
 
 using TEAMModelOS.Service.Models;

+ 3 - 5
TEAMModelOS/Controllers/Task/HomeworkController.cs

@@ -1,6 +1,5 @@
 
 using Microsoft.AspNetCore.Mvc;
-using Microsoft.Azure.ServiceBus;
 using System;
 using System.Collections.Generic;
 using System.Configuration;
@@ -15,8 +14,7 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
-using TEAMModelOS.SDK.DI;
-using TEAMModelOS.SDK.Module.AzureServiceBus;
+using TEAMModelOS.SDK.DI; 
 using TEAMModelOS.Service.Models; 
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.Service.Services.Learn.Implements;
@@ -32,8 +30,8 @@ namespace TEAMModelOS.Controllers.Learn
     {
         private readonly AzureCosmosFactory _cosmos;
        
-        private readonly IAzureServiceBusService _serviceBus;
-        public HomeworkController(AzureCosmosFactory cosmos , IAzureServiceBusService serviceBus  )
+        private readonly AzureServiceBusFactory _serviceBus;
+        public HomeworkController(AzureCosmosFactory cosmos , AzureServiceBusFactory serviceBus  )
         {
             _cosmos = cosmos;
             _serviceBus = serviceBus;

+ 3 - 4
TEAMModelOS/Controllers/Task/LearnController.cs

@@ -10,8 +10,7 @@ using TEAMModelOS.SDK.Helper.Common.ValidateHelper;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.Service.Models;
 using TEAMModelOS.Models; 
-using TEAMModelOS.SDK.Context.Constant.Common;
-using TEAMModelOS.SDK.Module.AzureServiceBus;
+using TEAMModelOS.SDK.Context.Constant.Common; 
 using TEAMModelOS.Service.Services.Learn.Implements;
 
 namespace TEAMModelOS.Controllers.Learn
@@ -24,8 +23,8 @@ namespace TEAMModelOS.Controllers.Learn
     public class LearnController: BaseController
     {
         private readonly AzureCosmosFactory cosmosDBV3Repository;
-        private readonly IAzureServiceBusService _serviceBus;
-        public LearnController(AzureCosmosFactory _cosmosDBV3Repository, IAzureServiceBusService serviceBus)
+        private readonly AzureServiceBusFactory _serviceBus;
+        public LearnController(AzureCosmosFactory _cosmosDBV3Repository, AzureServiceBusFactory serviceBus)
         {
             _serviceBus = serviceBus;
             cosmosDBV3Repository = _cosmosDBV3Repository;

+ 2 - 3
TEAMModelOS/Controllers/Task/SurveyController.cs

@@ -10,7 +10,6 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.Service.Models; 
 using TEAMModelOS.SDK.Context.Constant.Common;
-using TEAMModelOS.SDK.Module.AzureServiceBus;
 using TEAMModelOS.Service.Services.Learn.Implements;
 
 namespace TEAMModelOS.Controllers
@@ -24,8 +23,8 @@ namespace TEAMModelOS.Controllers
     {
         private readonly AzureCosmosFactory azureCosmosDBV3Repository;
  
-        private readonly IAzureServiceBusService _serviceBus;
-        public SurveyController(AzureCosmosFactory _azureCosmosDBV3Repository, IAzureServiceBusService serviceBus)
+        private readonly AzureServiceBusFactory _serviceBus;
+        public SurveyController(AzureCosmosFactory _azureCosmosDBV3Repository, AzureServiceBusFactory serviceBus)
         {
             //  _timerWorkService = timerWorkService;
             _serviceBus = serviceBus;

+ 2 - 3
TEAMModelOS/Controllers/Task/VoteController.cs

@@ -14,7 +14,6 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.Service.Models; 
 using TEAMModelOS.SDK.Context.Constant.Common;
-using TEAMModelOS.SDK.Module.AzureServiceBus;
 using TEAMModelOS.Service.Services.Learn.Implements;
 
 namespace TEAMModelOS.Controllers.Learn
@@ -29,8 +28,8 @@ namespace TEAMModelOS.Controllers.Learn
 
         private readonly AzureCosmosFactory _cosmos;
        
-        private readonly IAzureServiceBusService _serviceBus;
-        public VoteController(AzureCosmosFactory cosmos, IAzureServiceBusService serviceBus)
+        private readonly AzureServiceBusFactory _serviceBus;
+        public VoteController(AzureCosmosFactory cosmos, AzureServiceBusFactory serviceBus)
         {
             _cosmos = cosmos;
             _serviceBus = serviceBus;

+ 0 - 1
TEAMModelOS/Service/Evaluation/ImportExerciseService.cs

@@ -20,7 +20,6 @@ using TEAMModelOS.SDK.Helper.Common.FileHelper;
 using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.SDK.Helper.Security.ShaHash;
 using TEAMModelOS.SDK.Module.AzureBlob.Container;
-using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
 
 
 namespace TEAMModelOS.Service.Services.Exam.Implements

+ 3 - 13
TEAMModelOS/Service/Learn/ServiceBusService.cs

@@ -1,4 +1,3 @@
-using Microsoft.Azure.ServiceBus;
 using System;
 using System.Collections.Generic;
 using System.Reflection;
@@ -9,19 +8,16 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.DI;
-using TEAMModelOS.SDK.Module.AzureServiceBus;
 
 namespace TEAMModelOS.Service.Services.Learn.Implements
 {
     
     public static class ServiceBusService  
     {
-       // private readonly IAzureServiceBusService _serviceBus;
-                
 
-        public static async Task<long> SendMessage<T>(this IAzureServiceBusService _serviceBus ,string TopicName, string id,string pk, long startTime, int status, string msgId)
+        public static async Task<long> SendMessage<T>(this AzureServiceBusFactory _serviceBus ,string TopicName, string id,string pk, long startTime, int status, string msgId)
         {
-            ITopicClient topicClient = _serviceBus.GetTopClient(TopicName).topicClient;
+            var  topicClient = _serviceBus.GetServiceBusClient();
             //设定开始时间
             Dictionary<string, object> dict = new Dictionary<string, object>() {
                     { "name",typeof(T).Name},
@@ -31,10 +27,6 @@ namespace TEAMModelOS.Service.Services.Learn.Implements
                 };
             //var msgId = "1";
             string messageBody = $"Message {dict}";
-            var message = new Message() {
-                MessageId = msgId,
-                Body = Encoding.UTF8.GetBytes(dict.ToApiJson())
-            };
             long time = startTime - new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
             if (time <= 0)
             {
@@ -42,9 +34,7 @@ namespace TEAMModelOS.Service.Services.Learn.Implements
             }
             DateTime timer = DateTimeHelper.ConvertToDateTime(startTime);
             Console.WriteLine($"Sending message: {messageBody}");
-            long SequenceNumber = await topicClient.ScheduleMessageAsync(message, new DateTimeOffset(timer));            
-            //await topicClient.SendAsync(message);
-            //await topicClient.CloseAsync();
+            long SequenceNumber = await topicClient.SendScheduleMessageAsync(TopicName, dict.ToApiJson(), new DateTimeOffset(timer));            
             return SequenceNumber;
         }
     }

+ 0 - 1
TEAMModelOS/Service/PowerPoint/HtexService.cs

@@ -14,7 +14,6 @@ using TEAMModelOS.SDK.Context.Exception;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Security.ShaHash;
 using TEAMModelOS.SDK.Module.AzureBlob.Container;
-using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
 using TEAMModelOS.Service.Models.PowerPoint.Inner; 
 using Fill = TEAMModelOS.Service.Model.PowerPoint.Fill;
 using Media = TEAMModelOS.Service.Model.PowerPoint.Media;

+ 2 - 3
TEAMModelOS/Startup.cs

@@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Http.Features;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.SpaServices;
-using Microsoft.Azure.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
@@ -26,7 +25,6 @@ using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Context.Filter;
 using TEAMModelOS.SDK.DI;
-using TEAMModelOS.SDK.Module.AzureServiceBus;
 using TEAMModelOS.Service.Services.Learn.Implements;
 using VueCliMiddleware;
 
@@ -82,6 +80,7 @@ namespace TEAMModelOS
             services.AddAzureStorage(Configuration.GetValue<string>("Azure:Starage:ConnectionString"));            
             services.AddAzureRedis( Configuration.GetValue<string>("Azure:Redis:ConnectionString"));            
             services.AddAzureCosmos(Configuration.GetValue<string>("Azure:Cosmos:ConnectionString"));
+            services.AddAzureServiceBus(Configuration.GetValue<string>("Azure:ServiceBus:ConnectionString"));
             services.AddSnowflakeId(Convert.ToInt64(Configuration.GetValue<string>("Option:LocationNum")), 1);
             services.AddHttpClient();
             services.AddHttpClient<DingDing>();            
@@ -93,7 +92,7 @@ namespace TEAMModelOS
             //使用Blob配置
             //services.AddAzureBlobStorage().AddConnection(Configuration.GetSection("Azure:Blob").Get<AzureBlobOptions>());
             //使用AzureServiceBus
-            services.AddServiceBus().AddServiceBusOptions(Configuration.GetSection("Azure:ServiceBus").Get<AzureServiceBusOptions>());
+          
             //HttpContextAccessor,并用来访问HttpContext。
             services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
             //services.AddSingleton<IServiceBusReviceService, ServiceBusReviceService>();