浏览代码

word文档导入测试

黄贺彬 6 年之前
父节点
当前提交
5b883099e8

+ 0 - 1
.gitignore

@@ -252,4 +252,3 @@ _Pvt_Extensions
 
 .vscode/
 /.idea
-/TEAMModelOS

+ 14 - 0
TEAMModelOS.Model/Core/Dtos/CodeValue.cs

@@ -0,0 +1,14 @@
+using MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.Model.Core.Dtos
+{
+    [MessagePackObject(keyAsPropertyName: true)]
+    public class CodeValue
+    {
+        public string Code { get; set; }
+        public string Value { get; set; }
+    }
+}

+ 18 - 0
TEAMModelOS.Model/Core/Models/ContentVerify.cs

@@ -0,0 +1,18 @@
+using Microsoft.WindowsAzure.Storage.Table;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+
+namespace TEAMModelOS.Model.Core.Models
+{
+    [TableSpace(Name = "Core")]
+    public class ContentVerify : TableEntity
+    {
+        public string Content { get; set; }
+        public string AlgorithmType { get; set; }
+        public string DigestCode { get; set; }
+        public string TeamModelId { get; set; }
+
+    }
+}

+ 24 - 0
TEAMModelOS.Model/Evaluation/Dtos/ExerciseDto.cs

@@ -0,0 +1,24 @@
+using MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.Model.Core.Dtos;
+
+namespace TEAMModelOS.Model.Evaluation.Dtos
+{
+    [MessagePackObject(keyAsPropertyName: true)]
+    public class ExerciseDto
+    {
+        public ExerciseDto()
+        {
+            Option = new List<CodeValue>();
+            Answer = new List<string>();
+        }
+
+        public string Question { get; set; }
+        public List<CodeValue> Option { get; set; }
+        public List<string> Answer { get; set; }
+        public string Explain { get; set; }
+        public string Type { get; set; }
+    }
+}

+ 1 - 0
TEAMModelOS.Model/TEAMModelOS.Model.csproj

@@ -7,6 +7,7 @@
   <ItemGroup>
     <Folder Include="Analysis\Dtos\" />
     <Folder Include="Analysis\Models\" />
+    <Folder Include="Evaluation\Models\" />
   </ItemGroup>
   <ItemGroup>
     <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />

+ 23 - 0
TEAMModelOS.SDK/Extension/SnowFlake/DisposableAction.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Extension.SnowFlake
+{
+    public class DisposableAction : IDisposable
+    {
+        readonly Action _action;
+
+        public DisposableAction(Action action)
+        {
+            if (action == null)
+                throw new ArgumentNullException("action");
+            _action = action;
+        }
+
+        public void Dispose()
+        {
+            _action();
+        }
+    }
+}

+ 139 - 0
TEAMModelOS.SDK/Extension/SnowFlake/IdWorker.cs

