黄贺彬 6 éve
szülő
commit
15f0fbb346

+ 11 - 12
HaBookCms.AzureStorage/Implements/AzureTableDBRepository.cs

@@ -1,30 +1,29 @@
-using Microsoft.Extensions.Options;
-using HaBookCms.AzureStorage.Options;
+using HaBookCms.AzureStorage.AzureTable.Interfaces;
+using HaBookCms.AzureStorage.Extensions;
+using Microsoft.Extensions.Options;
 using Microsoft.WindowsAzure.Storage;
 using Microsoft.WindowsAzure.Storage.Table;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Linq;
+using System.Text;
 using System.Threading.Tasks;
-using HaBookCms.AzureStorage.Interfaces;
-using HaBookCms.Jwt.Model;
 
-namespace HaBookCms.AzureStorage.Implements
+namespace HaBookCms.AzureStorage.AzureTable.Implements
 {
-    public class AzureTableDBRepository : IAzureTableDBRepository
+   public class AzureTableDBRepository : IAzureTableDBRepository
     {
-
         public string _connectionString { get; set; }
         public CloudTable table;
-        //public AzureTableDBRepository(IOptions<DatabaseOptions> optionsAccessor)
-        //{
-        //    _connectionString = optionsAccessor.Value.ConnectionString;
-        //}
+        public AzureTableDBRepository(IOptions<DatabaseOptions> optionsAccessor)
+        {
+            _connectionString = optionsAccessor.Value.ConnectionString;
+        }
 
         public AzureTableDBRepository()
         {
-            _connectionString = BaseConfigModel.Configuration["AppSettings:Azure:TableStorageConnection"];
+           // _connectionString = BaseConfigModel.Configuration["AppSettings:Azure:TableStorageConnection"];
 
         }
         private async Task InitializeTable<T>()

+ 3 - 2
HaBookCms.AzureStorage/Interfaces/IAzureTableDBRepository.cs

@@ -1,9 +1,10 @@
 using Microsoft.WindowsAzure.Storage.Table;
 using System.Collections.Generic;
 using System.Threading.Tasks;
-namespace HaBookCms.AzureStorage.Interfaces
+
+namespace HaBookCms.AzureStorage.AzureTable.Interfaces
 {
-    public interface IAzureTableDBRepository
+   public interface IAzureTableDBRepository
     {
         Task<List<T>> GetEntities<T>(IDictionary<string, object> dict) where T : TableEntity, new();
         Task<T> FindOneByDict<T>(IDictionary<string, object> dict) where T : TableEntity, new();

+ 28 - 0
HaBookCms.AzureStorage/Extensions/AzureStorageBuilder.cs

@@ -0,0 +1,28 @@
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace HaBookCms.AzureStorage.Extensions
+{
+    public class AzureStorageBuilder
+    {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="IdentityServerBuilder"/> class.
+        /// </summary>
+        /// <param name="services">The services.</param>
+        /// <exception cref="System.ArgumentNullException">services</exception>
+        public AzureStorageBuilder(IServiceCollection services)
+        {
+            Services = services ?? throw new ArgumentNullException(nameof(services));
+        }
+
+        /// <summary>
+        /// Gets the services.
+        /// </summary>
+        /// <value>
+        /// The services.
+        /// </value>
+        public IServiceCollection Services { get; }
+    }
+}

+ 25 - 0
HaBookCms.AzureStorage/Extensions/AzureStorageBuilderExtensions.cs

@@ -0,0 +1,25 @@
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace HaBookCms.AzureStorage.Extensions
+{
+    public static class AzureStorageBuilderExtensions
+    {
+
+        /// <summary>
+        /// Adds test users.
+        /// </summary>
+        /// <param name="builder">The builder.</param>
+        /// <param name="users">The users.</param>
+        /// <returns></returns>
+        public static AzureStorageBuilder AddConnection(this AzureStorageBuilder builder, string _connectionString)
+        {
+            DatabaseOptions databaseOptions = new DatabaseOptions();
+            databaseOptions.ConnectionString = _connectionString;
+            builder.Services.AddSingleton(databaseOptions);
+            return builder;
+        }
+    }
+}

+ 35 - 0
HaBookCms.AzureStorage/Extensions/AzureStorageServiceCollectionExtensions.cs

@@ -0,0 +1,35 @@
+using HaBookCms.AzureStorage.AzureTable.Implements;
+using HaBookCms.AzureStorage.AzureTable.Interfaces;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace HaBookCms.AzureStorage.Extensions
+{
+    public static class AzureStorageServiceCollectionExtensions
+    {
+
+        /// <summary>
+        /// Creates a builder.
+        /// </summary>
+        /// <param name="services">The services.</param>
+        /// <returns></returns>
+        private static AzureStorageBuilder AddAzureTableServerBuilder(this IServiceCollection services)
+        {
+            return new AzureStorageBuilder(services);
+        }
+
+        /// <summary>
+        /// Adds AddAzureTableStorage.
+        /// </summary>
+        /// <param name="services">The services.</param>
+        /// <returns></returns>
+        public static AzureStorageBuilder AddAzureTableStorage(this IServiceCollection services)
+        {
+            var builder = services.AddAzureTableServerBuilder();
+            services.AddSingleton<IAzureTableDBRepository, AzureTableDBRepository>();
+            return builder;
+        }
+    }
+}

+ 11 - 0
HaBookCms.AzureStorage/Extensions/DatabaseOptions.cs

@@ -0,0 +1,11 @@
+namespace HaBookCms.AzureStorage.Extensions
+{
+    public class  DatabaseOptions
+    {
+        public string ConnectionString { get; set; } = null;
+        public DatabaseOptions()
+        {
+            //Azure Table Init
+        }
+    }
+}

+ 5 - 0
HaBookCms.AzureStorage/HaBookCms.AzureStorage.csproj

@@ -13,4 +13,9 @@
     <ProjectReference Include="..\HaBookCms.Jwt\HaBookCms.Jwt.csproj" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Folder Include="AzureBlob\" />
+    <Folder Include="AzureQueue\" />
+  </ItemGroup>
+
 </Project>

+ 0 - 11
HaBookCms.AzureStorage/Options/DatabaseOptions.cs

@@ -1,11 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace HaBookCms.AzureStorage.Options
-{
-    public class DatabaseOptions
-    {
-        public string ConnectionString { get; set; } = null;
-    }
-}

+ 1 - 4
HaBookCms.Contest/Controllers/CmsUsersController.cs

@@ -1,4 +1,4 @@
-using HaBookCms.AzureStorage.Interfaces;
+using HaBookCms.AzureStorage.AzureTable.Interfaces;
 using HaBookCms.Common.Constants;
 using HaBookCms.Common.CryptHelper;
 using HaBookCms.Common.HttpHelper;
@@ -13,9 +13,6 @@ using Microsoft.AspNetCore.Cors;
 using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
 using System.Security.Claims;
 using System.Text;
 using System.Threading.Tasks;

+ 2 - 4
HaBookCms.Contest/Startup.cs

@@ -5,9 +5,7 @@ using System.Security.Claims;
 using System.Text;
 using System.Text.Encodings.Web;
 using System.Text.Unicode;
-using HaBookCms.AzureStorage.Implements;
-using HaBookCms.AzureStorage.Interfaces;
-using HaBookCms.AzureStorage.Options;
+using HaBookCms.AzureStorage.Extensions;
 using HaBookCms.Common.LogHelper;
 using HaBookCms.ContextConfig.Exceptions;
 using HaBookCms.Jwt.Filter;
@@ -54,7 +52,7 @@ namespace HaBookCms.Contest
         // This method gets called by the runtime. Use this method to add services to the container.
         public void ConfigureServices(IServiceCollection services)
         {
-            services.AddSingleton(typeof(IAzureTableDBRepository), typeof(AzureTableDBRepository));
+            services.AddAzureTableStorage().AddConnection(Configuration["AppSettings:Azure:TableStorageConnection"]);
             services.Configure<CookiePolicyOptions>(options =>
             {
                 // This lambda determines whether user consent for non-essential cookies is needed for a given request.

+ 1 - 0
HaBookCms.JosnRPCTest/HaBookCms.JosnRPCTest.csproj

@@ -9,6 +9,7 @@
     <ProjectReference Include="..\HaBookCms.Common\HaBookCms.Common.csproj" />
     <ProjectReference Include="..\HaBookCms.Core\HaBookCms.Core.csproj" />
     <ProjectReference Include="..\HaBookCms.IP2Region\HaBookCms.IP2Region.csproj" />
+    <ProjectReference Include="..\HaBookCms.Response\HaBookCms.Response.csproj" />
   </ItemGroup>
 
 </Project>

+ 13 - 5
HaBookCms.JosnRPCTest/Program.cs

@@ -3,6 +3,7 @@ using HaBookCms.Common.ValidateHelper;
 using HaBookCms.Core.Dtos;
 using HaBookCms.Core.Models.Common;
 using HaBookCms.IP2Region;
+using HaBookCms.Response;
 using IP2Region.Models;
 using MessagePack;
 using System;
@@ -17,19 +18,26 @@ namespace HaBookCms.JosnRPCTest
     {
         static void Main(string[] args)
         {
-            string rp = "{\"id\":1.0,\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32601,\"message\":\"No method found with the requested signature or multiple methods matched the request.\",\"data\":null}}";
-            JosnRPCResponse<TeamModelIdInfo> rs= MessagePackHelper.JsonToObject<JosnRPCResponse<TeamModelIdInfo>>(rp);
-            Task<DataBlock> dataBlock= DataIP2Region.IP2Region("110.185.29.187");
-            JosnRPCResponse<List<CmsUser>> response = new JosnRPCResponse<List<CmsUser>>();
             List<CmsUser> users = new List<CmsUser>();
             CmsUser user = new CmsUser();
             user.city = "123";
             users.Add(user);
+
+            ResponseBuilder responses = ResponseBuilder.custom();
+
+            responses.CurrPage(1).PageSize(23).totalCount(53).TotalPage(2).Data(users);
+            BaseResponse baseResponse= responses.build();
+           string s =  MessagePackHelper.ObjectToJson(baseResponse);
+            string rp = "{\"id\":1.0,\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32601,\"message\":\"No method found with the requested signature or multiple methods matched the request.\",\"data\":null}}";
+            JosnRPCResponse<TeamModelIdInfo> rs= MessagePackHelper.JsonToObject<JosnRPCResponse<TeamModelIdInfo>>(rp);
+            Task<DataBlock> dataBlock= DataIP2Region.IP2Region("110.185.29.187");
+            JosnRPCResponse<List<CmsUser>> response = new JosnRPCResponse<List<CmsUser>>();
+           
+           
             response.result= users;
             string json=  MessagePackHelper.ObjectToJson(response);
             response = MessagePackHelper.JsonToObject<JosnRPCResponse<List<CmsUser>>>(json);
             string jsons = MessagePackHelper.ObjectToJson(response);
-
             JosnRPCRequest<Dictionary<string, object>> request = new JosnRPCRequest<Dictionary<string, object>>();
             request.method = "method";
             Dictionary<string, object> ticket = new Dictionary<string, object>();

+ 0 - 8
HaBookCms.RedisStorage/Class1.cs

@@ -1,8 +0,0 @@
-using System;
-
-namespace HaBookCms.RedisStorage
-{
-    public class Class1
-    {
-    }
-}

+ 3 - 1
HaBookCms.Response/BaseResponse.cs

@@ -1,8 +1,10 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 
 namespace HaBookCms.Response
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class BaseResponse : TimeStampResponse
     {
         public Dictionary<String, Object> extend;

+ 3 - 1
HaBookCms.Response/DataResponse.cs

@@ -1,9 +1,11 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 
 namespace HaBookCms.Response
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class DataResponse<T> : BaseResponse
     {
         public T data;

+ 3 - 1
HaBookCms.Response/DatasResponse.cs

@@ -1,9 +1,11 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 
 namespace HaBookCms.Response
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class DatasResponse<T> : BaseResponse
     {
         public IList<T> datas;

+ 6 - 0
HaBookCms.Response/HaBookCms.Response.csproj

@@ -4,4 +4,10 @@
     <TargetFramework>netcoreapp2.2</TargetFramework>
   </PropertyGroup>
 
+  <ItemGroup>
+    <Reference Include="MessagePack">
+      <HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\messagepack\1.7.3.4\lib\netstandard2.0\MessagePack.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+
 </Project>

+ 3 - 1
HaBookCms.Response/PageDatasResponse.cs

@@ -1,9 +1,11 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 
 namespace HaBookCms.Response
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class PageDatasResponse<T> : DatasResponse<T>
     {
         public PageResponse page;

+ 3 - 1
HaBookCms.Response/PageResponse.cs

@@ -1,9 +1,11 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 
 namespace HaBookCms.Response
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class PageResponse
     {
         public long total;

+ 22 - 8
HaBookCms.Response/ResponseBuilder.cs

@@ -1,20 +1,23 @@
-using System;
+using MessagePack;
+using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Text;
 
 namespace HaBookCms.Response
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class ResponseBuilder
     {
-        private String message = "success";
-        private Object data;
+        private string message = "success";
+        private object data;
         private int code = 0;
-        private IList<Object> datas;
+        private IList<object> datas;
         private int total;
         private int currPage;
         private int pageSize;
         private int totalPage;
-        private Dictionary<String, Object> extend;
+        private Dictionary<string, object> extend;
 
         private ResponseBuilder()
         {
@@ -27,7 +30,8 @@ namespace HaBookCms.Response
 
         public BaseResponse build()
         {
-            if (this.total > 0 && this.pageSize > 0 && this.totalPage <= 0)
+            //if (this.total > 0 && this.pageSize > 0 && this.totalPage <= 0)
+            if (this.total > 0 && this.pageSize > 0 )
             {
                 this.totalPage = (int)Math.Ceiling((double)this.total / (double)this.pageSize);
             }
@@ -77,9 +81,19 @@ namespace HaBookCms.Response
             return this;
         }
 
-        public ResponseBuilder Data(Object data)
+        public ResponseBuilder Data(object data)
         {
-            this.data = data;
+            
+            if (data is IEnumerable && (data.GetType().IsGenericType || data is Array))
+            {
+                List<object> list = data as List<object>;
+               
+                 //   System.Collections.Generic.IList<Object> newAl = data as System.Collections.Generic.IList<Object>;
+                this.datas = list;
+            }
+            else {
+                this.data = data;
+            }
             return this;
         }
 

+ 4 - 2
HaBookCms.Response/TimeStampResponse.cs

@@ -1,12 +1,14 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 
 namespace HaBookCms.Response
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class TimeStampResponse
     {
-        public long responseTime = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
+        public long responseTime = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
         public TimeStampResponse()
         {
         }