Explorar el Código

项目初始化

yuxi-lee hace 3 años
commit
2908abd2f7

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/bin
+/obj
+/.vs

+ 82 - 0
Controllers/L1SvrController.cs

@@ -0,0 +1,82 @@
+using LJLib.Client;
+using LJLib.Net.SPI.Client;
+using LJProxy.Settings;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+
+namespace LJProxy.Controllers
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class L1SvrController : Controller
+    {
+        private static object _syncRoot = new object();
+        public static AppSettings _appSettingModel;
+        public L1SvrController(IOptions<AppSettings> appSettingModel)
+        {
+            if (_appSettingModel == null)
+            {
+                _appSettingModel = appSettingModel.Value;
+            }
+        }
+        private static ILJClient _PROPool { get; set; }
+        private static ILJClient PROPool
+        {
+            get
+            {
+                if (_PROPool == null)
+                {
+                    lock (_syncRoot)
+                    {
+                        var url = _appSettingModel.L1SvrPROUrl;
+                        var urlArr = url.Split(':');
+                        var ip = urlArr[0];
+                        var port = urlArr[1];
+                        var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port));
+                        _PROPool = new LJClientPool(creator, 1000);
+                    }
+                }
+                return _PROPool;
+            }
+        }
+        private static ILJClient _CRPPool { get; set; }
+        private static ILJClient CRPPool
+        {
+            get
+            {
+                if (_CRPPool == null)
+                {
+                    lock (_syncRoot)
+                    {
+                        var url = _appSettingModel.L1SvrCRPUrl;
+                        var urlArr = url.Split(':');
+                        var ip = urlArr[0];
+                        var port = urlArr[1];
+                        var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port));
+                        _CRPPool = new LJClientPool(creator, 20);
+                    }
+                }
+                return _CRPPool;
+            }
+        }
+        [Route("PRO/{apiName}")]
+        [HttpPost]
+        public string PRO(string apiName, [FromBody] object requestBody)
+        {
+            var rslt = PROPool.DoExcute(apiName, requestBody.ToString());
+            return rslt;
+        }
+        [Route("CRP/{apiName}")]
+        [HttpPost]
+        public string CRP(string apiName,[FromBody] object requestBody)
+        {
+            var rslt = CRPPool.DoExcute(apiName, requestBody.ToString());
+            return rslt;
+        }
+    }
+}

+ 138 - 0
LJLib.IP/IPUtils.cs