@@ -0,0 +1,139 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Extension.SnowFlake
+{
+    public class IdWorker
+    {
+        //基准时间
+        public const long Twepoch = 1288834974657L;
+        //机器标识位数
+        const int WorkerIdBits = 5;
+        //数据标志位数
+        const int DatacenterIdBits = 5;
+        //序列号识位数
+        const int SequenceBits = 12;
+        //机器ID最大值
+        const long MaxWorkerId = -1L ^ (-1L << WorkerIdBits);
+        //数据标志ID最大值
+        const long MaxDatacenterId = -1L ^ (-1L << DatacenterIdBits);
+        //序列号ID最大值
+        private const long SequenceMask = -1L ^ (-1L << SequenceBits);
+        //机器ID偏左移12位
+        private const int WorkerIdShift = SequenceBits;
+        //数据ID偏左移17位
+        private const int DatacenterIdShift = SequenceBits + WorkerIdBits;
+        //时间毫秒左移22位
+        public const int TimestampLeftShift = SequenceBits + WorkerIdBits + DatacenterIdBits;
+
+        private long _sequence = 0L;
+        private long _lastTimestamp = -1L;
+
+        private long WorkerId { get;  set; }
+        private long DatacenterId { get;  set; }
+        public long Sequence
+        {
+            get { return _sequence; }
+            internal set { _sequence = value; }
+        }
+        private IdWorker() { }
+        private IdWorker(long workerId, long datacenterId, long sequence = 0L)
+        {
+            // 如果超出范围就抛出异常
+            if (workerId > MaxWorkerId || workerId < 0)
+            {
+                throw new ArgumentException(string.Format("worker Id 必须大于0,且不能大于MaxWorkerId: {0}", MaxWorkerId));
+            }
+
+            if (datacenterId > MaxDatacenterId || datacenterId < 0)
+            {
+                throw new ArgumentException(string.Format("region Id 必须大于0,且不能大于MaxWorkerId: {0}", MaxDatacenterId));
+            }
+
+            //先检验再赋值
+            WorkerId = workerId;
+            DatacenterId = datacenterId;
+            _sequence = sequence;
+        }
+
+        readonly object _lock = new Object();
+        public virtual long NextId()
+        {
+            lock (_lock)
+            {
+                var timestamp = TimeGen();
+                if (timestamp < _lastTimestamp)
+                {
+                    throw new Exception(string.Format("时间戳必须大于上一次生成ID的时间戳.  拒绝为{0}毫秒生成id", _lastTimestamp - timestamp));
+                }
+
+                //如果上次生成时间和当前时间相同,在同一毫秒内
+                if (_lastTimestamp == timestamp)
+                {
+                    //sequence自增,和sequenceMask相与一下,去掉高位
+                    _sequence = (_sequence + 1) & SequenceMask;
+                    //判断是否溢出,也就是每毫秒内超过1024,当为1024时,与sequenceMask相与,sequence就等于0
+                    if (_sequence == 0)
+                    {
+                        //等待到下一毫秒
+                        timestamp = TilNextMillis(_lastTimestamp);
+                    }
+                }
+                else
+                {
+                    //如果和上次生成时间不同,重置sequence,就是下一毫秒开始,sequence计数重新从0开始累加,
+                    //为了保证尾数随机性更大一些,最后一位可以设置一个随机数
+                    _sequence = 0;//new Random().Next(10);
+                }
+
+                _lastTimestamp = timestamp;
+                return ((timestamp - Twepoch) << TimestampLeftShift) | (DatacenterId << DatacenterIdShift) | (WorkerId << WorkerIdShift) | _sequence;
+            }
+        }
+
+        // 防止产生的时间比之前的时间还要小(由于NTP回拨等问题),保持增量的趋势.
+        protected virtual long TilNextMillis(long lastTimestamp)
+        {
+            var timestamp = TimeGen();
+            while (timestamp <= lastTimestamp)
+            {
+                timestamp = TimeGen();
+            }
+            return timestamp;
+        }
+
+        // 获取当前的时间戳
+        protected virtual long TimeGen()
+        {
+            return TimeExtensions.CurrentTimeMillis();
+        }
+
+        public static IdWorker getInstance()
+        {
+            return SingletonInstance.singleton;
+        }
+
+        public static class SingletonInstance
+        {
+           public static IdWorker singleton = new IdWorker(0, 1);
+        }
+        public  static List<long> getIdsByCount(int count)
+        {
+            if (count > 0)
+            {
+                List<long> ids = new List<long>();
+                IdWorker idWorker = IdWorker.getInstance();
+                for (int i = 0; i < count; i++)
+                {
+                    ids.Add(idWorker.NextId());
+                }
+                return ids;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+}

+ 42 - 0
TEAMModelOS.SDK/Extension/SnowFlake/TimeExtensions.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Extension.SnowFlake
+{
+    public static class TimeExtensions
+    {
+        public static Func<long> currentTimeFunc = InternalCurrentTimeMillis;
+
+        public static long CurrentTimeMillis()
+        {
+            return currentTimeFunc();
+        }
+
+        public static IDisposable StubCurrentTime(Func<long> func)
+        {
+            currentTimeFunc = func;
+            return new DisposableAction(() =>
+            {
+                currentTimeFunc = InternalCurrentTimeMillis;
+            });
+        }
+
+        public static IDisposable StubCurrentTime(long millis)
+        {
+            currentTimeFunc = () => millis;
+            return new DisposableAction(() =>
+            {
+                currentTimeFunc = InternalCurrentTimeMillis;
+            });
+        }
+
+        private static readonly DateTime Jan1st1970 = new DateTime
+           (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+
+        private static long InternalCurrentTimeMillis()
+        {
+            return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
+        }
+    }
+}

+ 168 - 0
TEAMModelOS.SDK/Helper/Network/HttpHelper/HttpHelper.cs

@@ -0,0 +1,168 @@
+using System;
+using System.Collections.Generic;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Helper.Network.HttpHelper
+{
+    public class HttpHelper
+    {
+        /// <summary>
+        /// 同步GET请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="headers"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <returns></returns>
+        public static string HttpGet(string url, Dictionary<string, string> headers = null, int timeout = 0)
+        {
+            HttpClient client = new HttpClient();
+            if (headers != null)
+            {
+                foreach (KeyValuePair<string, string> header in headers)
+                {
+                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
+                }
+            }
+            if (timeout > 0)
+            {
+                client.Timeout = new TimeSpan(0, 0, timeout);
+            }
+            Byte[] resultBytes = client.GetByteArrayAsync(url).Result;
+            return Encoding.UTF8.GetString(resultBytes);
+        }
+
+        /// <summary>
+        /// 异步GET请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="headers"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <returns></returns>
+        public static async Task<string> HttpGetAsync(string url, Dictionary<string, string> headers = null, int timeout = 0)
+        {
+            HttpClient client = new HttpClient();
+            if (headers != null)
+            {
+                foreach (KeyValuePair<string, string> header in headers)
+                {
+                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
+                }
+            }
+            if (timeout > 0)
+            {
+                client.Timeout = new TimeSpan(0, 0, timeout);
+            }
+            Byte[] resultBytes = await client.GetByteArrayAsync(url);
+            return Encoding.Default.GetString(resultBytes);
+        }
+
+
+        /// <summary>
+        /// 同步POST请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <param name="headers"></param>
+        /// <param name="contentType"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <param name="encoding">默认UTF8</param>
+        /// <returns></returns>
+        public static string HttpPost(string url, string postData, Dictionary<string, string> headers = null, string contentType = null, int timeout = 0, Encoding encoding = null)
+        {
+            HttpClient client = new HttpClient();
+            if (headers != null)
+            {
+                foreach (KeyValuePair<string, string> header in headers)
+                {
+                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
+                }
+            }
+            if (timeout > 0)
+            {
+                client.Timeout = new TimeSpan(0, 0, timeout);
+            }
+            HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8);
+            if (contentType != null)
+            {
+                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+            }
+            HttpResponseMessage responseMessage = client.PostAsync(url, content).Result;
+            Byte[] resultBytes = responseMessage.Content.ReadAsByteArrayAsync().Result;
+            return Encoding.UTF8.GetString(resultBytes);
+        }
+
+
+        /// <summary>
+        /// 异步POST请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <param name="headers"></param>
+        /// <param name="contentType"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <param name="encoding">默认UTF8</param>
+        /// <returns></returns>
+        public static async Task<string> HttpPostAsync(string url, string postData, Dictionary<string, string> headers = null, string contentType = null, int timeout = 0, Encoding encoding = null)
+        {
+            HttpClient client = new HttpClient();
+            if (headers != null)
+            {
+                foreach (KeyValuePair<string, string> header in headers)
+                {
+                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
+                }
+            }
+            if (timeout > 0)
+            {
+                client.Timeout = new TimeSpan(0, 0, timeout);
+            }
+            HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8);
+            if (contentType != null)
+            {
+                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+            }
+            HttpResponseMessage responseMessage = await client.PostAsync(url, content);
+            Byte[] resultBytes = await responseMessage.Content.ReadAsByteArrayAsync();
+            return Encoding.UTF8.GetString(resultBytes);
+        }
+
+        /// <summary>
+        /// 异步POST请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <param name="headers"></param>
+        /// <param name="contentType"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <param name="encoding">默认UTF8</param>
+        /// <returns></returns>
+        public static async Task<string> HttpPostAsync(string url, List<KeyValuePair<string, string>> postData, Dictionary<string, string> headers = null, string contentType = null, int timeout = 0, Encoding encoding = null)
+        {
+            HttpClient client = new HttpClient();
+            if (headers != null)
+            {
+                foreach (KeyValuePair<string, string> header in headers)
+                {
+                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
+                }
+            }
+            if (timeout > 0)
+            {
+                client.Timeout = new TimeSpan(0, 0, timeout);
+            }
+            HttpContent content = new FormUrlEncodedContent(postData);
+            if (contentType != null)
+            {
+                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+            }
+            HttpResponseMessage responseMessage = await client.PostAsync(url, content);
+
+            Byte[] resultBytes = await responseMessage.Content.ReadAsByteArrayAsync();
+            return Encoding.UTF8.GetString(resultBytes);
+
+        }
+    }
+}
+

+ 137 - 0
TEAMModelOS.SDK/Helper/Security/ShaHash/ShaHashHelper.cs

@@ -0,0 +1,137 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Helper.Security.ShaHash
+{
+    public class ShaHashHelper
+    {
+
+        public static string GetSHA1(string Code) {
+            var resbuffer = Encoding.Default.GetBytes(Code);
+            HashAlgorithm iSha = new SHA1CryptoServiceProvider();
+            resbuffer = iSha.ComputeHash(resbuffer);
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            //return Convert.ToBase64String(strRes);
+        }
+        public static string GetSHA1(byte[] buffer)
+        {
+            var resbuffer = buffer;
+            HashAlgorithm iSha = new SHA1CryptoServiceProvider();
+            resbuffer = iSha.ComputeHash(buffer);
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            // return Convert.ToBase64String(strRes);
+        }
+        public static string GetSHA1(Stream stream)
+        {
+            byte[] buffer = new byte[stream.Length];
+
+            stream.Read(buffer, 0, buffer.Length);
+            stream.Close();
+            var resbuffer = buffer;
+            HashAlgorithm iSha = new SHA1CryptoServiceProvider();
+            resbuffer = iSha.ComputeHash(buffer);
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            // return Convert.ToBase64String(strRes);
+        }
+        public static string GetSHA1(string Code,string SecretKey)
+        {
+            HMACSHA1 hmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(SecretKey));
+            byte[] resbuffer = hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(Code));
+
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            //return Convert.ToBase64String(rstRes); 
+        }
+        public static string GetSHA1(byte[] buffer, string SecretKey)
+        {
+            HMACSHA1 hmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(SecretKey));
+            byte[] resbuffer = hmacsha1.ComputeHash(buffer);
+
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            //eturn Convert.ToBase64String(buffer);
+        }
+        public static string GetSHA256(byte[] buffer)
+        {
+            SHA256Managed Sha256 = new SHA256Managed();
+            byte[] resbuffer = Sha256.ComputeHash(buffer);
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            //return Convert.ToBase64String(retval);
+
+        }
+
+        public static string GetSHA256(string Code)
+        {
+            SHA256Managed Sha256 = new SHA256Managed();
+            byte[] resbuffer = Sha256.ComputeHash(Encoding.UTF8.GetBytes(Code));
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            //return Convert.ToBase64String(retval);
+        }
+
+        public static string GetSHA256(byte[] buffer, string SecretKey)
+        {
+            byte[] messageBytes = buffer;
+            byte[] keyByte = Encoding.UTF8.GetBytes(SecretKey);
+            var hmacsha256 = new HMACSHA256(keyByte);
+            byte[] resbuffer = hmacsha256.ComputeHash(messageBytes);
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            //return Convert.ToBase64String(hashmessage);
+        }
+
+        public static string GetSHA256(string Code, string SecretKey)
+        {
+            byte[] messageBytes = Encoding.UTF8.GetBytes(Code);
+            byte[] keyByte = Encoding.UTF8.GetBytes(SecretKey);
+            var hmacsha256 = new HMACSHA256(keyByte);
+            byte[] resbuffer = hmacsha256.ComputeHash(messageBytes);
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < resbuffer.Length; i++)
+            {
+                builder.Append(resbuffer[i].ToString("x2"));
+            }
+            return builder.ToString();
+            //return Convert.ToBase64String(resbuffer);
+        }
+    }
+}

