提交 32fbd2f8 编写于 作者: 若汝棋茗's avatar 若汝棋茗

TouchSocket初始版本

上级 0f4c0848

要显示的变更太多。

To preserve performance only 1000 of 1000+ files are displayed.

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32428.217
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{06A5E4BC-4AE9-4F5F-BF8E-C6651413442B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RRQMSocket", "src\RRQMSocket\RRQMSocket.csproj", "{35F750B3-E4FE-4393-80BD-DA7CF2A584A3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RRQMCore", "src\RRQMCore\RRQMCore.csproj", "{B2ECE80C-5473-4774-A729-4360B60EDB73}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{517CF381-4C15-4519-9BC4-92DC4C412C8D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceApp", "examples\ServiceApp\ServiceApp.csproj", "{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientApp", "examples\ClientApp\ClientApp.csproj", "{0B7591F5-37C8-4570-ACEF-782CE3F12957}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tcp简单示例", "Tcp简单示例", "{FB46E926-0EEC-488C-B950-A16D2E7F694B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{5F888345-EC9C-4AC3-B4D5-D9510A32C9DC}"
ProjectSection(SolutionItems) = preProject
源码编译相关问题.txt = 源码编译相关问题.txt
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Udp简单示例", "Udp简单示例", "{F4D798A3-8D65-4750-9552-B02BCE081508}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdpDemoApp", "examples\UdpDemoApp\UdpDemoApp.csproj", "{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "适配器示例", "适配器示例", "{F8C07F29-7233-4FD3-A3DC-45963071E20A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdapterConsoleApp", "examples\AdapterConsoleApp\AdapterConsoleApp.csproj", "{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "插件示例", "插件示例", "{397AE2E0-1FB6-4B71-A888-328FF7FA05B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginConsoleApp", "examples\PluginConsoleApp\PluginConsoleApp.csproj", "{2DA72D0E-DAAC-4272-A10E-1EF89439636B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Consul集群示例", "Consul集群示例", "{B405B0AE-6ECD-4586-B3D6-9D875073DFAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsulConsoleApp", "examples\ConsulConsoleApp\ConsulConsoleApp.csproj", "{657BDC94-A1A5-44B3-8FA1-41531C6F7321}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NATService示例", "NATService示例", "{825D21FC-245C-4B6B-B237-E4ADEB2C98DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NATServiceConsoleApp", "examples\NATServiceConsoleApp\NATServiceConsoleApp.csproj", "{84206421-460C-4743-BA10-A749436AB4DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{35F750B3-E4FE-4393-80BD-DA7CF2A584A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35F750B3-E4FE-4393-80BD-DA7CF2A584A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35F750B3-E4FE-4393-80BD-DA7CF2A584A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35F750B3-E4FE-4393-80BD-DA7CF2A584A3}.Release|Any CPU.Build.0 = Release|Any CPU
{B2ECE80C-5473-4774-A729-4360B60EDB73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2ECE80C-5473-4774-A729-4360B60EDB73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2ECE80C-5473-4774-A729-4360B60EDB73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2ECE80C-5473-4774-A729-4360B60EDB73}.Release|Any CPU.Build.0 = Release|Any CPU
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Release|Any CPU.Build.0 = Release|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Release|Any CPU.Build.0 = Release|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Release|Any CPU.Build.0 = Release|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Release|Any CPU.Build.0 = Release|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Release|Any CPU.Build.0 = Release|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Debug|Any CPU.Build.0 = Debug|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Release|Any CPU.ActiveCfg = Release|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Release|Any CPU.Build.0 = Release|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{35F750B3-E4FE-4393-80BD-DA7CF2A584A3} = {06A5E4BC-4AE9-4F5F-BF8E-C6651413442B}
{B2ECE80C-5473-4774-A729-4360B60EDB73} = {06A5E4BC-4AE9-4F5F-BF8E-C6651413442B}
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E} = {FB46E926-0EEC-488C-B950-A16D2E7F694B}
{0B7591F5-37C8-4570-ACEF-782CE3F12957} = {FB46E926-0EEC-488C-B950-A16D2E7F694B}
{FB46E926-0EEC-488C-B950-A16D2E7F694B} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{F4D798A3-8D65-4750-9552-B02BCE081508} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA} = {F4D798A3-8D65-4750-9552-B02BCE081508}
{F8C07F29-7233-4FD3-A3DC-45963071E20A} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68} = {F8C07F29-7233-4FD3-A3DC-45963071E20A}
{397AE2E0-1FB6-4B71-A888-328FF7FA05B4} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{2DA72D0E-DAAC-4272-A10E-1EF89439636B} = {397AE2E0-1FB6-4B71-A888-328FF7FA05B4}
{B405B0AE-6ECD-4586-B3D6-9D875073DFAF} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{657BDC94-A1A5-44B3-8FA1-41531C6F7321} = {B405B0AE-6ECD-4586-B3D6-9D875073DFAF}
{825D21FC-245C-4B6B-B237-E4ADEB2C98DC} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{84206421-460C-4743-BA10-A749436AB4DE} = {825D21FC-245C-4B6B-B237-E4ADEB2C98DC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB787235-A13A-4A3D-B5A8-5DFEB6511EEE}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32428.217
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{06A5E4BC-4AE9-4F5F-BF8E-C6651413442B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{517CF381-4C15-4519-9BC4-92DC4C412C8D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceApp", "examples\ServiceApp\ServiceApp.csproj", "{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientApp", "examples\ClientApp\ClientApp.csproj", "{0B7591F5-37C8-4570-ACEF-782CE3F12957}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tcp简单示例", "Tcp简单示例", "{FB46E926-0EEC-488C-B950-A16D2E7F694B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{5F888345-EC9C-4AC3-B4D5-D9510A32C9DC}"
ProjectSection(SolutionItems) = preProject
源码编译相关问题.txt = 源码编译相关问题.txt
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Udp简单示例", "Udp简单示例", "{F4D798A3-8D65-4750-9552-B02BCE081508}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdpDemoApp", "examples\UdpDemoApp\UdpDemoApp.csproj", "{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "适配器示例", "适配器示例", "{F8C07F29-7233-4FD3-A3DC-45963071E20A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdapterConsoleApp", "examples\AdapterConsoleApp\AdapterConsoleApp.csproj", "{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "插件示例", "插件示例", "{397AE2E0-1FB6-4B71-A888-328FF7FA05B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginConsoleApp", "examples\PluginConsoleApp\PluginConsoleApp.csproj", "{2DA72D0E-DAAC-4272-A10E-1EF89439636B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Consul集群示例", "Consul集群示例", "{B405B0AE-6ECD-4586-B3D6-9D875073DFAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsulConsoleApp", "examples\ConsulConsoleApp\ConsulConsoleApp.csproj", "{657BDC94-A1A5-44B3-8FA1-41531C6F7321}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NATService示例", "NATService示例", "{825D21FC-245C-4B6B-B237-E4ADEB2C98DC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NATServiceConsoleApp", "examples\NATServiceConsoleApp\NATServiceConsoleApp.csproj", "{84206421-460C-4743-BA10-A749436AB4DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TouchSocket", "src\TouchSocket\TouchSocket.csproj", "{37BF3CB2-9003-465D-A936-7373301FDA5C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TouchSocket.AspNetCore", "src\TouchSocket.AspNetCore\TouchSocket.AspNetCore.csproj", "{6E00016F-41A4-40BC-AF9C-DA3B0FA4F81A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E}.Release|Any CPU.Build.0 = Release|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B7591F5-37C8-4570-ACEF-782CE3F12957}.Release|Any CPU.Build.0 = Release|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA}.Release|Any CPU.Build.0 = Release|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68}.Release|Any CPU.Build.0 = Release|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2DA72D0E-DAAC-4272-A10E-1EF89439636B}.Release|Any CPU.Build.0 = Release|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Debug|Any CPU.Build.0 = Debug|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Release|Any CPU.ActiveCfg = Release|Any CPU
{657BDC94-A1A5-44B3-8FA1-41531C6F7321}.Release|Any CPU.Build.0 = Release|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84206421-460C-4743-BA10-A749436AB4DE}.Release|Any CPU.Build.0 = Release|Any CPU
{37BF3CB2-9003-465D-A936-7373301FDA5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37BF3CB2-9003-465D-A936-7373301FDA5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37BF3CB2-9003-465D-A936-7373301FDA5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37BF3CB2-9003-465D-A936-7373301FDA5C}.Release|Any CPU.Build.0 = Release|Any CPU
{6E00016F-41A4-40BC-AF9C-DA3B0FA4F81A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E00016F-41A4-40BC-AF9C-DA3B0FA4F81A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E00016F-41A4-40BC-AF9C-DA3B0FA4F81A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E00016F-41A4-40BC-AF9C-DA3B0FA4F81A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6BEF15C2-29A2-4E57-8879-1B4AD0B4935E} = {FB46E926-0EEC-488C-B950-A16D2E7F694B}
{0B7591F5-37C8-4570-ACEF-782CE3F12957} = {FB46E926-0EEC-488C-B950-A16D2E7F694B}
{FB46E926-0EEC-488C-B950-A16D2E7F694B} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{F4D798A3-8D65-4750-9552-B02BCE081508} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{1C5F10E8-9F7E-495F-BFB3-DE9ED12480CA} = {F4D798A3-8D65-4750-9552-B02BCE081508}
{F8C07F29-7233-4FD3-A3DC-45963071E20A} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{EA91FC37-341E-43C5-B5ED-AA2E363F0C68} = {F8C07F29-7233-4FD3-A3DC-45963071E20A}
{397AE2E0-1FB6-4B71-A888-328FF7FA05B4} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{2DA72D0E-DAAC-4272-A10E-1EF89439636B} = {397AE2E0-1FB6-4B71-A888-328FF7FA05B4}
{B405B0AE-6ECD-4586-B3D6-9D875073DFAF} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{657BDC94-A1A5-44B3-8FA1-41531C6F7321} = {B405B0AE-6ECD-4586-B3D6-9D875073DFAF}
{825D21FC-245C-4B6B-B237-E4ADEB2C98DC} = {517CF381-4C15-4519-9BC4-92DC4C412C8D}
{84206421-460C-4743-BA10-A749436AB4DE} = {825D21FC-245C-4B6B-B237-E4ADEB2C98DC}
{37BF3CB2-9003-465D-A936-7373301FDA5C} = {06A5E4BC-4AE9-4F5F-BF8E-C6651413442B}
{6E00016F-41A4-40BC-AF9C-DA3B0FA4F81A} = {06A5E4BC-4AE9-4F5F-BF8E-C6651413442B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB787235-A13A-4A3D-B5A8-5DFEB6511EEE}
EndGlobalSection
EndGlobal
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license procotol you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Text;
using System.Threading;
namespace RRQMCore.ByteManager
{
/// <summary>
/// 字节块流
/// </summary>
[System.Diagnostics.DebuggerDisplay("Len={Len}")]
public sealed class ByteBlock : Stream, IByteBlock
{
internal long m_length;
internal bool m_using;
private static float m_ratio = 1.5f;
private byte[] m_buffer;
private bool m_holding;
private bool m_needDis;
private long m_position;
private int dis = 1;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="byteSize"></param>
/// <param name="equalSize"></param>
public ByteBlock(int byteSize = 1024 * 64, bool equalSize = false)
{
this.m_needDis = true;
this.m_buffer = BytePool.GetByteCore(byteSize, equalSize);
this.m_using = true;
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="bytes"></param>
public ByteBlock(byte[] bytes)
{
this.m_buffer = bytes ?? throw new ArgumentNullException(nameof(bytes));
this.m_length = bytes.Length;
this.m_using = true;
}
/// <summary>
/// 扩容增长比,默认为1.5,
/// min:1.5
/// </summary>
public static float Ratio
{
get => m_ratio;
set
{
if (value < 1.5)
{
value = 1.5f;
}
m_ratio = value;
}
}
/// <summary>
/// 空闲长度,准确掌握该值,可以避免内存扩展,计算为<see cref="Capacity"/>与<see cref="Pos"/>的差值。
/// </summary>
public int FreeLength => this.Capacity - this.Pos;
/// <summary>
/// 字节实例
/// </summary>
public byte[] Buffer => this.m_buffer;
/// <summary>
/// 仅当内存块可用,且<see cref="CanReadLen"/>>0时为True。
/// </summary>
public override bool CanRead => this.m_using && this.CanReadLen > 0;
/// <summary>
/// 还能读取的长度,计算为<see cref="Len"/>与<see cref="Pos"/>的差值。
/// </summary>
public int CanReadLen => this.Len - this.Pos;
/// <summary>
/// 还能读取的长度,计算为<see cref="Len"/>与<see cref="Pos"/>的差值。
/// </summary>
public long CanReadLength => this.m_length - this.m_position;
/// <summary>
/// 支持查找
/// </summary>
public override bool CanSeek => this.m_using;
/// <summary>
/// 可写入
/// </summary>
public override bool CanWrite => this.m_using;
/// <summary>
/// 容量
/// </summary>
public int Capacity => this.m_buffer.Length;
/// <summary>
/// 表示持续性持有,为True时,Dispose将调用无效。
/// </summary>
public bool Holding => this.m_holding;
/// <summary>
/// Int真实长度
/// </summary>
public int Len => (int)this.m_length;
/// <summary>
/// 真实长度
/// </summary>
public override long Length => this.m_length;
/// <summary>
/// int型流位置
/// </summary>
public int Pos
{
get => (int)this.m_position;
set => this.m_position = value;
}
/// <summary>
/// 流位置
/// </summary>
public override long Position
{
get => this.m_position;
set => this.m_position = value;
}
/// <summary>
/// 使用状态
/// </summary>
public bool Using => this.m_using;
/// <summary>
/// 直接完全释放,游离该对象,然后等待GC
/// </summary>
public void AbsoluteDispose()
{
if (Interlocked.Decrement(ref this.dis) == 0)
{
this.Dis();
}
}
private void Dis()
{
this.m_holding = false;
this.m_using = false;
this.m_position = 0;
this.m_length = 0;
this.m_buffer = null;
}
/// <summary>
/// 清空所有内存数据
/// </summary>
/// <exception cref="ObjectDisposedException">内存块已释放</exception>
public void Clear()
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
Array.Clear(this.m_buffer, 0, this.m_buffer.Length);
}
/// <summary>
/// 无实际效果
/// </summary>
public override void Flush()
{
}
/// <summary>
/// 读取数据,然后递增Pos
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="ObjectDisposedException"></exception>
public override int Read(byte[] buffer, int offset, int length)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
int len = this.m_length - this.m_position > length ? length : this.CanReadLen;
Array.Copy(this.m_buffer, this.m_position, buffer, offset, len);
this.m_position += len;
return len;
}
/// <summary>
/// 从当前流位置读取一个<see cref="byte"/>值
/// </summary>
public override int ReadByte()
{
byte value = this.m_buffer[this.m_position];
this.m_position++;
return value;
}
/// <summary>
/// 将内存块初始化到刚申请的状态。
/// <para>仅仅重置<see cref="Position"/>和<see cref="Length"/>属性。</para>
/// </summary>
/// <exception cref="ObjectDisposedException">内存块已释放</exception>
public void Reset()
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
this.m_position = 0;
this.m_length = 0;
}
/// <summary>
/// 设置流位置
/// </summary>
/// <param name="offset"></param>
/// <param name="origin"></param>
/// <returns></returns>
/// <exception cref="ObjectDisposedException"></exception>
public override long Seek(long offset, SeekOrigin origin)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
switch (origin)
{
case SeekOrigin.Begin:
this.m_position = offset;
break;
case SeekOrigin.Current:
this.m_position += offset;
break;
case SeekOrigin.End:
this.m_position = this.m_length + offset;
break;
}
return this.m_position;
}
/// <summary>
/// 重新设置容量
/// </summary>
/// <param name="size">新尺寸</param>
/// <param name="retainedData">是否保留元数据</param>
/// <exception cref="ObjectDisposedException"></exception>
public void SetCapacity(int size, bool retainedData = false)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
byte[] bytes = new byte[size];
if (retainedData)
{
Array.Copy(this.m_buffer, 0, bytes, 0, this.m_buffer.Length);
}
BytePool.Recycle(this.m_buffer);
this.m_buffer = bytes;
}
/// <summary>
/// 设置持续持有属性,当为True时,调用Dispose会失效,表示该对象将长期持有,直至设置为False。
/// 当为False时,会自动调用Dispose。
/// </summary>
/// <param name="holding"></param>
/// <exception cref="ObjectDisposedException"></exception>
public void SetHolding(bool holding)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
this.m_holding = holding;
if (!holding)
{
this.Dispose();
}
}
/// <summary>
/// 设置实际长度
/// </summary>
/// <param name="value"></param>
/// <exception cref="ObjectDisposedException"></exception>
public override void SetLength(long value)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (value > this.m_buffer.Length)
{
throw new RRQMException("设置值超出容量");
}
this.m_length = value;
}
/// <summary>
/// 从指定位置转化到指定长度的有效内存
/// </summary>
/// <param name="offset"></param>
/// <param name="length"></param>
/// <returns></returns>
public byte[] ToArray(int offset, int length)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
byte[] buffer = new byte[length];
Array.Copy(this.m_buffer, offset, buffer, 0, buffer.Length);
return buffer;
}
/// <summary>
/// 转换为UTF-8字符
/// </summary>
/// <returns></returns>
public override string ToString()
{
return this.ToString(0, this.Len);
}
/// <summary>
/// 转换为UTF-8字符
/// </summary>
/// <param name="offset">偏移量</param>
/// <param name="length">长度</param>
/// <returns></returns>
public string ToString(int offset, int length)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
return Encoding.UTF8.GetString(this.m_buffer, offset, length);
}
/// <summary>
/// 转换为UTF-8字符
/// </summary>
/// <param name="offset">偏移量</param>
/// <returns></returns>
public string ToString(int offset)
{
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
return Encoding.UTF8.GetString(this.m_buffer, offset, this.Len - offset);
}
/// <summary>
/// 写入
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <exception cref="ObjectDisposedException"></exception>
public override void Write(byte[] buffer, int offset, int count)
{
if (count == 0)
{
return;
}
if (!this.m_using)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (this.m_buffer.Length - this.m_position < count)
{
int need = this.m_buffer.Length + count - ((int)(this.m_buffer.Length - this.m_position));
int lend = this.m_buffer.Length;
while (need > lend)
{
lend = (int)(lend * m_ratio);
}
this.SetCapacity(lend, true);
}
Array.Copy(buffer, offset, this.m_buffer, this.m_position, count);
this.m_position += count;
this.m_length = Math.Max(this.m_position, this.m_length);
}
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="disposing"></param>
protected sealed override void Dispose(bool disposing)
{
if (this.m_holding)
{
return;
}
if (this.m_needDis)
{
if (Interlocked.Decrement(ref this.dis) == 0)
{
GC.SuppressFinalize(this);
BytePool.Recycle(this.m_buffer);
this.Dis();
}
}
base.Dispose(disposing);
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace RRQMCore.ByteManager
{
/// <summary>
/// 字节池
/// </summary>
public static class BytePool
{
private static ConcurrentDictionary<long, BytesQueue> bytesDictionary = new ConcurrentDictionary<long, BytesQueue>();
private static bool m_autoZero;
private static long m_fullSize;
private static int m_keyCapacity;
private static int m_maxBlockSize;
private static long m_maxSize;
private static int m_minBlockSize;
private static Timer m_timer;
static BytePool()
{
m_timer = new Timer((o) =>
{
BytePool.Clear();
}, null, 1000 * 60 * 60, 1000 * 60 * 60);
m_keyCapacity = 100;
m_autoZero = false;
m_maxSize = 1024 * 1024 * 512;
SetBlockSize(1024, 1024 * 1024 * 20);
AddSizeKey(10240);
}
/// <summary>
/// 回收内存时,自动归零
/// </summary>
public static bool AutoZero
{
get => m_autoZero;
set => m_autoZero = value;
}
/// <summary>
/// 键容量
/// </summary>
public static int KeyCapacity
{
get => m_keyCapacity;
set => m_keyCapacity = value;
}
/// <summary>
/// 单个块最大值
/// </summary>
public static int MaxBlockSize => m_maxBlockSize;
/// <summary>
/// 允许的内存池最大值
/// </summary>
public static long MaxSize
{
get => m_maxSize;
set
{
if (value < 1024)
{
value = 1024;
}
m_maxSize = value;
}
}
/// <summary>
/// 单个块最小值
/// </summary>
public static int MinBlockSize => m_minBlockSize;
/// <summary>
/// 添加尺寸键
/// </summary>
/// <param name="byteSize"></param>
/// <returns></returns>
public static bool AddSizeKey(int byteSize)
{
if (bytesDictionary.TryAdd(byteSize, new BytesQueue(byteSize)))
{
return true;
}
return false;
}
/// <summary>
/// 清理
/// </summary>
public static void Clear()
{
bytesDictionary.Clear();
GC.Collect();
}
/// <summary>
/// 确定是否包含指定尺寸键
/// </summary>
/// <param name="byteSize"></param>
/// <returns></returns>
public static bool ContainsSizeKey(int byteSize)
{
return bytesDictionary.ContainsKey(byteSize);
}
/// <summary>
/// 获取所以内存键
/// </summary>
/// <returns></returns>
public static long[] GetAllSizeKeys()
{
return bytesDictionary.Keys.ToArray();
}
/// <summary>
/// 获取ByteBlock
/// </summary>
/// <param name="byteSize">长度</param>
/// <param name="equalSize">要求长度相同</param>
/// <returns></returns>
public static ByteBlock GetByteBlock(int byteSize, bool equalSize)
{
ByteBlock byteBlock = new ByteBlock(byteSize, equalSize);
return byteBlock;
}
/// <summary>
/// 获取ByteBlock
/// </summary>
/// <param name="byteSize"></param>
/// <returns></returns>
public static ByteBlock GetByteBlock(int byteSize)
{
if (byteSize < m_minBlockSize)
{
byteSize = m_minBlockSize;
}
return GetByteBlock(byteSize, false);
}
/// <summary>
/// 获取内存池容量
/// </summary>
/// <returns></returns>
public static long GetPoolSize()
{
long size = 0;
foreach (var item in bytesDictionary.Values)
{
size += item.FullSize;
}
return size;
}
/// <summary>
/// 移除尺寸键
/// </summary>
/// <param name="byteSize"></param>
/// <returns></returns>
public static bool RemoveSizeKey(int byteSize)
{
if (bytesDictionary.TryRemove(byteSize, out BytesQueue queue))
{
queue.Clear();
return true;
}
return false;
}
/// <summary>
/// 设置内存块参数
/// </summary>
/// <param name="minBlockSize"></param>
/// <param name="maxBlockSize"></param>
public static void SetBlockSize(int minBlockSize, int maxBlockSize)
{
BytePool.m_maxBlockSize = maxBlockSize;
BytePool.m_minBlockSize = minBlockSize;
bytesDictionary.Clear();
}
/// <summary>
/// 获取内存核心。获取的核心可以不用归还。
/// </summary>
/// <param name="byteSize"></param>
/// <param name="equalSize"></param>
/// <returns></returns>
public static byte[] GetByteCore(int byteSize, bool equalSize = false)
{
BytesQueue bytesCollection;
if (equalSize)
{
//等长
if (bytesDictionary.TryGetValue(byteSize, out bytesCollection))
{
if (bytesCollection.TryGet(out byte[] bytes))
{
m_fullSize -= byteSize;
return bytes;
}
}
else
{
CheckKeyCapacity(byteSize);
}
return new byte[byteSize];
}
else
{
byteSize = HitSize(byteSize);
//搜索已创建集合
if (bytesDictionary.TryGetValue(byteSize, out bytesCollection))
{
if (bytesCollection.TryGet(out byte[] bytes))
{
m_fullSize -= byteSize;
return bytes;
}
}
else
{
CheckKeyCapacity(byteSize);
}
return new byte[byteSize];
}
}
/// <summary>
/// 回收内存核心
/// </summary>
/// <param name="bytes"></param>
public static void Recycle(byte[] bytes)
{
if (bytes == null)
{
return;
}
if (m_maxSize > m_fullSize)
{
if (bytesDictionary.TryGetValue(bytes.Length, out BytesQueue bytesQueue))
{
if (m_autoZero)
{
Array.Clear(bytes, 0, bytes.Length);
}
m_fullSize += bytes.Length;
bytesQueue.Add(bytes);
}
}
else
{
long size = 0;
foreach (var collection in bytesDictionary.Values)
{
size += collection.FullSize;
}
m_fullSize = size;
}
}
private static void CheckKeyCapacity(int byteSize)
{
if (byteSize < m_minBlockSize || byteSize > m_maxBlockSize)
{
return;
}
if (bytesDictionary.Count < m_keyCapacity)
{
bytesDictionary.TryAdd(byteSize, new BytesQueue(byteSize));
}
else
{
List<BytesQueue> bytesQueues = bytesDictionary.Values.ToList();
bytesQueues.Sort((x, y) => { return x.referenced > y.referenced ? -1 : 1; });
for (int i = (int)(bytesQueues.Count * 0.2); i < bytesQueues.Count; i++)
{
if (bytesDictionary.TryRemove(bytesQueues[i].size, out BytesQueue queue))
{
queue.Clear();
}
}
}
}
private static int HitSize(int num)
{
//switch (num)
//{
// case <= 1024:
// {
// return 1024;
// }
// case <= 2048:
// {
// return 2048;
// }
// case <= 4096:
// {
// return 4096;
// }
// case <= 8192:
// {
// return 8192;
// }
// case <= 10240:
// {
// return 10240;
// }
// case <= 16384:
// {
// return 16384;
// }
// case <= 32768:
// {
// return 32768;
// }
// case <= 65536:
// {
// return 65536;
// }
// case <= 131072:
// {
// return 131072;
// }
// case <= 262144:
// {
// return 262144;
// }
// case <= 524288:
// {
// return 524288;
// }
// case <= 1048576:
// {
// return 1048576;
// }
// case <= 2097152:
// {
// return 2097152;
// }
// case <= 4194304:
// {
// return 4194304;
// }
// case <= 8388608:
// {
// return 8388608;
// }
// case <= 16777216:
// {
// return 16777216;
// }
// case <= 33554432:
// {
// return 33554432;
// }
// case <= 67108864:
// {
// return 67108864;
// }
// case <= 134217728:
// {
// return 134217728;
// }
// default:
// return num;
//}
//U3D无法编译时替换。
if (num <= 10240)//10k
{
return 10240;
}
else if (num <= 65536)//64k
{
return 65536;
}
else if (num <= 102400)//100k
{
return 102400;
}
else if (num <= 524288) //512k
{
return 524288;
}
else if (num <= 1048576)//1Mb
{
return 1048576;
}
else if (num <= 5242880)//5Mb
{
return 5242880;
}
else if (num <= 10485760)//10Mb
{
return 10485760;
}
else if (num <= 1024 * 1024 * 20)//20Mb
{
return 1024 * 1024 * 20;
}
else if (num <= 1024 * 1024 * 50)//50Mb
{
return 1024 * 1024 * 50;
}
else if (num <= 1024 * 1024 * 100)//100Mb
{
return 1024 * 1024 * 100;
}
else if (num <= 1024 * 1024 * 500)//500Mb
{
return 1024 * 1024 * 500;
}
else if (num <= 1024 * 1024 * 1024)//1Gb
{
return 1024 * 1024 * 1024;
}
else
{
return num;
}
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
namespace RRQMCore.ByteManager
{
/// <summary>
/// 字节块集合
/// </summary>
[DebuggerDisplay("Count = {bytesQueue.Count}")]
internal class BytesQueue
{
internal int size;
internal BytesQueue(int size)
{
this.size = size;
}
/// <summary>
/// 占用空间
/// </summary>
public long FullSize => this.size * this.bytesQueue.Count;
private ConcurrentQueue<byte[]> bytesQueue = new ConcurrentQueue<byte[]>();
internal long referenced;
/// <summary>
/// 获取当前实例中的空闲的Block
/// </summary>
/// <returns></returns>
public bool TryGet(out byte[] bytes)
{
this.referenced++;
return this.bytesQueue.TryDequeue(out bytes);
}
/// <summary>
/// 向当前集合添加Block
/// </summary>
/// <param name="bytes"></param>
public void Add(byte[] bytes)
{
this.bytesQueue.Enqueue(bytes);
}
internal void Clear()
{
this.bytesQueue.Clear();
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
namespace RRQMCore.ByteManager
{
/// <summary>
/// 字节块流
/// </summary>
public interface IByteBlock : IDisposable
{
/// <summary>
/// 字节实例
/// </summary>
byte[] Buffer { get; }
/// <summary>
/// 仅当内存块可用,且<see cref="CanReadLen"/>>0时为True。
/// </summary>
bool CanRead { get; }
/// <summary>
/// 剩余的长度,准确掌握该值,可以避免内存扩展,计算为<see cref="Capacity"/>与<see cref="Pos"/>的差值。
/// </summary>
int FreeLength { get; }
/// <summary>
/// 还能读取的长度,计算为<see cref="Len"/>与<see cref="Pos"/>的差值。
/// </summary>
int CanReadLen { get; }
/// <summary>
/// 还能读取的长度,计算为<see cref="Len"/>与<see cref="Pos"/>的差值。
/// </summary>
long CanReadLength { get; }
/// <summary>
/// 容量
/// </summary>
int Capacity { get; }
/// <summary>
/// 表示持续性持有,为True时,Dispose将调用无效。
/// </summary>
bool Holding { get; }
/// <summary>
/// Int真实长度
/// </summary>
int Len { get; }
/// <summary>
/// 真实长度
/// </summary>
long Length { get; }
/// <summary>
/// int型流位置
/// </summary>
int Pos { get; set; }
/// <summary>
/// 流位置
/// </summary>
long Position { get; set; }
/// <summary>
/// 使用状态
/// </summary>
bool Using { get; }
/// <summary>
/// 直接完全释放,游离该对象,然后等待GC
/// </summary>
void AbsoluteDispose();
/// <summary>
/// 清空所有内存数据
/// </summary>
/// <exception cref="ObjectDisposedException">内存块已释放</exception>
void Clear();
/// <summary>
/// 将内存块初始化到刚申请的状态。
/// <para>仅仅重置<see cref="Position"/>和<see cref="Length"/>属性。</para>
/// </summary>
/// <exception cref="ObjectDisposedException">内存块已释放</exception>
void Reset();
/// <summary>
/// 读取数据,然后递增Pos
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="ObjectDisposedException"></exception>
int Read(byte[] buffer, int offset, int length);
/// <summary>
/// 读取一个字节
/// </summary>
/// <returns></returns>
int ReadByte();
/// <summary>
/// 重新设置容量
/// </summary>
/// <param name="size">新尺寸</param>
/// <param name="retainedData">是否保留元数据</param>
/// <exception cref="ObjectDisposedException"></exception>
void SetCapacity(int size, bool retainedData = false);
/// <summary>
/// 设置持续持有属性,当为True时,调用Dispose会失效,表示该对象将长期持有,直至设置为False。
/// 当为False时,会自动调用Dispose。
/// </summary>
/// <param name="holding"></param>
/// <exception cref="ObjectDisposedException"></exception>
void SetHolding(bool holding);
/// <summary>
/// 设置实际长度
/// </summary>
/// <param name="value"></param>
/// <exception cref="ObjectDisposedException"></exception>
void SetLength(long value);
/// <summary>
/// 从指定位置转化到指定长度的有效内存
/// </summary>
/// <param name="offset"></param>
/// <param name="length"></param>
/// <returns></returns>
byte[] ToArray(int offset, int length);
/// <summary>
/// 写入
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <exception cref="ObjectDisposedException"></exception>
void Write(byte[] buffer, int offset, int count);
}
}
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System.Collections.Concurrent;
namespace RRQMCore.Collections.Concurrent
{
/// <summary>
/// 安全双向字典
/// </summary>
public class ConcurrentDoublyDictionary<TKey, TValue>
{
private ConcurrentDictionary<TKey, TValue> m_keyToValue;
private ConcurrentDictionary<TValue, TKey> m_valueToKey;
/// <summary>
/// 构造函数
/// </summary>
public ConcurrentDoublyDictionary()
{
this.m_keyToValue = new ConcurrentDictionary<TKey, TValue>();
this.m_valueToKey = new ConcurrentDictionary<TValue, TKey>();
}
/// <summary>
/// 由键指向值得集合
/// </summary>
public ConcurrentDictionary<TKey, TValue> KeyToValue => this.m_keyToValue;
/// <summary>
/// 由值指向键的集合
/// </summary>
public ConcurrentDictionary<TValue, TKey> ValueToKey => this.m_valueToKey;
/// <summary>
/// 尝试将指定的键和值添加到字典中。
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool TryAdd(TKey key, TValue value)
{
if (this.m_keyToValue.TryAdd(key, value))
{
if (this.m_valueToKey.TryAdd(value, key))
{
return true;
}
else
{
this.m_keyToValue.TryRemove(key, out _);
return false;
}
}
return false;
}
/// <summary>
/// 由键尝试移除
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool TryRemoveFromKey(TKey key, out TValue value)
{
if (this.m_keyToValue.TryRemove(key, out value))
{
if (this.m_valueToKey.TryRemove(value, out _))
{
return true;
}
}
return false;
}
/// <summary>
/// 由值尝试移除
/// </summary>
/// <param name="value"></param>
/// <param name="key"></param>
/// <returns></returns>
public bool TryRemoveFromValue(TValue value, out TKey key)
{
if (this.m_valueToKey.TryRemove(value, out key))
{
if (this.m_keyToValue.TryRemove(key, out _))
{
return true;
}
}
return false;
}
/// <summary>
/// 由键获取到值
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool TryGetFromKey(TKey key, out TValue value)
{
return this.m_keyToValue.TryGetValue(key, out value);
}
/// <summary>
/// 由值获取到键
/// </summary>
/// <param name="value"></param>
/// <param name="key"></param>
/// <returns></returns>
public bool TryGetFromValue(TValue value, out TKey key)
{
return this.m_valueToKey.TryGetValue(value, out key);
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System.Collections.Concurrent;
using System.Threading;
namespace RRQMCore.Collections.Concurrent
{
/// <summary>
/// 智能安全队列
/// </summary>
/// <typeparam name="T"></typeparam>
public class IntelligentConcurrentQueue<T> : ConcurrentQueue<T>
{
private int m_count;
private int m_maxCount;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="maxCount"></param>
public IntelligentConcurrentQueue(int maxCount)
{
this.m_maxCount = maxCount;
}
/// <summary>
/// 允许的最大长度
/// </summary>
public int MaxCount => this.m_maxCount;
/// <summary>
/// 长度
/// </summary>
public new int Count => this.m_count;
/// <summary>
/// 入队
/// </summary>
/// <param name="item"></param>
public new void Enqueue(T item)
{
SpinWait.SpinUntil(this.Check);
Interlocked.Increment(ref this.m_count);
base.Enqueue(item);
}
/// <summary>
/// 出队
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
public new bool TryDequeue(out T result)
{
if (base.TryDequeue(out result))
{
Interlocked.Decrement(ref this.m_count);
return true;
}
return false;
}
private bool Check()
{
return this.m_count < this.m_maxCount;
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Threading;
namespace RRQMCore.Collections.Concurrent
{
/// <summary>
/// 智能数据安全队列
/// </summary>
/// <typeparam name="T"></typeparam>
public class IntelligentDataQueue<T> : ConcurrentQueue<T> where T : IQueueData
{
private bool m_overflowWait;
/// <summary>
/// 溢出等待
/// </summary>
public bool OverflowWait
{
get => this.m_overflowWait;
set => this.m_overflowWait = value;
}
private Action<bool> m_onQueueChanged;
/// <summary>
/// 在队列修改时
/// </summary>
public Action<bool> OnQueueChanged
{
get => this.m_onQueueChanged;
set => this.m_onQueueChanged = value;
}
private bool m_free;
/// <summary>
/// 是否有空位允许入队
/// </summary>
public bool Free => this.m_free;
private long m_actualSize;
private long m_maxSize;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="maxSize"></param>
public IntelligentDataQueue(long maxSize)
{
this.m_free = true;
this.m_overflowWait = true;
this.MaxSize = maxSize;
}
/// <summary>
/// 构造函数
/// </summary>
public IntelligentDataQueue() : this(1024 * 1024 * 10)
{
}
/// <summary>
/// 允许的最大长度
/// </summary>
public long MaxSize
{
get => this.m_maxSize;
set
{
if (value < 1)
{
value = 1;
}
this.m_maxSize = value;
}
}
/// <summary>
/// 实际尺寸
/// </summary>
public long ActualSize => this.m_actualSize;
/// <summary>
/// 清空队列
/// </summary>
public void Clear(Action<T> onClear)
{
while (base.TryDequeue(out T t))
{
onClear?.Invoke(t);
}
}
/// <summary>
/// 入队
/// </summary>
/// <param name="item"></param>
public new void Enqueue(T item)
{
lock (this)
{
bool free = this.m_actualSize < this.m_maxSize;
if (this.m_free != free)
{
this.m_free = free;
this.m_onQueueChanged?.Invoke(this.m_free);
}
if (this.m_overflowWait)
{
SpinWait.SpinUntil(this.Check);
}
Interlocked.Add(ref this.m_actualSize, item.Size);
base.Enqueue(item);
}
}
/// <summary>
/// 出队
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
public new bool TryDequeue(out T result)
{
if (base.TryDequeue(out result))
{
Interlocked.Add(ref this.m_actualSize, -result.Size);
bool free = this.m_actualSize < this.m_maxSize;
if (this.m_free != free)
{
this.m_free = free;
this.m_onQueueChanged?.Invoke(this.m_free);
}
return true;
}
return false;
}
private bool Check()
{
return this.m_actualSize < this.m_maxSize;
}
}
/// <summary>
/// 队列数据
/// </summary>
public interface IQueueData
{
/// <summary>
/// 数据长度
/// </summary>
int Size { get; }
}
/// <summary>
/// 传输字节
/// </summary>
public readonly struct QueueDataBytes : IQueueData
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="length"></param>
public QueueDataBytes(byte[] buffer, int offset, int length)
{
this.Offset = offset;
this.Length = length;
this.Buffer = buffer;
this.Size = length;
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="buffer"></param>
public QueueDataBytes(byte[] buffer) : this(buffer, 0, buffer.Length)
{
}
/// <summary>
/// 数据内存
/// </summary>
public byte[] Buffer { get; }
/// <summary>
/// 偏移
/// </summary>
public int Offset { get; }
/// <summary>
/// 长度
/// </summary>
public int Length { get; }
/// <summary>
/// 尺寸
/// </summary>
public int Size { get; }
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using RRQMCore.Extensions;
using RRQMCore.XREF.Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace RRQMCore
{
/// <summary>
/// 运行配置类
/// </summary>
public abstract class AppConfigBase
{
private readonly string m_fullPath;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="fullPath"></param>
public AppConfigBase(string fullPath)
{
if (string.IsNullOrEmpty(fullPath))
{
throw new ArgumentException($"“{nameof(fullPath)}”不能为 null 或空。", nameof(fullPath));
}
this.m_fullPath = fullPath;
}
/// <summary>
/// 保存配置
/// </summary>
/// <param name="overwrite"></param>
/// <param name="msg"></param>
/// <returns></returns>
public bool Save(bool overwrite, out string msg)
{
if (overwrite == false && File.Exists(this.m_fullPath))
{
msg = null;
return true;
}
try
{
File.WriteAllBytes(this.m_fullPath, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(this, Formatting.Indented)));
msg = null;
return true;
}
catch (Exception ex)
{
msg = ex.Message;
return false;
}
}
/// <summary>
/// 加载配置
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public bool Load(out string msg)
{
try
{
if (!File.Exists(this.m_fullPath))
{
this.Save(false, out _);
}
var obj = File.ReadAllText(this.m_fullPath).ToJsonObject(this.GetType());
var ps = this.GetType().GetProperties();
foreach (var item in ps)
{
item.SetValue(this, item.GetValue(obj));
}
msg = null;
return true;
}
catch (Exception ex)
{
msg = ex.Message;
return false;
}
}
/// <summary>
/// 获取默认配置。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T GetDefault<T>() where T : AppConfigBase, new()
{
Type type = typeof(T);
if (list.TryGetValue(type, out object value))
{
return (T)value;
}
T _default = ((T)Activator.CreateInstance(typeof(T)));
_default.Load(out _);
list.Add(type, _default);
return _default;
}
private static Dictionary<Type, object> list = new Dictionary<Type, object>();
/// <summary>
/// 获取默认配置,每次调用该方法时,都会重新加载配置。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T GetNewDefault<T>() where T : AppConfigBase, new()
{
T _default = ((T)Activator.CreateInstance(typeof(T)));
_default.Load(out _);
if (list.ContainsKey(_default.GetType()))
{
list[_default.GetType()] = _default;
}
else
{
list.Add(_default.GetType(), _default);
}
return _default;
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
namespace RRQMCore
{
/// <summary>
/// 具有释放的对象。
/// </summary>
public class DisposableObject : IDisposable
{
/// <summary>
/// 判断是否已释放。
/// </summary>
protected volatile bool disposedValue;
/// <summary>
/// 释放
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
if (!this.disposedValue)
{
if (disposing)
{
// TODO: 释放托管状态(托管对象)
}
// TODO: 释放未托管的资源(未托管的对象)并重写终结器
// TODO: 将大型字段设置为 null
this.disposedValue = true;
}
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
// 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace RRQMCore
{
/// <summary>
/// 大小端类型
/// </summary>
public enum EndianType
{
/// <summary>
/// 小端模式
/// </summary>
Little,
/// <summary>
/// 大端模式
/// </summary>
Big
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System.ComponentModel;
namespace RRQMCore
{
/// <summary>
/// RRQM资源枚举
/// </summary>
public enum ResType
{
/// <summary>
/// 未知错误
/// </summary>
[Description("未知错误")]
UnknownError,
/// <summary>
/// 参数为空
/// </summary>
[Description("参数‘{0}’为空。")]
ArgumentNull,
/// <summary>
/// 远程终端拒绝该操作
/// </summary>
[Description("远程终端拒绝该操作,反馈信息:{0}。")]
RemoteRefuse,
/// <summary>
/// 远程终端不响应该操作
/// </summary>
[Description("远程终端不支持响应该操作。")]
RemoteNotSupported,
/// <summary>
/// 远程终端异常
/// </summary>
[Description("远程终端异常,信息:{0}。")]
RemoteException,
/// <summary>
/// 通道设置失败
/// </summary>
[Description("通道设置失败。")]
SetChannelFail,
/// <summary>
/// 路径无效
/// </summary>
[Description("参数‘{0}’设置的路径‘{1}’不合法。")]
PathInvalid,
/// <summary>
/// 文件已存在
/// </summary>
[Description("文件‘{0}’已存在。")]
FileExists,
/// <summary>
/// 文件不存在
/// </summary>
[Description("文件‘{0}’不存在。")]
FileNotExists,
/// <summary>
/// 远程文件不存在
/// </summary>
[Description("远程文件‘{0}’不存在。")]
RemoteFileNotExists,
/// <summary>
/// 创建写入流失败
/// </summary>
[Description("从‘{0}’创建写入流失败,信息:{1}。")]
CreateWriteStreamFail,
/// <summary>
/// 没有找到流文件
/// </summary>
[Description("没有找到路径‘{0}’对应的流文件。")]
StreamNotFind,
/// <summary>
/// 没有找到客户端
/// </summary>
[Description("没有找到ID为{0}的客户端。")]
ClientNotFind,
/// <summary>
/// 流文件正在被应用
/// </summary>
[Description("路径‘{0}’对应的流文件,仍然被‘{1}’对象应用。")]
StreamReferencing,
/// <summary>
/// 接收流容器为空
/// </summary>
[Description("接收流容器为空。")]
StreamBucketNull,
/// <summary>
/// 加载流异常。
/// </summary>
[Description("从‘{0}’路径加载流异常,信息:‘{1}’。")]
LoadStreamFail,
/// <summary>
/// 事件操作器异常
/// </summary>
[Description("事件操作器异常。")]
GetEventArgsFail,
/// <summary>
/// 长时间没有响应。
/// </summary>
[Description("长时间没有响应。")]
NoResponse,
/// <summary>
/// 该Token消息已注册
/// </summary>
[Description("Token消息为‘{0}’的已注册。")]
TokenExist,
/// <summary>
/// 信息未找到
/// </summary>
[Description("Token消息为‘{0}’的未注册。")]
MessageNotFound,
/// <summary>
/// 数据处理适配器为空
/// </summary>
[Description("数据处理适配器为空,可能客户端已掉线。")]
NullDataAdapter,
/// <summary>
/// 操作超时
/// </summary>
[Description("操作超时")]
Overtime,
/// <summary>
/// 名称为“{0}”的事件已存在
/// </summary>
[Description("名称为“{0}”的事件已存在。")]
EventExisted,
/// <summary>
/// 名称为“{0}”的事件不存在
/// </summary>
[Description("名称为“{0}”的事件不存在。")]
EventNotExist,
/// <summary>
/// 客户端没有连接
/// </summary>
[Description("客户端没有连接。")]
NotConnected,
/// <summary>
/// 授权密钥无效
/// </summary>
[Description("授权密钥无效,程序将在5秒后退出。请检查密钥,或者不使用企业版功能。")]
LicenceKeyInvalid
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace RRQMCore
{
/// <summary>
/// 结果类型
/// </summary>
public enum ResultCode
{
/// <summary>
/// 未执行的
/// </summary>
Default,
/// <summary>
/// 错误
/// </summary>
Error,
/// <summary>
/// 成功
/// </summary>
Success,
/// <summary>
/// 操作超时
/// </summary>
Overtime,
/// <summary>
/// 操作取消
/// </summary>
Canceled
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using RRQMCore;
using System;
using System.Diagnostics;
using System.Threading;
namespace RRQMCore
{
/// <summary>
/// 流量控制
/// </summary>
public class FlowGate
{
private long m_maximum;
private Stopwatch m_stopwatch;
private long m_timeTick;
private long m_transferLength;
/// <summary>
/// 构造函数
/// </summary>
public FlowGate()
{
this.m_stopwatch = new Stopwatch();
}
/// <summary>
/// 最大值
/// </summary>
public long Maximum
{
get => this.m_maximum;
set => this.m_maximum = value;
}
/// <summary>
/// 检测等待
/// </summary>
public void AddCheckWait(int increment)
{
this.m_transferLength += increment;
if (this.GetNowTick() - this.m_timeTick > 0)
{
//时间过了一秒
this.m_timeTick = this.GetNowTick();
this.m_transferLength = 0;
this.m_stopwatch.Restart();
}
else
{
//在这一秒中
if (this.m_transferLength > this.m_maximum)
{
//上传饱和
this.m_stopwatch.Stop();
int sleepTime = 1000 - (int)this.m_stopwatch.ElapsedMilliseconds <= 0 ? 0 : 1000 - (int)this.m_stopwatch.ElapsedMilliseconds;
Thread.Sleep(sleepTime);
}
}
}
/// <summary>
/// 获取当前时间帧
/// </summary>
/// <returns></returns>
private long GetNowTick()
{
return DateTime.Now.Ticks / 10000000;
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace RRQMCore
{
/// <summary>
/// 返回通知接口
/// </summary>
public interface IResult
{
/// <summary>
/// 是否成功
/// </summary>
ResultCode ResultCode { get; }
/// <summary>
/// 消息
/// </summary>
string Message { get; }
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
using System.Threading;
namespace RRQMCore
{
/// <summary>
/// 读取锁
/// </summary>
public struct ReadLock : IDisposable
{
private ReaderWriterLockSlim m_locks;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="locks"></param>
public ReadLock(ReaderWriterLockSlim locks)
{
this.m_locks = locks;
this.m_locks.EnterReadLock();
}
/// <summary>
/// 释放
/// </summary>
public void Dispose()
{
this.m_locks.ExitReadLock();
}
}
/// <summary>
/// 写入锁
/// </summary>
public struct WriteLock : IDisposable
{
private ReaderWriterLockSlim m_locks;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="locks"></param>
public WriteLock(ReaderWriterLockSlim locks)
{
this.m_locks = locks;
this.m_locks.EnterWriteLock();
}
/// <summary>
/// 释放
/// </summary>
public void Dispose()
{
this.m_locks.ExitWriteLock();
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System.Collections.Generic;
namespace RRQMCore
{
/// <summary>
/// 可传输的元数据
/// </summary>
public class Metadata : Dictionary<string, string>
{
/// <summary>
/// 添加或更新
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void AddOrUpdate(string key, string value)
{
if (this.ContainsKey(key))
{
this[key] = value;
}
else
{
this.Add(key, value);
}
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
namespace RRQMCore
{
/// <summary>
/// 将基数据类型转换为指定端的一个字节数组,
/// 或将一个字节数组转换为指定端基数据类型。
/// </summary>
public class RRQMBitConverter
{
/// <summary>
/// 以大端
/// </summary>
public static RRQMBitConverter BigEndian;
/// <summary>
/// 以小端
/// </summary>
public static RRQMBitConverter LittleEndian;
static RRQMBitConverter()
{
BigEndian = new RRQMBitConverter(EndianType.Big);
LittleEndian = new RRQMBitConverter(EndianType.Little);
DefaultEndianType = EndianType.Little;
}
private static RRQMBitConverter @default;
/// <summary>
/// 以默认小端,可通过<see cref="RRQMBitConverter.DefaultEndianType"/>重新指定默认端。
/// </summary>
public static RRQMBitConverter Default => @default;
private static EndianType @defaultEndianType;
/// <summary>
/// 默认大小端切换。
/// </summary>
public static EndianType DefaultEndianType
{
get => @defaultEndianType;
set
{
@defaultEndianType = value;
switch (value)
{
case EndianType.Little:
@default = LittleEndian;
break;
case EndianType.Big:
@default = BigEndian;
break;
default:
break;
}
}
}
private EndianType endianType;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="endianType"></param>
public RRQMBitConverter(EndianType endianType)
{
this.endianType = endianType;
}
/// <summary>
/// 指定大小端。
/// </summary>
public EndianType EndianType => this.endianType;
/// <summary>
/// 判断当前系统是否为设置的大小端
/// </summary>
/// <returns></returns>
public bool IsSameOfSet()
{
return !(BitConverter.IsLittleEndian ^ (this.endianType == EndianType.Little));
}
#region ushort
/// <summary>
/// 转换为指定端2字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(ushort value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的2字节转换为UInt16数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public ushort ToUInt16(byte[] buffer, int offset)
{
byte[] bytes = new byte[2];
Array.Copy(buffer, offset, bytes, 0, 2);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToUInt16(bytes, 0);
}
#endregion ushort
#region ulong
/// <summary>
/// 转换为指定端8字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(ulong value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的Ulong数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public ulong ToUInt64(byte[] buffer, int offset)
{
byte[] bytes = new byte[8];
Array.Copy(buffer, offset, bytes, 0, 8);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToUInt64(bytes, 0);
}
#endregion ulong
#region bool
/// <summary>
/// 转换为指定端1字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(bool value)
{
return BitConverter.GetBytes(value);
}
/// <summary>
/// 转换为指定端模式的bool数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public bool ToBoolean(byte[] buffer, int offset)
{
return BitConverter.ToBoolean(buffer, offset);
}
#endregion bool
#region char
/// <summary>
/// 转换为指定端2字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(char value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的Char数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public char ToChar(byte[] buffer, int offset)
{
byte[] bytes = new byte[2];
Array.Copy(buffer, offset, bytes, 0, bytes.Length);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToChar(bytes, 0);
}
#endregion char
#region short
/// <summary>
/// 转换为指定端2字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(short value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的Short数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public short ToInt16(byte[] buffer, int offset)
{
byte[] bytes = new byte[2];
Array.Copy(buffer, offset, bytes, 0, bytes.Length);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToInt16(bytes, 0);
}
#endregion short
#region int
/// <summary>
/// 转换为指定端4字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(int value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的int数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public int ToInt32(byte[] buffer, int offset)
{
byte[] bytes = new byte[4];
Array.Copy(buffer, offset, bytes, 0, bytes.Length);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToInt32(bytes, 0);
}
#endregion int
#region long
/// <summary>
/// 转换为指定端8字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(long value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的long数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public long ToInt64(byte[] buffer, int offset)
{
byte[] bytes = new byte[8];
Array.Copy(buffer, offset, bytes, 0, bytes.Length);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToInt64(bytes, 0);
}
#endregion long
#region uint
/// <summary>
/// 转换为指定端4字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(uint value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的Uint数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public uint ToUInt32(byte[] buffer, int offset)
{
byte[] bytes = new byte[4];
Array.Copy(buffer, offset, bytes, 0, bytes.Length);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToUInt32(bytes, 0);
}
#endregion uint
#region float
/// <summary>
/// 转换为指定端4字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(float value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的float数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public float ToSingle(byte[] buffer, int offset)
{
byte[] bytes = new byte[4];
Array.Copy(buffer, offset, bytes, 0, bytes.Length);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToSingle(bytes, 0);
}
#endregion float
#region long
/// <summary>
/// 转换为指定端8字节
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public byte[] GetBytes(double value)
{
byte[] bytes = BitConverter.GetBytes(value);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return bytes;
}
/// <summary>
/// 转换为指定端模式的double数据。
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <returns></returns>
public double ToDouble(byte[] buffer, int offset)
{
byte[] bytes = new byte[8];
Array.Copy(buffer, offset, bytes, 0, bytes.Length);
if (!this.IsSameOfSet())
{
Array.Reverse(bytes);
}
return BitConverter.ToDouble(bytes, 0);
}
#endregion long
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
using System.Collections;
namespace RRQMCore
{
/// <summary>
/// 常量
/// </summary>
public class RRQMCoreUtility
{
#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
public static readonly Type stringType = typeof(string);
public static readonly Type byteType = typeof(byte);
public static readonly Type sbyteType = typeof(sbyte);
public static readonly Type shortType = typeof(short);
public static readonly Type ushortType = typeof(ushort);
public static readonly Type intType = typeof(int);
public static readonly Type uintType = typeof(uint);
public static readonly Type boolType = typeof(bool);
public static readonly Type charType = typeof(char);
public static readonly Type longType = typeof(long);
public static readonly Type ulongType = typeof(ulong);
public static readonly Type floatType = typeof(float);
public static readonly Type doubleType = typeof(double);
public static readonly Type decimalType = typeof(decimal);
public static readonly Type dateTimeType = typeof(DateTime);
public static readonly Type bytesType = typeof(byte[]);
public static readonly Type dicType = typeof(IDictionary);
public static readonly Type iEnumerableType = typeof(IEnumerable);
public static readonly Type arrayType = typeof(Array);
public static readonly Type listType = typeof(IList);
public static readonly Type nullableType = typeof(Nullable<>);
#pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace RRQMCore
{
/// <summary>
/// 结果返回
/// </summary>
public struct Result : IResult
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="resultCode"></param>
/// <param name="message"></param>
public Result(ResultCode resultCode, string message)
{
this.ResultCode = resultCode;
this.Message = message;
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="resultCode"></param>
public Result(ResultCode resultCode)
{
this.ResultCode = resultCode;
this.Message = resultCode.GetDescription();
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public ResultCode ResultCode { get; private set; }
/// <summary>
/// <inheritdoc/>
/// </summary>
public string Message { get; private set; }
/// <summary>
/// ToString
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"类型:{this.ResultCode},信息:{this.Message}";
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
namespace RRQMCore
{
/// <summary>
/// 雪花ID生成器(该代码来自网络)
/// </summary>
public class SnowflakeIDGenerator
{
//机器ID
private static long workerId;
private long twepoch = 687888001020L; //唯一时间,这是一个避免重复的随机量,自行设定不要大于当前时间戳
private static long sequence = 0L;
private static int workerIdBits = 4; //机器码字节数。4个字节用来保存机器码(定义为Long类型会出现,最大偏移64位,所以左移64位没有意义)
/// <summary>
/// 最大机器ID
/// </summary>
public static long maxWorkerId = -1L ^ (-1L << workerIdBits); //最大机器ID
private static int sequenceBits = 10; //计数器字节数,10个字节用来保存计数码
private static int workerIdShift = sequenceBits; //机器码数据左移位数,就是后面计数器占用的位数
private static int timestampLeftShift = sequenceBits + workerIdBits; //时间戳左移动位数就是机器码和计数器总字节数
/// <summary>
/// 一微秒内可以产生计数,如果达到该值则等到下一微妙在进行生成
/// </summary>
public static long sequenceMask = -1L ^ -1L << sequenceBits; //一微秒内可以产生计数,如果达到该值则等到下一微妙在进行生成
private long lastTimestamp = -1L;
/// <summary>
/// 机器码
/// </summary>
/// <param name="workerId"></param>
public SnowflakeIDGenerator(long workerId)
{
if (workerId > maxWorkerId || workerId < 0)
throw new Exception(string.Format("worker Id can't be greater than {0} or less than 0 ", workerId));
SnowflakeIDGenerator.workerId = workerId;
this.twepoch = DateTime.Now.Ticks - 10000;
}
/// <summary>
/// 获取ID
/// </summary>
/// <returns></returns>
public long NextID()
{
lock (this)
{
long timestamp = this.timeGen();
if (this.lastTimestamp == timestamp)
{ //同一微妙中生成ID
sequence = (sequence + 1) & sequenceMask; //用&运算计算该微秒内产生的计数是否已经到达上限
if (sequence == 0)
{
//一微妙内产生的ID计数已达上限,等待下一微妙
timestamp = this.tillNextMillis(this.lastTimestamp);
}
}
else
{ //不同微秒生成ID
sequence = 0; //计数清0
}
if (timestamp < this.lastTimestamp)
{ //如果当前时间戳比上一次生成ID时时间戳还小,抛出异常,因为不能保证现在生成的ID之前没有生成过
throw new Exception(string.Format("Clock moved backwards. Refusing to generate id for {0} milliseconds",
this.lastTimestamp - timestamp));
}
this.lastTimestamp = timestamp; //把当前时间戳保存为最后生成ID的时间戳
long nextId = (timestamp - this.twepoch << timestampLeftShift) | workerId << workerIdShift | sequence;
return nextId;
}
}
/// <summary>
/// 获取下一微秒时间戳
/// </summary>
/// <param name="lastTimestamp"></param>
/// <returns></returns>
private long tillNextMillis(long lastTimestamp)
{
long timestamp = this.timeGen();
while (timestamp <= lastTimestamp)
{
timestamp = this.timeGen();
}
return timestamp;
}
/// <summary>
/// 生成当前时间戳
/// </summary>
/// <returns></returns>
private long timeGen()
{
return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using RRQMCore.Extensions;
using System;
using System.Collections.Concurrent;
using System.ComponentModel;
namespace RRQMCore
{
/// <summary>
/// 字符串资源字典
/// </summary>
public static class StringResStore
{
private static ConcurrentDictionary<Enum, string> m_cache = new ConcurrentDictionary<Enum, string>();
/// <summary>
/// 获取资源字符
/// </summary>
/// <param name="enum"></param>
/// <param name="objs"></param>
/// <returns></returns>
public static string GetDescription(this Enum @enum, params object[] objs)
{
if (m_cache.TryGetValue(@enum, out string str))
{
if (string.IsNullOrEmpty(str))
{
return @enum.ToString();
}
else
{
return str.Format(objs);
}
}
if (@enum.GetAttribute<DescriptionAttribute>() is DescriptionAttribute description)
{
string res = description.Description;
m_cache.TryAdd(@enum, res);
if (!string.IsNullOrEmpty(res))
{
if (objs.Length > 0)
{
return res.Format(objs);
}
else
{
return res;
}
}
}
return @enum.ToString();
}
}
}
\ No newline at end of file
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System;
namespace RRQMCore.Converter
{
/// <summary>
/// 转换器接口
/// </summary>
public interface IConverter<TSource>
{
/// <summary>
/// 转换器执行顺序
/// <para>该属性值越小,越靠前执行。值相等时,按添加先后顺序</para>
/// <para>该属性效果,仅在<see cref="RRQMConverter{TSource}.Add(IConverter{TSource})"/>之前设置有效。</para>
/// </summary>
int Order { get; set; }
/// <summary>
/// 尝试将源数据转换目标类型对象
/// </summary>
/// <param name="source"></param>
/// <param name="targetType"></param>
/// <param name="target"></param>
/// <returns></returns>
bool TryConvertFrom(TSource source, Type targetType, out object target);
/// <summary>
/// 尝试将目标类型对象转换源数据
/// </summary>
/// <param name="target"></param>
/// <param name="source"></param>
/// <returns></returns>
bool TryConvertTo(object target, out TSource source);
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
//------------------------------------------------------------------------------
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://www.yuque.com/eo2w71/rrqm
// 交流QQ群:234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace RRQMCore.Data.Security
{
/// <summary>
/// 数据锁,用于加密或解密
/// </summary>
public static class DataLock
{
/// <summary>
/// 使用3DES加密
/// </summary>
/// <param name="data">待加密字节</param>
/// <param name="encryptKey">加密口令(长度为8)</param>
/// <returns></returns>
public static byte[] EncryptDES(byte[] data, string encryptKey)
{
byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
byte[] rgbIV = { 0x12, 0x34, 4, 0x78, 0x90, 255, 0xCD, 0xEF };
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
using (MemoryStream mStream = new MemoryStream())
{
using (CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write))
{
cStream.Write(data, 0, data.Length);
cStream.FlushFinalBlock();
return mStream.ToArray();
}
}
}
/// <summary>
/// 使用3DES解密
/// </summary>
/// <param name="data">待解密字节</param>
/// <param name="decryptionKey">解密口令(长度为8)</param>
/// <returns></returns>
public static byte[] DecryptDES(byte[] data, string decryptionKey)
{
byte[] rgbKey = Encoding.UTF8.GetBytes(decryptionKey);
byte[] rgbIV = { 0x12, 0x34, 4, 0x78, 0x90, 255, 0xCD, 0xEF };
DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
using (MemoryStream mStream = new MemoryStream())
{
using (CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write))
{
cStream.Write(data, 0, data.Length);
cStream.FlushFinalBlock();
return mStream.ToArray();
}
}
}
}
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册