@@ -0,0 +1,138 @@
+using System;
+using System.Diagnostics;
+using System.Net;
+using System.Net.Sockets;
+using System.Text.RegularExpressions;
+
+namespace LJLib.IP
+{
+    public static class IPUtils
+    {
+        [Obsolete("建议改用方法GetURLIPv4")]
+        public static string GetURLIP(string URL)
+        {
+            string ip = string.Empty;
+            try
+            {
+                IPHostEntry ipHost = Dns.GetHostEntry(URL);
+                bool haveip = false;
+                for (int i = 0; i < ipHost.AddressList.Length; i++)
+                {
+                    if (!haveip)
+                    {
+                        var tip = ipHost.AddressList[i].ToString();
+                        if (tip != "::1")
+                        {
+                            ip = tip;
+                            haveip = true;
+                        }
+                    }
+                }
+            }
+            catch (System.Exception ex)
+            {
+                Debug.Write(string.Format("获取龙嘉网失败,URL:[{0}],{1}.", URL, ex.ToString()));
+                ip = "获取龙嘉网失败:" + URL;
+            }
+            return ip;
+        }
+
+        /// <summary>
+        /// 返回URL的IPv4的地址
+        /// </summary>
+        /// <param name="URL">URL地址</param>
+        /// <returns>IPv4</returns>
+        public static IPAddress GetURLIPv4(string URL)
+        {
+            IPAddress ip = null;
+            if (IsIPv4Address(URL))
+            {
+                return IPAddress.Parse(URL);
+            }
+            try
+            {
+                var ipHost = Dns.GetHostEntry(URL);
+                foreach (var ipAddress in ipHost.AddressList)
+                {
+                    if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
+                    {
+                        if (!IPAddress.IsLoopback(ipAddress))
+                        {
+                            return ipAddress;
+                        }
+
+                        ip = ipAddress;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                Debug.Write(string.Format("获取龙嘉网失败,URL:[{0}],{1}.", URL, ex.ToString()));
+            }
+            return ip;
+        }
+
+        public static IPEndPoint GetIPEndPoint(string ipPortStr)
+        {
+            int index = ipPortStr.IndexOf(":");
+            if (index < 0)
+            {
+                throw new Exception(string.Format("ip:port不合法,{0}", ipPortStr));
+            }
+            var ipStr = ipPortStr.Substring(0, index);
+            var portStr = ipPortStr.Substring(index + 1);
+            try
+            {
+                var address = IPAddress.Parse(ipStr);
+                var port = int.Parse(portStr);
+                return new IPEndPoint(address, port);
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(string.Format("ip:port不合法,{0},异常:{1}", ipPortStr, ex));
+            }
+        }
+
+        private static Regex r = null;
+
+        public static bool IsIPv4Address(string ip)
+        {
+            if (r == null)
+            {
+                r = new Regex(@"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$");
+            }
+            return r.IsMatch(ip);
+        }
+
+        /// <summary>
+        /// 判断TcpClient是否在连接
+        /// </summary>
+        public static bool IsConnecting(TcpClient tcpclient)
+        {
+            try
+            {
+                if (!tcpclient.Connected)
+                {
+                    return false;
+                }
+
+                var ifSelectRead = tcpclient.Client.Poll(1000, SelectMode.SelectRead);
+                if (!ifSelectRead) // 网络在连接无数据可读
+                {
+                    return true;
+                }
+
+                var ns = tcpclient.GetStream();
+                return ns.CanRead && ns.DataAvailable;
+            }
+            catch (Exception ex)
+            {
+                if (!(ex is ObjectDisposedException) && !(ex is InvalidOperationException))
+                {
+                    Trace.Write(ex.ToString());
+                }
+                return false;
+            }
+        }
+    }
+}

+ 13 - 0
LJLib.Net.SPI.Client/ILJClient.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace LJLib.Net.SPI.Client
+{
+    public interface ILJClient : IDisposable
+    {
+        string DoExcute(string apiName, string requestJSON);
+        void Beat();
+        void Dispose();
+    }
+}

+ 33 - 0
LJLib.TcpClient/DirectP1ClientCreator.cs

@@ -0,0 +1,33 @@
+using LJLib.Net.SPI.Client;
+using System;
+using System.Net;
+using System.Net.Sockets;
+using LJLib.IP;
+
+namespace LJLib.Client
+{
+    public sealed class DirectP1ClientCreator : LJClientCreator
+    {
+        private string _url;
+        private IPAddress _ip = null;
+        private int _port;
+
+        public DirectP1ClientCreator(String url, int port)
+        {
+            _url = url;
+            _port = port;
+        }
+
+        public override ILJClient newClient()
+        {
+            if (_ip == null)
+            {
+                _ip = IPUtils.GetURLIPv4(_url);
+            }
+
+            var tcpClient = new TcpClient();
+            tcpClient.Connect(_ip, _port);
+            return new P1Client(tcpClient.GetStream());
+        }
+    }
+}

+ 9 - 0
LJLib.TcpClient/LJClientCreator.cs

@@ -0,0 +1,9 @@
+using LJLib.Net.SPI.Client;
+
+namespace LJLib.Client
+{
+    public abstract class LJClientCreator
+    {
+        public abstract ILJClient newClient();
+    }
+}

+ 140 - 0
LJLib.TcpClient/LJClientPool.cs

@@ -0,0 +1,140 @@
+using LJLib.Net.SPI.Client;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Threading;
+
+namespace LJLib.Client
+{
+    public sealed class LJClientPool : ILJClient
+    {
+        private const int DEFAULT_RETRY_COUNT = 1;
+
+        private LJClientCreator _creator;
+        private ILJClient[] _clients;
+        private bool[] _client_states;
+        private object _syncRoot = new object();
+
+        public LJClientPool(LJClientCreator creator, int size)
+        {
+            _creator = creator;
+            _clients = new ILJClient[size];
+            _client_states = new bool[size];
+            for (int i = 0; i < size; i++)
+            {
+                _clients[i] = null;
+                _client_states[i] = false;
+            }
+        }
+        public string DoExcute(string apiName, string requestJSON)
+        {
+            int i;
+            do
+            {
+                lock (_syncRoot)
+                {
+                    for (i = 0; i < _client_states.Length; i++)
+                    {
+                        if (!_client_states[i])
+                        {
+                            _client_states[i] = true;
+                            break;
+                        }
+                    }
+                }
+                if (i >= _client_states.Length)
+                {
+                    Thread.Sleep(100);
+                }
+            } while (i >= _client_states.Length);
+
+            try
+            {
+                int retry = 0;
+                string rslt = null;
+                while (retry <= DEFAULT_RETRY_COUNT)
+                {
+                    try
+                    {
+                        if (_clients[i] == null)
+                        {
+                            _clients[i] = _creator.newClient();
+                        }
+                        rslt = _clients[i].DoExcute(apiName, requestJSON);
+                        break;
+                    }
+                    catch (Exception e)
+                    {
+                        Trace.Write(e.ToString());
+                        if (_clients[i] != null)
+                        {
+                            _clients[i].Dispose();
+                            _clients[i] = null;
+                        }
+                        ++retry;
+                        if (retry > DEFAULT_RETRY_COUNT)
+                        {
+                            throw e;//大于重试次数时异常重抛
+                        }
+                    }
+                }
+                return rslt;
+            }
+            catch (Exception ex)
+            {
+                Trace.Write(ex.ToString());
+                return ex.ToString();
+            }
+            finally
+            {
+                _client_states[i] = false;
+            }
+        }
+
+        public void Beat()
+        {
+            for (int i = 0; i < _client_states.Length; i++)
+            {
+                lock (_syncRoot)
+                {
+                    if (_client_states[i])
+                    {
+                        continue;
+                    }
+                    _client_states[i] = true;
+                }
+                try
+                {
+                    //空实例无须心跳
+                    if (_clients[i] != null)
+                    {
+                        _clients[i].Beat();
+                    }
+                }
+                catch (Exception e)
+                {
+                    _clients[i].Dispose();
+                    _clients[i] = null;
+                    Trace.Write("连接池请求异常" + e.ToString());
+                }
+                finally
+                {
+                    _client_states[i] = false;
+                }
+            }
+        }
+
+        public void Dispose()
+        {
+            for (int i = 0; i < _clients.Length; i++)
+            {
+                if (_clients[i] != null)
+                {
+                    _clients[i].Dispose();
+                    _clients[i] = null;
+                }
+            }
+        }
+
+    }
+}

+ 264 - 0
LJLib.TcpClient/P1Client.cs

@@ -0,0 +1,264 @@
+using LJLib.Net.SPI.Client;
+using LJLib.Tools.Helper;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.IO.Compression;
+using System.Text;
+using System.Threading;
+
+namespace LJLib.Client
+{
+    public sealed class P1Client : ILJClient
+    {
+        private const byte NEW_ALLGZIP = 0x10;
+        private const byte SVRBEAT = 0x08;
+        private const byte PROTOCOL_FLAG = 0x04;
+        private const byte READ_GZIP = 0x02;
+        private const byte WRITE_GZIP = 0x01;
+
+        private Stream _stream = null;
+
+        private object syncRoot = new object();
+
+        public P1Client(Stream stream)
+        {
+            _stream = stream;
+        }
+
+        public string DoExcute(string apiName, string requestJSON)
+        {
+            lock (syncRoot)
+            {
+                var apiname = apiName;
+
+                var firstByte = new[]
+                {
+                    (byte)(SVRBEAT | PROTOCOL_FLAG | READ_GZIP | WRITE_GZIP | NEW_ALLGZIP),
+                    (byte)(SVRBEAT | PROTOCOL_FLAG | READ_GZIP | WRITE_GZIP),
+                    (byte)(SVRBEAT | PROTOCOL_FLAG),
+                };
+
+                var headByte = firstByte[0];
+                if (headByte > 0x1F || (headByte & PROTOCOL_FLAG) != PROTOCOL_FLAG)
+                {
+                    throw new Exception("不支持协议" + headByte.ToString("X2"));
+                }
+
+                if ((headByte & NEW_ALLGZIP) == NEW_ALLGZIP)
+                {
+                    if ((headByte & READ_GZIP) != READ_GZIP)
+                    {
+                        throw new Exception("协议异常:新协议必须压缩发送");
+                    }
+                    if ((headByte & WRITE_GZIP) != WRITE_GZIP)
+                    {
+                        throw new Exception("协议异常:新协议必须压缩返回");
+                    }
+                }
+
+
+                if (!_stream.CanWrite)
+                {
+                    throw new Exception(string.Format("远端服务已中断(不能写)"));
+                }
+
+                _stream.Write(firstByte, 0, 1);
+
+                var ostream = _stream;
+
+                if ((headByte & READ_GZIP) == READ_GZIP)
+                {
+                    ostream = new MemoryStream();
+                }
+
+                string str = apiname + requestJSON;
+
+                WriteStringAndFiles(ostream, str, null, null);
+
+                if ((headByte & READ_GZIP) == READ_GZIP)
+                {
+                    using (ostream)
+                    using (var gzipms = new MemoryStream())
+                    using (var gzip = new GZipStream(gzipms, CompressionMode.Compress, true))
+                    {
+                        ostream.Seek(0, SeekOrigin.Begin);
+                        StreamHelper.StreamCopy(gzip, ostream);
+                        gzip.Close();
+
+                        if ((headByte & NEW_ALLGZIP) == NEW_ALLGZIP)
+                        {
+                            var filelen = BitConverter.GetBytes((int)gzipms.Length);
+                            _stream.Write(filelen, 0, filelen.Length);
+                        }
+
+                        gzipms.Seek(0, SeekOrigin.Begin);
+                        StreamHelper.StreamCopy(_stream, gzipms);
+                    }
+                }
+
+                if (!_stream.CanRead)
+                {
+                    throw new Exception(string.Format("远端服务已中断(不能读)"));
+                }
+                if ((headByte & SVRBEAT) == SVRBEAT)
+                {
+                    var oldTimeout = _stream.ReadTimeout;
+                    _stream.ReadTimeout = 10000;
+                    var hasRslt = _stream.ReadByte();
+                    while (hasRslt == 0)
+                    {
+                        Thread.Sleep(100);
+                        if (!_stream.CanRead)
+                        {
+                            throw new Exception(string.Format("远端服务已中断(不能读)"));
+                        }
+                        hasRslt = _stream.ReadByte();
+                        if (hasRslt == -1)
+                        {
+                            throw new Exception(string.Format("远端服务已中断(不能读)"));
+                        }
+                    }
+                    _stream.ReadTimeout = oldTimeout;
+                }
+
+                Debug.Write("WaitServer End");
+
+                var istream = _stream;
+
+                MemoryStream ms = null;
+                GZipStream gzipstream = null;
+
+                if ((headByte & WRITE_GZIP) == WRITE_GZIP)
+                {
+                    if ((headByte & NEW_ALLGZIP) == NEW_ALLGZIP)
+                    {
+                        ms = new MemoryStream();
+                        var allen = new byte[4];
+                        _stream.Read(allen, 0, allen.Length);
+                        var alen = BitConverter.ToInt32(allen, 0);
+
+                        StreamHelper.StreamCopy(ms, _stream, alen);
+
+                        Debug.Write("ReadResponseFromNet End");
+                        ms.Seek(0, SeekOrigin.Begin);
+                        gzipstream = new GZipStream(ms, CompressionMode.Decompress, false);
+                        istream = gzipstream;
+                    }
+                    else
+                    {
+                        gzipstream = new GZipStream(_stream, CompressionMode.Decompress, true);
+                        istream = gzipstream;
+                    }
+                }
+
+                byte[] bytes;
+                Dictionary<string, byte[]> rfiles = new Dictionary<string, byte[]>();
+                using (ms)
+                using (gzipstream)
+                {
+                    var reader = new BinaryReader(istream);
+                    var len = reader.ReadInt32();
+                    bytes = reader.ReadBytes(len);
+
+                    var filecnt = reader.ReadByte();
+                    for (int i = 0; i < filecnt; i++)
+                    {
+                        var namelen = reader.ReadInt32();
+                        var namebytes = reader.ReadBytes(namelen);
+                        var datalen = reader.ReadInt32();
+                        var databytes = reader.ReadBytes(datalen);
+                        rfiles.Add(Encoding.UTF8.GetString(namebytes), databytes);
+                    }
+                    Debug.Write("ReadResponse End");
+                }
+
+                var strrsp = Encoding.UTF8.GetString(bytes);
+                return strrsp;
+            }
+        }
+
+        private static void WriteStringAndFiles(Stream ostream, string str, IDictionary<string, string> files, Dictionary<string, byte[]> exfiles)
+        {
+            var strbytes = Encoding.UTF8.GetBytes(str);
+            var lenbytes = BitConverter.GetBytes(strbytes.Length);
+            ostream.Write(lenbytes, 0, lenbytes.Length);
+            ostream.Write(strbytes, 0, strbytes.Length);
+            ostream.Flush();
+
+            if (files == null)
+            {
+                files = new Dictionary<string, string>();
+            }
+
+            if (exfiles == null)
+            {
+                exfiles = new Dictionary<string, byte[]>();
+            }
+
+            var shortbytes = BitConverter.GetBytes((short)(files.Count + exfiles.Count));
+            ostream.Write(shortbytes, 0, shortbytes.Length);
+
+            foreach (var file in files)
+            {
+                var namebytes = Encoding.UTF8.GetBytes(file.Key);
+                var namelen = BitConverter.GetBytes(namebytes.Length);
+                ostream.Write(namelen, 0, namelen.Length);
+                ostream.Write(namebytes, 0, namebytes.Length);
+                ostream.Flush();
+
+                using (var fs = File.OpenRead(file.Value))
+                {
+                    var filelen = BitConverter.GetBytes((int)fs.Length);
+                    ostream.Write(filelen, 0, filelen.Length);
+                    byte[] buff = new byte[10240];
+                    int read = 0;
+                    while ((read = fs.Read(buff, 0, buff.Length)) > 0)
+                    {
+                        ostream.Write(buff, 0, read);
+                        ostream.Flush();
+                    }
+                }
+            }
+
+            foreach (var file in exfiles)
+            {
+                var namebytes = Encoding.UTF8.GetBytes(file.Key);
+                var namelen = BitConverter.GetBytes(namebytes.Length);
+                ostream.Write(namelen, 0, namelen.Length);
+                ostream.Write(namebytes, 0, namebytes.Length);
+                ostream.Flush();
+                var filelen = BitConverter.GetBytes((int)file.Value.Length);
+                ostream.Write(filelen, 0, filelen.Length);
+
+                using (var ms = new MemoryStream(file.Value))
+                {
+                    byte[] buff = new byte[10240];
+                    int read = 0;
+                    while ((read = ms.Read(buff, 0, buff.Length)) > 0)
+                    {
+                        ostream.Write(buff, 0, read);
+                        ostream.Flush();
+                    }
+                }
+                ostream.Flush();
+            }
+
+            ostream.Flush();
+        }
+
+        public void Beat()
+        {
+            lock (syncRoot)
+            {
+                _stream.WriteByte(0x00);
+            }
+        }
+
+        public void Dispose()
+        {
+            _stream.Dispose();
+        }
+    }
+}

+ 16 - 0
LJProxy.csproj

@@ -0,0 +1,16 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp3.1</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <None Include="LJProxy.sln" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.18" />
+  </ItemGroup>
+
+
+</Project>

+ 9 - 0
LJProxy.csproj.user

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
+    <Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
+    <ShowAllFiles>true</ShowAllFiles>
+    <NameOfLastUsedPublishProfile>D:\ImportantData\Develop\ProjectCode\LJProxy\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
+  </PropertyGroup>
+</Project>

+ 25 - 0
LJProxy.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.31424.327
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LJProxy", "LJProxy.csproj", "{4B29784A-E029-4796-94B8-9C1EA47813D9}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{4B29784A-E029-4796-94B8-9C1EA47813D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4B29784A-E029-4796-94B8-9C1EA47813D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4B29784A-E029-4796-94B8-9C1EA47813D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4B29784A-E029-4796-94B8-9C1EA47813D9}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {E61F7846-99DE-4F18-A547-3F1C32D692B2}
+	EndGlobalSection
+EndGlobal

+ 26 - 0
Program.cs

@@ -0,0 +1,26 @@
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace LJProxy
+{
+    public class Program
+    {
+        public static void Main(string[] args)
+        {
+            CreateHostBuilder(args).Build().Run();
+        }
+
+        public static IHostBuilder CreateHostBuilder(string[] args) =>
+            Host.CreateDefaultBuilder(args)
+                .ConfigureWebHostDefaults(webBuilder =>
+                {
+                    webBuilder.UseStartup<Startup>();
+                });
+    }
+}

+ 16 - 0
Properties/PublishProfiles/FolderProfile.pubxml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <DeleteExistingFiles>False</DeleteExistingFiles>
+    <ExcludeApp_Data>False</ExcludeApp_Data>
+    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
+    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
+    <LastUsedPlatform>Any CPU</LastUsedPlatform>
+    <PublishProvider>FileSystem</PublishProvider>
+    <PublishUrl>bin\Release\netcoreapp3.1\publish\</PublishUrl>
+    <WebPublishMethod>FileSystem</WebPublishMethod>
+  </PropertyGroup>
+</Project>

+ 10 - 0
Properties/PublishProfiles/FolderProfile.pubxml.user

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <_PublishTargetUrl>D:\ImportantData\Develop\ProjectCode\LJProxy\bin\Release\netcoreapp3.1\publish\</_PublishTargetUrl>
+    <History>True|2021-08-16T06:51:54.8412175Z;True|2021-08-16T11:30:00.7278175+08:00;</History>
+  </PropertyGroup>
+</Project>

+ 28 - 0
Properties/launchSettings.json

@@ -0,0 +1,28 @@
+{
+  "iisSettings": {
+    "windowsAuthentication": false,
+    "anonymousAuthentication": true,
+    "iisExpress": {
+      "applicationUrl": "http://127.0.0.1:58966",
+      "sslPort": 0
+    }
+  },
+  "$schema": "http://json.schemastore.org/launchsettings.json",
+  "profiles": {
+    "IIS Express": {
+      "commandName": "IISExpress",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "LJProxy": {
+      "commandName": "Project",
+      "launchBrowser": true,
+      "launchUrl": "weatherforecast",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      },
+      "applicationUrl": "https://localhost:5001;http://localhost:5000"
+    }
+  }
+}

+ 13 - 0
Settings/AppSettings.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace LJProxy.Settings
+{
+    public class AppSettings
+    {
+        public string L1SvrCRPUrl { get; set; }
+        public string L1SvrPROUrl { get; set; }
+    }
+}

+ 53 - 0
Startup.cs

@@ -0,0 +1,53 @@
+using LJProxy.Settings;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.HttpsPolicy;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace LJProxy
+{
+    public class Startup
+    {
+        public Startup(IConfiguration configuration)
+        {
+            Configuration = configuration;
+        }
+
+        public IConfiguration Configuration { get; }
+
+        // This method gets called by the runtime. Use this method to add services to the container.
+        public void ConfigureServices(IServiceCollection services)
+        {
+            services.AddControllers().AddNewtonsoftJson();
+            services.Configure<AppSettings>(Configuration.GetSection("Appsettings"));
+        }
+
+        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+        {
+            if (env.IsDevelopment())
+            {
+                app.UseDeveloperExceptionPage();
+            }
+
+            app.UseHttpsRedirection();
+
+            app.UseRouting();
+
+            app.UseAuthorization();
+
+            app.UseEndpoints(endpoints =>
+            {
+                endpoints.MapControllers();
+            });
+        }
+    }
+}

+ 43 - 0
StreamHelper/StreamHelper.cs

@@ -0,0 +1,43 @@
+using System;
+using System.IO;
+using System.Threading;
+
+namespace LJLib.Tools.Helper
+{
+    public class StreamHelper
+    {
+        public static void StreamCopy(Stream dest, Stream source, int len)
+        {
+            byte[] buff = new byte[10240];
+            int total = 0;
+            while (total < len)
+            {
+                var read = source.Read(buff, 0, Math.Min(buff.Length, len - total));
+                if (read > 0)
+                {
+                    dest.Write(buff, 0, read);
+                    dest.Flush();
+                    total += read;
+                }
+                else
+                {
+                    Thread.Sleep(100);
+                }
+            }
+        }
+
+        public static void StreamCopy(Stream dest, Stream source)
+        {
+            byte[] buff = new byte[10240];
+            int read = 0;
+            int total = 0;
+            while ((read = source.Read(buff, 0, buff.Length)) > 0)
+            {
+                dest.Write(buff, 0, read);
+                dest.Flush();
+                total += read;
+            }
+        }
+
+    }
+}

+ 9 - 0
appsettings.Development.json

@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft": "Warning",
+      "Microsoft.Hosting.Lifetime": "Information"
+    }
+  }
+}

+ 14 - 0
appsettings.json

@@ -0,0 +1,14 @@
+{
+  "Appsettings": {
+    "L1SvrCRPUrl": "127.0.0.1:30032",
+    "L1SvrPROUrl": "192.168.0.93:30032"
+  },
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft": "Warning",
+      "Microsoft.Hosting.Lifetime": "Information"
+    }
+  },
+  "AllowedHosts": "*"
+}