+ 16 - 2
TEAMModelOS.SDK/Module/AzureBlob/Container/AzureBlobModel.cs

@@ -2,6 +2,7 @@
 using Microsoft.AspNetCore.Http;
 using Microsoft.WindowsAzure.Storage.Table;
 using System;
+using System.ComponentModel.DataAnnotations;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 
 namespace TEAMModelOS.SDK.Module.AzureBlob.Container
@@ -25,6 +26,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Container
             FileName = f.FileName;
             // Headers = f.Headers.Values;
             RealName =  groupName + "/"+ newName;
+            Folder = groupName;
             Length = f.Length;
             Name = f.Name;
             UploadTime = time;
@@ -33,40 +35,52 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Container
             Extension = f.FileName.Substring(f.FileName.LastIndexOf(".") + 1, (f.FileName.Length - f.FileName.LastIndexOf(".") - 1)); //扩展名
             Timestamp = DateTimeHelper.ConvertToDateTime(time);
         }
-
+        [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; }
+        //  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; }
     }
 }

+ 60 - 3
TEAMModelOS.SDK/Module/AzureBlob/Implements/AzureBlobDBRepository.cs

@@ -12,6 +12,9 @@ using Microsoft.AspNetCore.Http.Internal;
 using TEAMModelOS.SDK.Helper.Security.AESCrypt;
 using TEAMModelOS.SDK.Context.Exception;
 using Microsoft.AspNetCore.Http;
+using System.Linq;
+using Microsoft.WindowsAzure.Storage.Shared.Protocol;
+using TEAMModelOS.SDK.Extension.SnowFlake;
 
 namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
 {
@@ -66,12 +69,33 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
         //    //await UploadFiles(null, new FileContainer() );
         //}
 
-        public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file)
+        public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file,string fileSpace="common")
         {
-            string groupName = DateTime.Now.ToString("yyyyMMdd");
+            string groupName = fileSpace+"/" +DateTime.Now.ToString("yyyyMMdd");
             string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
             // await InitializeBlob(DateTime.Now.ToString("yyyyMMdd"));
-            blobContainer  = blobClient.GetContainerReference(groupName);
+            blobContainer  = blobClient.GetContainerReference( groupName);
+            //var serviceProperties = await blobClient.GetServicePropertiesAsync();
+            //var corsSettings = serviceProperties.Cors;
+            //var corsRule = corsSettings.CorsRules.FirstOrDefault(
+            //    o => o.AllowedOrigins.Contains("http://localhost:3904"));//设置你自己的服务器地址
+            //if (corsRule == null)
+            //{
+            //    //Add a new rule.
+            //    corsRule = new CorsRule()
+            //    {
+            //        AllowedHeaders = new List<string> { "x-ms-*", "content-type", "accept" },
+            //        AllowedMethods = CorsHttpMethods.Put| CorsHttpMethods.Head | CorsHttpMethods.Post | CorsHttpMethods.Merge | CorsHttpMethods.Get,//Since we'll only be calling Put Blob, let's just allow PUT verb
+            //        AllowedOrigins = new List<string> { "http://localhost:3904" },//This is the URL of our application.
+            //        ExposedHeaders = { },
+            //        MaxAgeInSeconds = 1 * 60 * 60,//Let the browswer cache it for an hour
+            //    };
+            //    corsSettings.CorsRules.Add(corsRule);
+            //    //Save the rule
+            //    await blobClient.SetServicePropertiesAsync(serviceProperties);
+            //}
+
+
             StorageUri url = blobContainer.StorageUri;
             List<AzureBlobModel> list = new List<AzureBlobModel>();
             foreach (FormFile f in file)
@@ -100,5 +124,38 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
             }
             return list;
         }
+
+        public async Task<AzureBlobModel> UploadWord(IFormFile file, string fileSpace = "wordfiles")
+        {
+            long  bizno= IdWorker.getInstance().NextId();
+            string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd")+"/"+ bizno;
+            string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
+            // await InitializeBlob(DateTime.Now.ToString("yyyyMMdd"));
+            blobContainer = blobClient.GetContainerReference(groupName);
+            StorageUri url = blobContainer.StorageUri;
+            string[] names = file.FileName.Split(".");
+            string name = "";
+            for (int i = 0; i < names.Length - 1; i++)
+            {
+                name = name + names[i];
+            }
+            if (names.Length <= 1)
+            {
+                name = name + "_" + newFileName;
+            }
+            else
+            {
+                name = name + "_" + newFileName + "." + names[names.Length - 1];
+            }
+            var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
+            var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
+            var blockBlob = blobContainer.GetBlockBlobReference(name);
+            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());
+            AzureBlobModel model = new AzureBlobModel(file, _options.Container, groupName, name)
+            {
+                BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + name
+            };
+            return model;
+        }
     }
 }

+ 2 - 1
TEAMModelOS.SDK/Module/AzureBlob/Interfaces/IAzureBlobDBRepository.cs

@@ -7,6 +7,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Interfaces
 {
     public interface IAzureBlobDBRepository
     {
-        Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file);
+        Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file ,string fileSpace="common");
+        Task<AzureBlobModel> UploadWord(IFormFile file, string fileSpace = "wordfiles");
     }
 }

+ 12 - 0
TEAMModelOS.Service/Evaluation/Implements/ImportExerciseService.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.Service.Core.Implements;
+using TEAMModelOS.Service.Evaluation.Interfaces;
+
+namespace TEAMModelOS.Service.Evaluation.Implements
+{
+    public class ImportExerciseService : BaseService, IImportExerciseService
+    {
+    }
+}

+ 11 - 0
TEAMModelOS.Service/Evaluation/Interfaces/IImportExerciseService.cs

@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.Service.Core.Interfaces;
+
+namespace TEAMModelOS.Service.Evaluation.Interfaces
+{
+    public interface IImportExerciseService : IBusinessService, IBaseService
+    {
+    }
+}

+ 1 - 1
TEAMModelOS.sln

@@ -23,7 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "05-应用测试", "05-应
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS.Test.CosmosDB", "TEAMModelOS.Test.CosmosDB\TEAMModelOS.Test.CosmosDB.csproj", "{72CA120D-2C8E-433C-93EC-2E84FC6EFF8E}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamModelOS.Test.JsonPath", "TeamModelOS.Test.JsonPath\TeamModelOS.Test.JsonPath.csproj", "{519FE59A-2D7B-407C-952B-4F497B8BA07E}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamModelOS.Test.JsonPath", "TeamModelOS.Test.JsonPath\TeamModelOS.Test.JsonPath.csproj", "{519FE59A-2D7B-407C-952B-4F497B8BA07E}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+ 65 - 4
TEAMModelOS/Controllers/Core/FileController.cs

@@ -7,7 +7,10 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.Context.Constant.Common;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+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.Core.Interfaces;
@@ -27,7 +30,6 @@ namespace TEAMModelOS.Controllers.Core
 
 
         [HttpPost("uploadFiles")]
-        [AllowAnonymous]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<BaseJosnRPCResponse> BlobSaveFile([FromForm] IFormFile[] files)
         {
@@ -45,7 +47,6 @@ namespace TEAMModelOS.Controllers.Core
             return responseBuilder.Data(list).build();
         }
         [HttpPost("uploadFile")]
-        [AllowAnonymous]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<BaseJosnRPCResponse> BlobSaveFile([FromForm] IFormFile file)
         {
@@ -65,7 +66,6 @@ namespace TEAMModelOS.Controllers.Core
             return responseBuilder.Data(list).build();
         }
         [HttpPost("uploadCkeditor")]
-        [AllowAnonymous]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<Dictionary<string,Object>> uploadCkeditor([FromForm] IFormFile file)
         {
@@ -85,7 +85,6 @@ namespace TEAMModelOS.Controllers.Core
             return  new Dictionary<string, object> { { "uploaded",1 },{"url",list.First().BlobUrl } };
         }
         [HttpPost("uploadWangEditor")]
-        [AllowAnonymous]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<Dictionary<string, Object>> uploadWangEditor([FromForm] IFormFile[] files)
         {
@@ -102,5 +101,67 @@ namespace TEAMModelOS.Controllers.Core
             await _azureBlobModelService.SaveAll<AzureBlobModel>(list);
             return new Dictionary<string, object> { { "errno", 0 }, { "data", list.Select(x=>x.BlobUrl)}};
         }
+
+        [HttpPost("uploadWord")]
+        [RequestSizeLimit(102_400_000_00)] //最大10000m左右
+        public async Task<BaseJosnRPCResponse> uploadWord([FromForm] IFormFile file)
+        {
+            JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
+            if (!FileType.GetExtention(file.FileName).ToLower().Equals("doc"))
+            {
+                return responseBuilder.Error("type is not doc").build();
+            }
+            string shaCode =   ShaHashHelper.GetSHA1(file.OpenReadStream());
+            long length = file.Length;
+            Dictionary<string, object> dict = new Dictionary<string, object> { { "Sha1Code", shaCode },{ "Length", length } };
+            List<AzureBlobModel> models= await _azureBlobModelService.FindListByDict<AzureBlobModel>(dict);
+            if (models.IsNotEmpty()) {
+                return responseBuilder.Data(models.First()).build();
+            }
+            AzureBlobModel model = await _azureBlobDBRepository.UploadWord(file);
+            model.Sha1Code = shaCode;
+            await _azureBlobModelService.Save<AzureBlobModel>(model);
+            return responseBuilder.Data(model).build();
+        }
+
+
+        /// <summary>
+        /// {"Sha1Code":"1111","Length":233444}
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("uploaded")]
+        public async Task<BaseJosnRPCResponse> uploaded(JosnRPCRequest<Dictionary<string,object>> request)
+        {
+            JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
+            List<AzureBlobModel> models = await _azureBlobModelService.FindListByDict<AzureBlobModel>(request.@params);
+            if (models.IsNotEmpty())
+            {
+                return responseBuilder.Data(models.First()).build();
+            }
+            else {
+                return responseBuilder.Data(null).build();
+            }
+        }
+
+
+        /// <summary>
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("saveBlob")]
+        public async Task<BaseJosnRPCResponse> saveBlob(JosnRPCRequest<AzureBlobModel> request)
+        {
+            JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
+             AzureBlobModel  model = await _azureBlobModelService.SaveOrUpdate<AzureBlobModel>(request.@params);
+            if (model != null && !string.IsNullOrEmpty(model.RowKey))
+            {
+                return responseBuilder.Data(model).build();
+            }
+            else
+            {
+                return responseBuilder.Data(null).build();
+            }
+        }
     }
 }

+ 36 - 0
TEAMModelOS/Controllers/Evaluation/ImportExerciseController.cs

@@ -0,0 +1,36 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.Controllers.Core;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.Service.Evaluation.Interfaces;
+
+namespace TEAMModelOS.Controllers.Evaluation
+{
+
+
+    [Route("api/[controller]")]
+    [ApiController]
+    [Authorize]
+    public class ImportExerciseController : BaseController
+    {
+        private readonly  IImportExerciseService importExerciseService;
+
+        public ImportExerciseController(IImportExerciseService _importExerciseService) {
+            importExerciseService = _importExerciseService;
+        }
+
+        [HttpPost("AnalyzeWord")]
+        public async Task<BaseJosnRPCResponse> AnalyzeWord(JosnRPCRequest<Dictionary<string, object>> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            //importExerciseService
+            return builder.Data("").build();
+        }
+        
+    }
+}

+ 0 - 20
TEAMModelOS/Controllers/OssController.cs

@@ -1,20 +0,0 @@
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using System.Linq;
-
-namespace TEAMModelOS.Controllers
-{
-
-    [Route("api/[controller]")]
-    [ApiController]
-    public class OssController : Controller
-    {
-        [HttpPost("Upload")]
-        //[RequestSizeLimit(102_400_000_00)] //最大10000m左右
-        public string[] BlobSaveFile([FromForm] IFormFile[] files)
-        {
-            //throw new BizException("1");
-            return files.Select(f => f.FileName).ToArray();
-        }
-    }
-}

+ 0 - 44
TEAMModelOS/Controllers/ValuesController.cs

@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using TEAMModelOS.SDK.Context.Attributes.Azure;
-
-namespace TEAMModelOS.Controllers
-{
-    [Route("api/[controller]")]
-    [ApiController]
-    public class ValuesController : ControllerBase
-    {
-        // GET api/values
-        [HttpGet]
-        public ActionResult<IEnumerable<string>> Get()
-        {
-
-           // GetTableSpace<Textbook>();
-            return new string[] { "value1", "value2" };
-        }
-
-
-        public string GetTableSpace<T>()
-        {
-            Type type = typeof(T);
-
-            string Name = type.Name;
-
-            object[] attributes = type.GetCustomAttributes(true);
-            foreach (object attribute in attributes) //2.通过映射,找到成员属性上关联的特性类实例,
-            {
-                if (attribute is TableSpaceAttribute tableSpace)
-                {
-                    Name = tableSpace.Name + Name;
-                }
-            }
-            return Name;
-        }
-       
-    }
-}

+ 3 - 3
TEAMModelOS/Properties/launchSettings.json

@@ -10,14 +10,14 @@
   "profiles": {
     "IIS Express": {
       "commandName": "IISExpress",
-      "launchBrowser": true,
+      "launchBrowser": false,
       "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development"
       }
     },
     "TEAMModelOS": {
       "commandName": "Project",
-      "launchBrowser": true,
+      "launchBrowser": false,
       "environmentVariables": {
         "isDebug": "false",
         "ASPNETCORE_ENVIRONMENT": "Development"
@@ -25,4 +25,4 @@
       "applicationUrl": "https://localhost:5001;http://localhost:5000"
     }
   }
-}
+}

文件差异内容过多而无法显示
+ 400 - 15
TeamModelOS.Test.JsonPath/Program.cs


+ 10 - 0
TeamModelOS.Test.JsonPath/TeamModelOS.Test.JsonPath.csproj

@@ -6,7 +6,17 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="HtmlAgilityPack" Version="1.11.4" />
+    <PackageReference Include="Open-Xml-PowerTools" Version="4.4.0" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\TEAMModelOS.Model\TEAMModelOS.Model.csproj" />
     <ProjectReference Include="..\TEAMModelOS.SDK\TEAMModelOS.SDK.csproj" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Folder Include="DocToHtml\" />
+  </ItemGroup>
+
 </Project>

+ 24 - 0
TeamModelOS.Test.JsonPath/TestInfo.cs

@@ -0,0 +1,24 @@
+using MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.Model.Core.Dtos;
+
+namespace TeamModelOS.Test.JsonPath
+{
+    [MessagePackObject(keyAsPropertyName: true)]
+    public class TestInfo
+    {
+        public TestInfo() {
+            Option = new List<CodeValue>();
+            Answer = new List<string>();
+        }
+
+        public string Question { get; set; }
+        public List<CodeValue> Option { get; set; }
+        public List<string> Answer { get; set; }
+        public string Explain { get; set; }
+        public string Type { get; set; }
+
+    }
+}