├── .gitignore ├── CatLib.Framework.sln ├── LICENSE ├── README.md ├── packages ├── CatLib.Core.1.1.4 │ └── lib │ │ ├── net35 │ │ └── CatLib.Core.dll │ │ └── netstandard2.0 │ │ └── CatLib.Core.dll └── CatLib.Core.1.2.5 │ └── lib │ ├── net35 │ ├── CatLib.Core.dll │ ├── CatLib.Core.pdb │ └── CatLib.Core.xml │ └── netstandard2.0 │ ├── CatLib.Core.dll │ ├── CatLib.Core.pdb │ └── CatLib.Core.xml └── src ├── CatLib.Framework.API.NetStandard └── CatLib.Framework.API.NetStandard.csproj ├── CatLib.Framework.API ├── CatLib.Framework.API.csproj ├── Compress │ ├── ICompress.cs │ └── ICompressManager.cs ├── Debugger │ ├── ILogger.cs │ ├── InvalidArgumentException.cs │ └── LogLevels.cs ├── Encryption │ ├── EncryptionException.cs │ ├── IEncrypter.cs │ └── IEncryptionManager.cs ├── FileSystem │ ├── IFileSystemManager.cs │ └── Internal │ │ ├── IDirectory.cs │ │ ├── IFile.cs │ │ ├── IFileSystem.cs │ │ └── IHandler.cs ├── Hashing │ ├── Checksums.cs │ ├── Hashes.cs │ └── IHashing.cs ├── Json │ ├── IJson.cs │ └── IJsonAware.cs ├── Network │ ├── INetworkChannel.cs │ ├── INetworkManager.cs │ └── IPacker.cs ├── Properties │ └── AssemblyInfo.cs ├── Random │ ├── IRandom.cs │ ├── IRandomFactory.cs │ └── RandomTypes.cs ├── Routing │ ├── EventArgs │ │ └── DispatchEventArgs.cs │ ├── Exception │ │ ├── DomainException.cs │ │ ├── NotFoundRouteException.cs │ │ └── UndefinedDefaultSchemeException.cs │ ├── Features │ │ ├── IMiddleware.cs │ │ └── RoutedAttribute.cs │ ├── IRouter.cs │ └── Internal │ │ ├── IRequest.cs │ │ ├── IResponse.cs │ │ ├── IRoute.cs │ │ └── IRouteGroup.cs ├── Socket │ ├── ISocket.cs │ ├── ISocketManager.cs │ └── SocketEvents.cs ├── Tick │ └── ITick.cs ├── Translation │ ├── Features │ │ └── ITranslateResources.cs │ ├── ITranslator.cs │ └── Languages.cs └── packages.config ├── CatLib.Framework.NetStandard └── CatLib.Framework.NetStandard.csproj ├── CatLib.Framework.Tests ├── CatLib.Framework.Tests.csproj ├── Compress │ └── CompressProviderTests.cs ├── Debugger │ ├── DebuggerHelper.cs │ ├── Log │ │ └── LoggerTests.cs │ ├── WebConsole │ │ ├── HttpDebuggerConsoleTests.cs │ │ └── HttpListenerTests.cs │ ├── WebLog │ │ ├── Controller │ │ │ └── UtilTests.cs │ │ └── LogStoreTests.cs │ └── WebMonitor │ │ ├── Controller │ │ └── MonitorTests.cs │ │ ├── Handler │ │ └── SizeMonitorHandlerTests.cs │ │ └── MonitorStoreTests.cs ├── Encryption │ └── EncryptionProviderTests.cs ├── ExceptionAssert.cs ├── FileSystem │ ├── Adapter │ │ └── LocalTests.cs │ ├── DirectoryTests.cs │ ├── FileSystemProviderTests.cs │ ├── FileSystemTests.cs │ ├── FileTests.cs │ └── HandlerTests.cs ├── Hashing │ └── HashingProviderTests.cs ├── HttpHelper.cs ├── Json │ └── JsonProviderTests.cs ├── Network │ ├── NetworkChannelTests.cs │ ├── NetworkProviderTests.cs │ ├── Packer │ │ ├── FramePackerTests.cs │ │ └── TextPackerTests.cs │ ├── ReceiveStateTests.cs │ └── TcpServer.cs ├── Properties │ └── AssemblyInfo.cs ├── Random │ └── RandomProviderTests.cs ├── Routing │ ├── AttrCompilerRouting.cs │ ├── OptionsParamsAttrRouting.cs │ ├── ParamsAttrRouting.cs │ ├── RequestTests.cs │ ├── RouteCompilerTests.cs │ ├── RouterExceptionTests.cs │ ├── RouterTests.cs │ ├── RoutingMiddleware.cs │ ├── RoutingPriortityMiddleware.cs │ ├── TestMiddlewareException.cs │ ├── UTAttrRoutingSimple.cs │ ├── UTMultAttrRoutingSimple.cs │ └── UriTests.cs ├── Socket │ ├── KcpConnectorTests.cs │ ├── KcpTestsServer.cs │ ├── SocketProviderTests.cs │ ├── TcpConnectorTests.cs │ ├── TcpTestsServer.cs │ └── Util.cs ├── Tick │ └── TickProviderTests.cs ├── Translation │ ├── SelectorTests.cs │ └── TranslationTests.cs └── packages.config ├── CatLib.Framework ├── CatLib.Framework.csproj ├── Compress │ ├── 3rd │ │ ├── SharpCompress │ │ │ ├── Common │ │ │ │ └── SevenZip │ │ │ │ │ ├── CBindPair.cs │ │ │ │ │ ├── CCoderInfo.cs │ │ │ │ │ ├── CFolder.cs │ │ │ │ │ └── CMethodId.cs │ │ │ ├── Compressors │ │ │ │ ├── CompressionMode.cs │ │ │ │ └── LZMA │ │ │ │ │ ├── AesDecoderStream.cs │ │ │ │ │ ├── Bcj2DecoderStream.cs │ │ │ │ │ ├── BitVector.cs │ │ │ │ │ ├── CRC.cs │ │ │ │ │ ├── DecoderStream.cs │ │ │ │ │ ├── ICoder.cs │ │ │ │ │ ├── LZ │ │ │ │ │ ├── CRC.cs │ │ │ │ │ ├── LzBinTree.cs │ │ │ │ │ ├── LzInWindow.cs │ │ │ │ │ └── LzOutWindow.cs │ │ │ │ │ ├── LZipStream.cs │ │ │ │ │ ├── Log.cs │ │ │ │ │ ├── LzmaBase.cs │ │ │ │ │ ├── LzmaDecoder.cs │ │ │ │ │ ├── LzmaEncoder.cs │ │ │ │ │ ├── LzmaEncoderProperties.cs │ │ │ │ │ ├── LzmaStream.cs │ │ │ │ │ ├── RangeCoder │ │ │ │ │ ├── RangeCoder.cs │ │ │ │ │ ├── RangeCoderBit.cs │ │ │ │ │ └── RangeCoderBitTree.cs │ │ │ │ │ ├── Registry.cs │ │ │ │ │ └── Utilites │ │ │ │ │ ├── CrcBuilderStream.cs │ │ │ │ │ ├── CrcCheckStream.cs │ │ │ │ │ ├── IPasswordProvider.cs │ │ │ │ │ └── Utils.cs │ │ │ ├── Converters │ │ │ │ └── DataConverter.cs │ │ │ ├── Crypto │ │ │ │ └── Crc32Stream.cs │ │ │ └── IO │ │ │ │ ├── BufferedSubStream.cs │ │ │ │ └── CountingWritableSubStream.cs │ │ └── SharpZipLib │ │ │ ├── Checksum.meta │ │ │ ├── Checksum │ │ │ ├── Adler32.cs │ │ │ ├── Adler32.cs.meta │ │ │ ├── Crc32.cs │ │ │ ├── Crc32.cs.meta │ │ │ ├── IChecksum.cs │ │ │ └── IChecksum.cs.meta │ │ │ ├── Core.meta │ │ │ ├── Core │ │ │ ├── FileSystemScanner.cs │ │ │ ├── FileSystemScanner.cs.meta │ │ │ ├── INameTransform.cs │ │ │ ├── INameTransform.cs.meta │ │ │ ├── IScanFilter.cs │ │ │ ├── IScanFilter.cs.meta │ │ │ ├── NameFilter.cs │ │ │ ├── NameFilter.cs.meta │ │ │ ├── PathFilter.cs │ │ │ ├── PathFilter.cs.meta │ │ │ ├── StreamUtils.cs │ │ │ ├── StreamUtils.cs.meta │ │ │ ├── WindowsPathUtils.cs │ │ │ └── WindowsPathUtils.cs.meta │ │ │ ├── Encryption.meta │ │ │ ├── Encryption │ │ │ ├── PkzipClassic.cs │ │ │ ├── PkzipClassic.cs.meta │ │ │ ├── ZipAESTransform.cs │ │ │ └── ZipAESTransform.cs.meta │ │ │ ├── GZip.meta │ │ │ ├── GZip │ │ │ ├── GZip.cs │ │ │ ├── GZip.cs.meta │ │ │ ├── GZipConstants.cs │ │ │ ├── GZipConstants.cs.meta │ │ │ ├── GZipException.cs │ │ │ ├── GZipException.cs.meta │ │ │ ├── GzipInputStream.cs │ │ │ ├── GzipInputStream.cs.meta │ │ │ ├── GzipOutputStream.cs │ │ │ └── GzipOutputStream.cs.meta │ │ │ ├── SharpZipBaseException.cs │ │ │ ├── SharpZipBaseException.cs.meta │ │ │ ├── Zip.meta │ │ │ └── Zip │ │ │ ├── Compression.meta │ │ │ ├── Compression │ │ │ ├── Deflater.cs │ │ │ ├── Deflater.cs.meta │ │ │ ├── DeflaterConstants.cs │ │ │ ├── DeflaterConstants.cs.meta │ │ │ ├── DeflaterEngine.cs │ │ │ ├── DeflaterEngine.cs.meta │ │ │ ├── DeflaterHuffman.cs │ │ │ ├── DeflaterHuffman.cs.meta │ │ │ ├── DeflaterPending.cs │ │ │ ├── DeflaterPending.cs.meta │ │ │ ├── Inflater.cs │ │ │ ├── Inflater.cs.meta │ │ │ ├── InflaterDynHeader.cs │ │ │ ├── InflaterDynHeader.cs.meta │ │ │ ├── InflaterHuffmanTree.cs │ │ │ ├── InflaterHuffmanTree.cs.meta │ │ │ ├── PendingBuffer.cs │ │ │ ├── PendingBuffer.cs.meta │ │ │ ├── Streams.meta │ │ │ └── Streams │ │ │ │ ├── DeflaterOutputStream.cs │ │ │ │ ├── DeflaterOutputStream.cs.meta │ │ │ │ ├── InflaterInputStream.cs │ │ │ │ ├── InflaterInputStream.cs.meta │ │ │ │ ├── OutputWindow.cs │ │ │ │ ├── OutputWindow.cs.meta │ │ │ │ ├── StreamManipulator.cs │ │ │ │ └── StreamManipulator.cs.meta │ │ │ ├── ZipConstants.cs │ │ │ ├── ZipConstants.cs.meta │ │ │ ├── ZipEntry.cs │ │ │ ├── ZipEntry.cs.meta │ │ │ ├── ZipException.cs │ │ │ ├── ZipException.cs.meta │ │ │ ├── ZipExtraData.cs │ │ │ ├── ZipExtraData.cs.meta │ │ │ ├── ZipHelperStream.cs │ │ │ └── ZipHelperStream.cs.meta │ ├── CompressManager.cs │ ├── CompressProvider.cs │ ├── GZipAdapter.cs │ └── LzmaAdapter.cs ├── Debugger │ ├── DebuggerProvider.cs │ ├── Log │ │ ├── Handler │ │ │ └── StdOutLogHandler.cs │ │ ├── ILogEntry.cs │ │ ├── ILogHandler.cs │ │ ├── LogEntry.cs │ │ ├── LogUtil.cs │ │ └── Logger.cs │ ├── WebConsole │ │ ├── BaseProtocol.cs │ │ ├── HttpDebuggerConsole.cs │ │ ├── HttpListener.cs │ │ ├── IWebConsoleResponse.cs │ │ └── Protocol │ │ │ └── GetGuid.cs │ ├── WebLog │ │ ├── Controller │ │ │ ├── Log.cs │ │ │ └── Util.cs │ │ ├── LogHandler │ │ │ └── WebLogHandler.cs │ │ ├── LogStore.cs │ │ └── Protocol │ │ │ └── WebConsoleOutputs.cs │ └── WebMonitor │ │ ├── Controller │ │ └── Monitor.cs │ │ ├── Handler │ │ ├── OnceRecordMonitorHandler.cs │ │ └── SizeMonitorHandler.cs │ │ ├── IMonitor.cs │ │ ├── IMonitorHandler.cs │ │ ├── MonitorStore.cs │ │ └── Protocol │ │ └── GetMonitors.cs ├── Encryption │ ├── 3rd │ │ └── Curve25519.cs │ ├── AesEncrypter.cs │ ├── Encrypter.cs │ └── EncryptionProvider.cs ├── Facade │ ├── Compress.cs │ ├── Dispatcher.cs │ ├── Encrypter.cs │ ├── FileSystem.cs │ ├── Hashing.cs │ ├── I18N.cs │ ├── Json.cs │ ├── Network.cs │ ├── Random.cs │ ├── Router.cs │ └── Socket.cs ├── FileSystem │ ├── Adapter │ │ ├── IFileSystemAdapter.cs │ │ └── Local.cs │ ├── Directory.cs │ ├── File.cs │ ├── FileSystem.cs │ ├── FileSystemManager.cs │ ├── FileSystemProvider.cs │ └── Handler.cs ├── Hashing │ ├── 3rd │ │ ├── BCrypt │ │ │ ├── Bcrypt.cs │ │ │ └── SaltParseException.cs │ │ └── MurmurHash │ │ │ ├── Extensions.cs │ │ │ ├── Murmur32.cs │ │ │ └── Murmur32ManagedX86.cs │ ├── Checksum │ │ ├── Adler32.cs │ │ ├── Crc32.cs │ │ ├── Djb.cs │ │ ├── IChecksum.cs │ │ └── Murmur32.cs │ ├── Hashing.cs │ ├── HashingGuard.cs │ └── HashingProvider.cs ├── Json │ ├── 3rd │ │ └── LitJson │ │ │ ├── IJsonWrapper.cs │ │ │ ├── JsonData.cs │ │ │ ├── JsonException.cs │ │ │ ├── JsonMapper.cs │ │ │ ├── JsonMockWrapper.cs │ │ │ ├── JsonReader.cs │ │ │ ├── JsonWriter.cs │ │ │ ├── Lexer.cs │ │ │ ├── Netstandard15Polyfill.cs │ │ │ └── ParserToken.cs │ ├── JsonProvider.cs │ ├── JsonUtility.cs │ └── LitJsonAdapter.cs ├── Network │ ├── HeartBeatState.cs │ ├── NetworkChannel.cs │ ├── NetworkManager.cs │ ├── NetworkProvider.cs │ ├── Packer │ │ ├── FramePacker.cs │ │ └── TextPacker.cs │ └── ReceiveState.cs ├── Properties │ └── AssemblyInfo.cs ├── Random │ ├── 3rd │ │ └── MathNet │ │ │ ├── Euclid.cs │ │ │ └── Random │ │ │ ├── MersenneTwister.cs │ │ │ ├── Mrg32k3a.cs │ │ │ ├── RandomSeed.cs │ │ │ ├── RandomSource.cs │ │ │ ├── WH2006.cs │ │ │ └── Xorshift.cs │ ├── RandomAdaptor.cs │ ├── RandomFactory.cs │ └── RandomProvider.cs ├── Routing │ ├── AttrRouteCompiler.cs │ ├── CompiledRoute.cs │ ├── ExceptionRequest.cs │ ├── Request.cs │ ├── Response.cs │ ├── Route.cs │ ├── RouteAction.cs │ ├── RouteCompiler.cs │ ├── RouteGroup.cs │ ├── RouteOptions.cs │ ├── RouteParameterBinder.cs │ ├── Router.cs │ ├── RouterEvents.cs │ ├── RoutingProvider.cs │ ├── Scheme.cs │ ├── Uri.cs │ └── Validators │ │ ├── HostValidator.cs │ │ ├── IValidators.cs │ │ └── UriValidator.cs ├── Socket │ ├── 3rd │ │ └── kcp │ │ │ ├── kcp.cs │ │ │ └── switch_queue.cs │ ├── Emmiter.cs │ ├── ITick.cs │ ├── KcpConnector.cs │ ├── SocketManager.cs │ ├── SocketProvider.cs │ └── TcpConnector.cs ├── Tick │ ├── TickProvider.cs │ └── TimeTicker.cs ├── Translation │ ├── ISelector.cs │ ├── Selector.cs │ ├── TranslationProvider.cs │ └── Translator.cs └── packages.config └── settings.runsettings /.gitignore: -------------------------------------------------------------------------------- 1 | TestResults 2 | src/CatLib.Framework/bin 3 | src/CatLib.Framework/obj 4 | src/CatLib.Framework.NetStandard/bin 5 | src/CatLib.Framework.NetStandard/obj 6 | src/CatLib.Framework.Tests/bin 7 | src/CatLib.Framework.Tests/obj 8 | src/CatLib.Framework.API/bin 9 | src/CatLib.Framework.API/obj 10 | src/CatLib.Framework.API.NetStandard/bin 11 | src/CatLib.Framework.API.NetStandard/obj 12 | src/coverage.xml 13 | build 14 | 15 | .vscode 16 | .vs 17 | UWP/ 18 | ExportedObj/ 19 | *.svd 20 | *.userprefs 21 | *.pidb 22 | *.suo 23 | *.svd 24 | *.user 25 | *.unityproj 26 | *.tmp 27 | *.booproj 28 | .DS_Store 29 | .DS_Store? 30 | ._* 31 | .Spotlight-V100 32 | .Trashes 33 | Icon? 34 | ehthumbs.db 35 | Thumbs.db 36 | *.nupkg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 CatLib 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/CatLib.Core.1.1.4/lib/net35/CatLib.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatLib/Framework/87eeb58a39b9ea759166337a80d0fa5e410656d4/packages/CatLib.Core.1.1.4/lib/net35/CatLib.Core.dll -------------------------------------------------------------------------------- /packages/CatLib.Core.1.1.4/lib/netstandard2.0/CatLib.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatLib/Framework/87eeb58a39b9ea759166337a80d0fa5e410656d4/packages/CatLib.Core.1.1.4/lib/netstandard2.0/CatLib.Core.dll -------------------------------------------------------------------------------- /packages/CatLib.Core.1.2.5/lib/net35/CatLib.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatLib/Framework/87eeb58a39b9ea759166337a80d0fa5e410656d4/packages/CatLib.Core.1.2.5/lib/net35/CatLib.Core.dll -------------------------------------------------------------------------------- /packages/CatLib.Core.1.2.5/lib/net35/CatLib.Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatLib/Framework/87eeb58a39b9ea759166337a80d0fa5e410656d4/packages/CatLib.Core.1.2.5/lib/net35/CatLib.Core.pdb -------------------------------------------------------------------------------- /packages/CatLib.Core.1.2.5/lib/netstandard2.0/CatLib.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatLib/Framework/87eeb58a39b9ea759166337a80d0fa5e410656d4/packages/CatLib.Core.1.2.5/lib/netstandard2.0/CatLib.Core.dll -------------------------------------------------------------------------------- /packages/CatLib.Core.1.2.5/lib/netstandard2.0/CatLib.Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatLib/Framework/87eeb58a39b9ea759166337a80d0fa5e410656d4/packages/CatLib.Core.1.2.5/lib/netstandard2.0/CatLib.Core.pdb -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Compress/ICompress.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Compress 13 | { 14 | /// 15 | /// 压缩解压缩 16 | /// 17 | public interface ICompress 18 | { 19 | /// 20 | /// 压缩 21 | /// 22 | /// 需要压缩的字节流 23 | /// 压缩后的结果 24 | byte[] Compress(byte[] bytes); 25 | 26 | /// 27 | /// 解压缩 28 | /// 29 | /// 需要解压缩的字节流 30 | /// 解压缩的结果 31 | byte[] Decompress(byte[] bytes); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Compress/ICompressManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Compress 13 | { 14 | /// 15 | /// 压缩管理器 16 | /// 17 | public interface ICompressManager : ISingleManager 18 | { 19 | /// 20 | /// 压缩 21 | /// 22 | /// 需要压缩的字节流 23 | /// 使用的压缩解压缩名字 24 | /// 压缩后的结果 25 | byte[] Compress(byte[] bytes, string name = null); 26 | 27 | /// 28 | /// 解压缩 29 | /// 30 | /// 需要解压缩的字节流 31 | /// 使用的压缩解压缩名字 32 | /// 解压缩的结果 33 | byte[] Decomporess(byte[] bytes, string name = null); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Debugger/InvalidArgumentException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Debugger 15 | { 16 | /// 17 | /// 无效的参数异常 18 | /// 19 | [ExcludeFromCodeCoverage] 20 | public sealed class InvalidArgumentException : ArgumentException 21 | { 22 | /// 23 | /// 无效的参数 24 | /// 25 | public InvalidArgumentException() 26 | : base() { 27 | } 28 | 29 | /// 30 | /// 无效的参数 31 | /// 32 | /// 异常消息 33 | public InvalidArgumentException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | /// 39 | /// 无效的参数 40 | /// 41 | /// 异常消息 42 | /// 异常结构 43 | public InvalidArgumentException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | 48 | /// 49 | /// 无效的参数 50 | /// 51 | /// 异常消息 52 | /// 诱发异常的参数 53 | /// 异常结构 54 | public InvalidArgumentException(string message, string paramName, Exception innerException) 55 | : base(message , paramName, innerException) 56 | { 57 | } 58 | 59 | /// 60 | /// 无效的参数 61 | /// 62 | /// 异常消息 63 | /// 诱发异常的参数 64 | public InvalidArgumentException(string message, string paramName) 65 | : base (message , paramName) 66 | { 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Debugger/LogLevels.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Debugger 13 | { 14 | /// 15 | /// 日志等级 16 | /// 细节见:https://tools.ietf.org/html/rfc5424 17 | /// 18 | public enum LogLevels 19 | { 20 | /// 21 | /// 紧急(系统不可用) 22 | /// 23 | Emergency = 0, 24 | 25 | /// 26 | /// 警报(必须立即采取行动) 27 | /// 28 | Alert = 1, 29 | 30 | /// 31 | /// 关键(关键日志) 32 | /// 33 | Critical = 2, 34 | 35 | /// 36 | /// 错误 37 | /// 38 | Error = 3, 39 | 40 | /// 41 | /// 警告 42 | /// 43 | Warning = 4, 44 | 45 | /// 46 | /// 通知 47 | /// 48 | Notice = 5, 49 | 50 | /// 51 | /// 信息 52 | /// 53 | Info = 6, 54 | 55 | /// 56 | /// 调试级消息 57 | /// 58 | Debug = 7 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Encryption/EncryptionException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Encryption 15 | { 16 | /// 17 | /// 加解密异常 18 | /// 19 | public sealed class EncryptionException : RuntimeException 20 | { 21 | /// 22 | /// 加解密异常 23 | /// 24 | public EncryptionException() : base() 25 | { 26 | 27 | } 28 | 29 | /// 30 | /// 加解密异常 31 | /// 32 | /// 异常消息 33 | public EncryptionException(string message) : base(message) 34 | { 35 | } 36 | 37 | /// 38 | /// 加解密异常 39 | /// 40 | /// 异常消息 41 | /// 内部异常 42 | public EncryptionException(string message, Exception innerException) : base(message, innerException) 43 | { 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Encryption/IEncrypter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Encryption 13 | { 14 | /// 15 | /// 加解密 16 | /// 17 | public interface IEncrypter 18 | { 19 | /// 20 | /// 加密(以Base64返回) 21 | /// 22 | /// 加密数据 23 | /// 加密后的数据 24 | string Encrypt(byte[] content); 25 | 26 | /// 27 | /// 解密 28 | /// 29 | /// 被加密的内容 30 | /// 解密内容 31 | byte[] Decrypt(string payload); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Encryption/IEncryptionManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Encryption 15 | { 16 | /// 17 | /// 加解密管理器 18 | /// 19 | public interface IEncryptionManager : ISingleManager , IEncrypter 20 | { 21 | /// 22 | /// 交换密钥 23 | /// 24 | /// 交换流程(输入值是我方公钥,返回值是对端公钥) 25 | /// 密钥 26 | byte[] ExchangeSecret(Func exchange); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/FileSystem/IFileSystemManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.FileSystem 13 | { 14 | /// 15 | /// 文件系统管理器 16 | /// 17 | public interface IFileSystemManager : ISingleManager 18 | { 19 | /// 20 | /// 获取一个文件系统解决方案(磁盘) 21 | /// 22 | /// 解决方案名 23 | /// 文件系统 24 | IFileSystem Disk(string name = null); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/FileSystem/Internal/IDirectory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.FileSystem 13 | { 14 | /// 15 | /// 文件夹 16 | /// 17 | public interface IDirectory : IHandler 18 | { 19 | /// 20 | /// 获取文件夹下的文件/文件夹列表(不会迭代子文件夹) 21 | /// 22 | /// 指定目录下的文件夹句柄和文件句柄列表 23 | IHandler[] GetList(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/FileSystem/Internal/IFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.FileSystem 13 | { 14 | /// 15 | /// 文件 16 | /// 17 | public interface IFile : IHandler 18 | { 19 | /// 20 | /// 写入数据 21 | /// 如果数据已经存在则覆盖 22 | /// 23 | /// 写入数据 24 | void Write(byte[] contents); 25 | 26 | /// 27 | /// 读取文件 28 | /// 29 | /// 读取的数据 30 | byte[] Read(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/FileSystem/Internal/IHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.IO; 13 | 14 | namespace CatLib.API.FileSystem 15 | { 16 | /// 17 | /// 句柄 18 | /// 19 | public interface IHandler 20 | { 21 | /// 22 | /// 文件/文件夹路径 23 | /// 24 | string Path { get; } 25 | 26 | /// 27 | /// 文件/文件夹是否存在 28 | /// 29 | bool IsExists { get; } 30 | 31 | /// 32 | /// 重命名 33 | /// 34 | /// 新的文件/文件夹名字 35 | void Rename(string newName); 36 | 37 | /// 38 | /// 将文件/文件夹移动到指定路径 39 | /// 40 | /// 移动到的目标路径 41 | void Move(string newPath); 42 | 43 | /// 44 | /// 复制文件或文件夹到指定路径 45 | /// 46 | /// 复制到的路径(不应该包含文件夹或者文件名) 47 | void Copy(string copyPath); 48 | 49 | /// 50 | /// 删除文件或者文件夹 51 | /// 52 | void Delete(); 53 | 54 | /// 55 | /// 获取文件/文件夹属性 56 | /// 57 | /// 文件/文件夹属性 58 | FileAttributes GetAttributes(); 59 | 60 | /// 61 | /// 是否是文件夹 62 | /// 63 | /// 是否是文件夹 64 | bool IsDir { get; } 65 | 66 | /// 67 | /// 文件/文件夹大小 68 | /// 69 | long GetSize(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Hashing/Checksums.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Hashing 13 | { 14 | /// 15 | /// 使用的校验方法 16 | /// 17 | public class Checksums : Enum 18 | { 19 | /// 20 | /// Adler32 21 | /// 22 | public static readonly Checksums Adler32 = new Checksums("Adler32"); 23 | 24 | /// 25 | /// Crc32 26 | /// 27 | public static readonly Checksums Crc32 = new Checksums("Crc32"); 28 | 29 | /// 30 | /// Djb 31 | /// 32 | public static readonly Checksums Djb = new Checksums("Djb"); 33 | 34 | /// 35 | /// Murmur32 36 | /// 37 | public static readonly Checksums Murmur32 = new Checksums("Murmur32"); 38 | 39 | /// 40 | /// 哈希算法类型 41 | /// 42 | /// 哈希算法名字 43 | protected Checksums(string name) : base(name) 44 | { 45 | } 46 | 47 | /// 48 | /// 字符串转Checksums 49 | /// 50 | /// 类型 51 | public static implicit operator Checksums(string type) 52 | { 53 | return new Checksums(type); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Hashing/Hashes.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Hashing 13 | { 14 | /// 15 | /// 哈希算法 16 | /// 17 | public class Hashes : Enum 18 | { 19 | /// 20 | /// DJB Hash 21 | /// 22 | public static readonly Hashes Djb = new Hashes("Djb"); 23 | 24 | /// 25 | /// Murmur Hash 26 | /// 27 | public static readonly Hashes MurmurHash = new Hashes("MurmurHash"); 28 | 29 | /// 30 | /// 哈希算法类型 31 | /// 32 | /// 哈希算法名字 33 | protected Hashes(string name) : base(name) 34 | { 35 | } 36 | 37 | /// 38 | /// 字符串转Hashes 39 | /// 40 | /// 类型 41 | public static implicit operator Hashes(string type) 42 | { 43 | return new Hashes(type); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Json/IJson.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Json 15 | { 16 | /// 17 | /// Json 工具 18 | /// 19 | public interface IJson 20 | { 21 | /// 22 | /// 反序列化 23 | /// 24 | /// 反序列化的类型 25 | /// json数据 26 | /// 反序列化的结果 27 | T Decode(string json); 28 | 29 | /// 30 | /// 反序列化 31 | /// 32 | /// json数据 33 | /// 反序列化的类型 34 | /// 反序列化的结果 35 | object Decode(string json, Type type); 36 | 37 | /// 38 | /// 序列化 39 | /// 40 | /// 需要序列化的对象 41 | /// json数据 42 | string Encode(object item); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Json/IJsonAware.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Json 13 | { 14 | /// 15 | /// Json实例接口 16 | /// 17 | public interface IJsonAware 18 | { 19 | /// 20 | /// 设定json处理器实例接口 21 | /// 22 | /// json处理器 23 | void SetJson(IJson handler); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Network/INetworkManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Network 15 | { 16 | /// 17 | /// 网络管理器 18 | /// 19 | public interface INetworkManager : ISingleManager 20 | { 21 | /// 22 | /// 当释放时 23 | /// 24 | event Action OnReleased; 25 | 26 | /// 27 | /// 当网络链接完成时 28 | /// 29 | event Action OnConnected; 30 | 31 | /// 32 | /// 当网络出现异常时 33 | /// 34 | event Action OnError; 35 | 36 | /// 37 | /// 当收到数据包时 38 | /// 39 | event Action OnMessage; 40 | 41 | /// 42 | /// 当网络断开链接 43 | /// 44 | event Action OnDisconnect; 45 | 46 | /// 47 | /// 当网络链接关闭时 48 | /// 49 | event Action OnClosed; 50 | 51 | /// 52 | /// 当数据发送完成 53 | /// 54 | event Action OnSent; 55 | 56 | /// 57 | /// 当丢失心跳时 58 | /// 59 | event Action OnMissHeartBeat; 60 | 61 | /// 62 | /// 建立链接 63 | /// 64 | /// 网络服务提供商 65 | /// 名字 66 | /// 网络频道 67 | INetworkChannel Make(string nsp, string name = null); 68 | 69 | /// 70 | /// 建立链接 71 | /// 72 | /// 网络服务提供商 73 | /// 打包解包器 74 | /// 名字 75 | /// 网络频道 76 | INetworkChannel Make(string nsp, IPacker packer, string name = null); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Network/IPacker.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Network 15 | { 16 | /// 17 | /// 打包解包器 18 | /// 19 | public interface IPacker 20 | { 21 | /// 22 | /// 检查包的完整性。 23 | /// 如果能够得到包长,则返回包的在buffer中的长度(包含包头),否则返回0继续等待数据。 24 | /// 如果协议有问题,则填入ex参数,当前连接会因此断开。 25 | /// 26 | /// 需要检查完整性的数据 27 | /// 用户自定义异常 28 | /// 如果能够得到包长,则返回包的在buffer中的长度(包含包头),否则返回0继续等待数据。 29 | int Input(byte[] source, out Exception ex); 30 | 31 | /// 32 | /// 序列化消息包。 33 | /// 如果协议有问题,则填入ex参数,当前连接会因此断开。 34 | /// 35 | /// 需要序列化的消息包。 36 | /// 用户自定义异常。 37 | /// 序列化后的消息包字节流。如果需要抛弃数据包则返回null。 38 | byte[] Encode(object packet, out Exception ex); 39 | 40 | /// 41 | /// 反序列化消息包(包体)。 42 | /// 如果协议有问题,则填入ex参数,当前连接会因此断开。 43 | /// 44 | /// 需要反序列化的数据。 45 | /// 用户自定义异常。 46 | /// 反序列化后的消息包。如果需要抛弃数据包则返回null。 47 | object Decode(byte[] source, out Exception ex); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.Reflection; 13 | using System.Runtime.InteropServices; 14 | 15 | [assembly: AssemblyTitle("CatLib.API")] 16 | [assembly: AssemblyDescription("CatLib Component-Based Framework API")] 17 | [assembly: AssemblyConfiguration("")] 18 | [assembly: AssemblyCompany("CatLib")] 19 | [assembly: AssemblyProduct("CatLib.Framework.API")] 20 | [assembly: AssemblyCopyright("Copyright © CatLib 2017")] 21 | [assembly: AssemblyTrademark("")] 22 | [assembly: AssemblyCulture("")] 23 | 24 | [assembly: ComVisible(false)] 25 | 26 | [assembly: Guid("5bf5d9dc-26f3-46ae-a735-fe37b0d4fe2e")] 27 | 28 | [assembly: AssemblyVersion("1.1.2.0")] 29 | [assembly: AssemblyFileVersion("1.1.2.0")] -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Random/IRandom.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Random 13 | { 14 | /// 15 | /// 随机算法 16 | /// 17 | public interface IRandom 18 | { 19 | /// 20 | /// 返回一个随机数 21 | /// 22 | /// 随机数 23 | int Next(); 24 | 25 | /// 26 | /// 返回一个随机数 27 | /// 28 | /// 最大值(不包含) 29 | /// 随机数 30 | int Next(int maxValue); 31 | 32 | /// 33 | /// 返回一个随机数 34 | /// 35 | /// 最小值(包含) 36 | /// 最大值(不包含) 37 | /// 随机数 38 | int Next(int minValue, int maxValue); 39 | 40 | /// 41 | /// 生成随机数填充流 42 | /// 43 | /// 流 44 | void NextBytes(byte[] buffer); 45 | 46 | /// 47 | /// 返回一个介于0(包含)到1(不包含)之间的随机数 48 | /// 49 | /// 随机数 50 | double NextDouble(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Random/IRandomFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Random 13 | { 14 | /// 15 | /// 随机算法生成器 16 | /// 17 | public interface IRandomFactory : IRandom 18 | { 19 | /// 20 | /// 生成随机算法 21 | /// 22 | /// 随机数算法 23 | IRandom Make(); 24 | 25 | /// 26 | /// 生成随机算法 27 | /// 28 | /// 算法类型 29 | /// 随机数算法 30 | IRandom Make(RandomTypes type); 31 | 32 | /// 33 | /// 生成随机算法 34 | /// 35 | /// 随机数算法 36 | IRandom Make(int seed, RandomTypes type); 37 | 38 | /// 39 | /// 返回一个随机数 40 | /// 41 | /// 使用的随机算法类型 42 | /// 随机数 43 | int Next(RandomTypes type); 44 | 45 | /// 46 | /// 返回一个随机数 47 | /// 48 | /// 最大值(不包含) 49 | /// 使用的随机算法类型 50 | /// 随机数 51 | int Next(int maxValue, RandomTypes type); 52 | 53 | /// 54 | /// 返回一个随机数 55 | /// 56 | /// 最小值(包含) 57 | /// 最大值(不包含) 58 | /// 使用的随机算法类型 59 | /// 随机数 60 | int Next(int minValue, int maxValue, RandomTypes type); 61 | 62 | /// 63 | /// 生成随机数填充流 64 | /// 65 | /// 流 66 | /// 使用的随机算法类型 67 | void NextBytes(byte[] buffer, RandomTypes type); 68 | 69 | /// 70 | /// 返回一个介于0(包含)到1(不包含)之间的随机数 71 | /// 72 | /// 使用的随机算法类型 73 | /// 随机数 74 | double NextDouble(RandomTypes type); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Random/RandomTypes.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Random 13 | { 14 | /// 15 | /// 随机算法类型 16 | /// 17 | public class RandomTypes : Enum 18 | { 19 | /// 20 | /// 马特赛特旋转演算法 21 | /// 22 | public static readonly RandomTypes MersenneTwister = new RandomTypes("MersenneTwister"); 23 | 24 | /// 25 | /// Xorshift 26 | /// 27 | public static readonly RandomTypes Xorshift = new RandomTypes("Xorshift"); 28 | 29 | /// 30 | /// Wichmann-Hill 31 | /// 32 | public static readonly RandomTypes WH2006 = new RandomTypes("WH2006"); 33 | 34 | /// 35 | /// 均匀随机数发生器(产数效率较低) 36 | /// 37 | public static readonly RandomTypes Mrg32k3a = new RandomTypes("Mrg32k3a"); 38 | 39 | /// 40 | /// 随机算法类型 41 | /// 42 | /// 随机算法名字 43 | protected RandomTypes(string name) : base(name) 44 | { 45 | } 46 | 47 | /// 48 | /// 字符串转RandomTypes 49 | /// 50 | /// 类型 51 | public static implicit operator RandomTypes(string type) 52 | { 53 | return new RandomTypes(type); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/EventArgs/DispatchEventArgs.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Routing 15 | { 16 | /// 17 | /// 调度事件 18 | /// 19 | public sealed class DispatchEventArgs : EventArgs 20 | { 21 | /// 22 | /// 路由器 23 | /// 24 | public IRouter Router { get; private set; } 25 | 26 | /// 27 | /// 异常 28 | /// 29 | public IRoute Route { get; private set; } 30 | 31 | /// 32 | /// 请求 33 | /// 34 | public IRequest Request { get; private set; } 35 | 36 | /// 37 | /// 请求 38 | /// 39 | /// 路由器 40 | /// 路由 41 | /// 请求 42 | public DispatchEventArgs(IRouter router, IRoute route, IRequest request) 43 | { 44 | Router = router; 45 | Route = route; 46 | Request = request; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Exception/DomainException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Routing 13 | { 14 | /// 15 | /// 参数范围及域异常 16 | /// 17 | public sealed class DomainException : RuntimeException 18 | { 19 | /// 20 | /// 创建一个参数范围及域异常 21 | /// 22 | /// 错误描述 23 | public DomainException(string message) : base(message) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Exception/NotFoundRouteException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Routing 13 | { 14 | /// 15 | /// 未能找到路由条目 16 | /// 17 | public sealed class NotFoundRouteException : RuntimeException 18 | { 19 | /// 20 | /// 未能找到路由条目 21 | /// 22 | /// 异常消息 23 | public NotFoundRouteException(string message) : base(message) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Exception/UndefinedDefaultSchemeException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Routing 13 | { 14 | /// 15 | /// 未定义默认的Scheme 16 | /// 17 | public sealed class UndefinedDefaultSchemeException : RuntimeException 18 | { 19 | /// 20 | /// 未定义默认的Scheme 21 | /// 22 | /// 异常消息 23 | public UndefinedDefaultSchemeException(string message) : base(message) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Features/IMiddleware.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Routing 13 | { 14 | /// 15 | /// 中间件 16 | /// 17 | public interface IMiddleware 18 | { 19 | /// 20 | /// 路由请求过滤链 21 | /// 22 | IFilterChain Middleware { get; } 23 | } 24 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Features/RoutedAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Routing 15 | { 16 | /// 17 | /// 路由标记 18 | /// 19 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = true)] 20 | public class RoutedAttribute : Attribute 21 | { 22 | /// 23 | /// 路由组 24 | /// 25 | public string Group { get; set; } 26 | 27 | /// 28 | /// 条件 29 | /// 30 | public string Where { get; set; } 31 | 32 | /// 33 | /// 默认值 34 | /// 35 | public string Defaults { get; set; } 36 | 37 | /// 38 | /// 路径 39 | /// 40 | public string Path { get; set; } 41 | 42 | /// 43 | /// 路由 44 | /// 45 | public RoutedAttribute() 46 | { 47 | } 48 | 49 | /// 50 | /// 路由路径 51 | /// 52 | /// 53 | public RoutedAttribute(string path) 54 | { 55 | Path = path; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Internal/IResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Routing 13 | { 14 | /// 15 | /// 响应 16 | /// 17 | public interface IResponse 18 | { 19 | /// 20 | /// 获取上下文 21 | /// 22 | /// 上下文 23 | object GetContext(); 24 | 25 | /// 26 | /// 设定上下文 27 | /// 28 | /// 29 | void SetContext(object context); 30 | } 31 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Internal/IRoute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Routing 15 | { 16 | /// 17 | /// 路由条目 18 | /// 19 | public interface IRoute 20 | { 21 | /// 22 | /// 将当前路由条目追加到指定路由组中 23 | /// 24 | /// 名字 25 | /// 路由条目实例 26 | IRoute Group(string name); 27 | 28 | /// 29 | /// 设定默认值 30 | /// 31 | /// 参数名 32 | /// 默认值 33 | /// 是否覆盖 34 | /// 路由条目实例 35 | IRoute Defaults(string name, string val, bool overrided = true); 36 | 37 | /// 38 | /// 约束指定参数必须符合指定模式才会被路由 39 | /// 40 | /// 名字 41 | /// 约束参数 42 | /// 是否覆盖 43 | /// 路由条目实例 44 | IRoute Where(string name, string pattern, bool overrided = true); 45 | 46 | /// 47 | /// 路由中间件 48 | /// 49 | /// 执行的处理函数 50 | /// 优先级(值越小越优先) 51 | /// 路由条目实例 52 | IRoute Middleware(Action> middleware, int priority = int.MaxValue); 53 | 54 | /// 55 | /// 当路由出现错误时 56 | /// 57 | /// 执行的处理函数 58 | /// 优先级(值越小越优先) 59 | /// 路由条目实例 60 | IRoute OnError(Action> onError, int priority = int.MaxValue); 61 | } 62 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Routing/Internal/IRouteGroup.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Routing 15 | { 16 | /// 17 | /// 路由组 18 | /// 19 | public interface IRouteGroup 20 | { 21 | /// 22 | /// 增加路由条目到路由组中 23 | /// 24 | /// 路由条目 25 | /// 当前路由组实例 26 | IRouteGroup AddRoute(IRoute route); 27 | 28 | /// 29 | /// 设定参数的默认值 30 | /// 31 | /// 参数名 32 | /// 参数值 33 | /// 当前路由组实例 34 | IRouteGroup Defaults(string name, string val); 35 | 36 | /// 37 | /// 约束指定参数必须符合正则表达式 38 | /// 39 | /// 参数名 40 | /// 约束的正则表达式 41 | /// 当前路由组实例 42 | IRouteGroup Where(string name, string pattern); 43 | 44 | /// 45 | /// 添加路由中间件 46 | /// 47 | /// 中间件 48 | /// 优先级(值越小越优先) 49 | /// 当前路由组实例 50 | IRouteGroup Middleware(Action> middleware, int priority = int.MaxValue); 51 | 52 | /// 53 | /// 当路由出现错误时 54 | /// 55 | /// 错误处理函数 56 | /// 优先级(值越小越优先) 57 | /// 当前路由组实例 58 | IRouteGroup OnError(Action> onError, int priority = int.MaxValue); 59 | } 60 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Socket/ISocket.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.API.Socket 15 | { 16 | /// 17 | /// 套接字服务 18 | /// 19 | public interface ISocket 20 | { 21 | /// 22 | /// 是否已经链接远端主机 23 | /// 24 | bool Connected { get; } 25 | 26 | /// 27 | /// 建立链接 28 | /// 29 | /// 异步等待接口 30 | IAwait Connect(); 31 | 32 | /// 33 | /// 建立链接 34 | /// 35 | /// 服务器地址 36 | /// 服务器端口 37 | /// 异步等待接口 38 | IAwait Connect(string hostname, int port); 39 | 40 | /// 41 | /// 异步发送 42 | /// 43 | /// 发送数据 44 | /// 异步等待接口 45 | IAwait Send(byte[] data); 46 | 47 | /// 48 | /// 断开链接 49 | /// 50 | void Disconnect(); 51 | 52 | /// 53 | /// 注册一条事件 54 | /// 55 | /// Socket事件 56 | /// 回调函数 57 | void On(SocketEvents socketEvent, Action callback); 58 | 59 | /// 60 | /// 反注册一条事件 61 | /// 62 | /// Socket事件 63 | /// 回调函数 64 | void Off(SocketEvents socketEvent, Action callback); 65 | 66 | /// 67 | /// 触发一个Socket事件 68 | /// 69 | /// Socket事件 70 | /// 载荷 71 | void Trigger(SocketEvents socketEvent, object payload); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Socket/ISocketManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Socket 13 | { 14 | /// 15 | /// Socket管理器 16 | /// 17 | public interface ISocketManager : ISingleManager 18 | { 19 | /// 20 | /// 建立链接 21 | /// 22 | /// 23 | /// 网络服务提供商 24 | /// tcp://localhost:9999 25 | /// kcp://localhost:9999 26 | /// ws://localhost:9999 27 | /// wss://localhost:9999 28 | /// 29 | /// 名字 30 | /// Socket链接 31 | ISocket Make(string nsp, string name = null); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Tick/ITick.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib 13 | { 14 | /// 15 | /// 滴答 16 | /// 17 | public interface ITick 18 | { 19 | /// 20 | /// 滴答间流逝的时间 21 | /// 22 | /// 滴答间流逝的时间(MS) 23 | void Tick(int elapseMillisecond); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CatLib.Framework.API/Translation/Features/ITranslateResources.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.API.Translation 13 | { 14 | /// 15 | /// 翻译映射 16 | /// 17 | public interface ITranslateResources 18 | { 19 | /// 20 | /// 获取映射 21 | /// 22 | /// 语言 23 | /// 键 24 | /// 返回的值 25 | /// 是否成功获取 26 | bool TryGetValue(string locale, string key, out string str); 27 | } 28 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.API/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Compress/CompressProviderTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Compress; 13 | using CatLib.Compress; 14 | using Microsoft.VisualStudio.TestTools.UnitTesting; 15 | 16 | namespace CatLib.Tests.Compress 17 | { 18 | [TestClass] 19 | public class CompressProviderTests 20 | { 21 | /// 22 | /// 准备环境 23 | /// 24 | /// 25 | public IApplication MakeEnv() 26 | { 27 | var app = new Application(); 28 | app.Bootstrap(); 29 | app.Register(new CompressProvider()); 30 | app.Init(); 31 | return app; 32 | } 33 | 34 | [TestMethod] 35 | public void TestGZipCompress() 36 | { 37 | TestCompress("gzip"); 38 | } 39 | 40 | [TestMethod] 41 | public void TestLzmaCompress() 42 | { 43 | TestCompress("lzma"); 44 | } 45 | 46 | private void TestCompress(string name = null) 47 | { 48 | var app = MakeEnv(); 49 | var manager = app.Make(); 50 | var compress = manager.Compress(System.Text.Encoding.Default.GetBytes("helloworld,helloworld,helloworld,helloworld,helloworld"), name); 51 | Assert.AreEqual(true, compress.Length < "helloworld,helloworld,helloworld,helloworld,helloworld".Length); 52 | Assert.AreEqual("helloworld,helloworld,helloworld,helloworld,helloworld", System.Text.Encoding.Default.GetString(manager.Decomporess(compress, name))); 53 | } 54 | 55 | [TestMethod] 56 | public void TestMakeFromICompress() 57 | { 58 | var app = MakeEnv(); 59 | var manager = app.Make(); 60 | Assert.AreSame(manager.Default, app.Make()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Debugger/DebuggerHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.Debugger; 13 | using CatLib.Json; 14 | using CatLib.Routing; 15 | using System; 16 | 17 | namespace CatLib.Tests.Debugger 18 | { 19 | public static class DebuggerHelper 20 | { 21 | public static Application GetApplication(bool enableWebConsole = true) 22 | { 23 | var app = new Application(); 24 | app.OnFindType((str) => { return Type.GetType(str);}); 25 | app.Bootstrap(); 26 | app.Register(new RoutingProvider()); 27 | app.Register(new JsonProvider()); 28 | app.Register(new DebuggerProvider 29 | { 30 | WebConsoleEnable = enableWebConsole 31 | }); 32 | app.Init(); 33 | return app; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Debugger/WebConsole/HttpListenerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using System.Net; 14 | using System.Threading; 15 | using HttpListener = CatLib.Debugger.WebConsole.HttpListener; 16 | using Microsoft.VisualStudio.TestTools.UnitTesting; 17 | 18 | namespace CatLib.Tests.Debugger.WebConsole 19 | { 20 | [TestClass] 21 | public class HttpListenerTests 22 | { 23 | private AutoResetEvent wait = new AutoResetEvent(false); 24 | 25 | [TestMethod] 26 | public void TestHttpListener() 27 | { 28 | var listener = new HttpListener("localhost", 9478); 29 | listener.OnRequest += OnRequest; 30 | 31 | string ret; 32 | var statu = HttpHelper.Get("http://localhost:9478", out ret); 33 | wait.WaitOne(); 34 | listener.Dispose(); 35 | 36 | Assert.AreEqual(HttpStatusCode.OK, statu); 37 | } 38 | 39 | private void OnRequest(HttpListenerContext context) 40 | { 41 | context.Response.StatusCode = (int)HttpStatusCode.OK; 42 | context.Response.OutputStream.Close(); 43 | wait.Set(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Debugger/WebLog/Controller/UtilTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.Net; 13 | using CatLib.Debugger.WebConsole; 14 | using Microsoft.VisualStudio.TestTools.UnitTesting; 15 | 16 | namespace CatLib.Tests.Debugger.WebLog.Controller 17 | { 18 | [TestClass] 19 | public class UtilTests 20 | { 21 | [TestMethod] 22 | public void TestEcho() 23 | { 24 | var app = DebuggerHelper.GetApplication(); 25 | var console = app.Make(); 26 | 27 | string ret; 28 | var statu = HttpHelper.Get("http://localhost:9478/debug/util/echo/helloworld", out ret); 29 | 30 | console.Stop(); 31 | Assert.AreEqual(HttpStatusCode.OK, statu); 32 | Assert.AreEqual(string.Empty, ret); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Debugger/WebLog/LogStoreTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Debugger; 13 | using CatLib.Debugger.Log; 14 | using CatLib.Debugger.WebLog; 15 | using Microsoft.VisualStudio.TestTools.UnitTesting; 16 | 17 | namespace CatLib.Tests.Debugger.WebLog 18 | { 19 | [TestClass] 20 | public class LogStoreTests 21 | { 22 | [TestMethod] 23 | public void TestLogOverflow() 24 | { 25 | var store = new LogStore(new Logger()); 26 | 27 | store.SetMaxStore(10); 28 | 29 | for (var i = 0; i < 20; i++) 30 | { 31 | store.Log(new LogEntry(LogLevels.Info, "hello", 0)); 32 | } 33 | 34 | Assert.AreEqual(10, store.GetUnloadEntrysByClientId("test").Count); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Debugger/WebMonitor/Handler/SizeMonitorHandlerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.Debugger.WebMonitor.Handler; 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; 14 | 15 | namespace CatLib.Tests.Debugger.WebMonitor.Handler 16 | { 17 | [TestClass] 18 | public class SizeMonitorHandlerTests 19 | { 20 | [TestMethod] 21 | public void TestSizeBound() 22 | { 23 | var monitor = new SizeMonitorHandler("test", new[] { "test" }, () => 24 | { 25 | return (long)1024; 26 | }); 27 | 28 | Assert.AreEqual("1.00", monitor.Value); 29 | Assert.AreEqual("unit.size.kb", monitor.Unit); 30 | } 31 | 32 | [TestMethod] 33 | public void TestSizeBoundSmall() 34 | { 35 | var monitor = new SizeMonitorHandler("test", new[] { "test" }, () => 36 | { 37 | return 512; 38 | }); 39 | 40 | Assert.AreEqual("512.00", monitor.Value); 41 | Assert.AreEqual("unit.size.b", monitor.Unit); 42 | } 43 | 44 | [TestMethod] 45 | public void TestSizeBoundLarge() 46 | { 47 | var monitor = new SizeMonitorHandler("test", new[] { "test" }, () => 48 | { 49 | return long.MaxValue; 50 | }); 51 | 52 | Assert.AreEqual("1024.00", monitor.Value); 53 | Assert.AreEqual("unit.size.pb", monitor.Unit); 54 | } 55 | 56 | [TestMethod] 57 | public void TestGetTagName() 58 | { 59 | var monitor = new SizeMonitorHandler("test", new[] { "tag" }, () => 60 | { 61 | return 512; 62 | }); 63 | 64 | Assert.AreEqual("test", monitor.Name); 65 | Assert.AreEqual("tag", monitor.Tags[0]); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/FileSystem/FileSystemTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using CatLib.FileSystem.Adapter; 14 | using SIO = System.IO; 15 | using Microsoft.VisualStudio.TestTools.UnitTesting; 16 | 17 | namespace CatLib.Tests.FileSystem 18 | { 19 | [TestClass] 20 | public class FileSystemTests 21 | { 22 | private global::CatLib.FileSystem.FileSystem fileSystem; 23 | 24 | [TestMethod] 25 | public void FileSystemCreateDirTest() 26 | { 27 | Env(() => 28 | { 29 | Assert.AreEqual(false, fileSystem.Exists("FileSystemCreateDirTest-dir")); 30 | fileSystem.MakeDir("FileSystemCreateDirTest-dir"); 31 | Assert.AreEqual(true, fileSystem.Exists("FileSystemCreateDirTest-dir")); 32 | 33 | Assert.AreEqual(false, fileSystem.Exists("FileSystemCreateDirTest2-dir/hello/world")); 34 | fileSystem.MakeDir("FileSystemCreateDirTest2-dir/hello/world"); 35 | Assert.AreEqual(true, fileSystem.Exists("FileSystemCreateDirTest2-dir/hello/world")); 36 | }); 37 | } 38 | 39 | private void Env(Action action) 40 | { 41 | var path = SIO.Path.Combine(System.Environment.CurrentDirectory, "FileSystemTest"); 42 | if (SIO.Directory.Exists(path)) 43 | { 44 | SIO.Directory.Delete(path, true); 45 | } 46 | SIO.Directory.CreateDirectory(path); 47 | 48 | var local = new Local(path); 49 | fileSystem = new global::CatLib.FileSystem.FileSystem(local); 50 | 51 | action.Invoke(); 52 | 53 | if (SIO.Directory.Exists(path)) 54 | { 55 | SIO.Directory.Delete(path, true); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/HttpHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.IO; 13 | using System.Net; 14 | using System.Text; 15 | 16 | namespace CatLib.Tests 17 | { 18 | /// 19 | /// http帮助器 20 | /// 21 | public static class HttpHelper 22 | { 23 | /// 24 | /// 以get的方式请求服务器 25 | /// 26 | /// 请求地址 27 | /// 请求结果 28 | /// http状态码 29 | public static HttpStatusCode Get(string url, out string ret) 30 | { 31 | var request = (HttpWebRequest)WebRequest.Create(url); 32 | request.Method = "get"; 33 | request.ContentType = "text/html;charset=utf-8"; 34 | 35 | var response = (HttpWebResponse)request.GetResponse(); 36 | var responseStream = response.GetResponseStream(); 37 | var responseReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")); 38 | ret = responseReader.ReadToEnd(); 39 | responseReader.Close(); 40 | responseReader.Close(); 41 | 42 | return response.StatusCode; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Network/Packer/FramePackerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using System.Text; 14 | using CatLib.Network.Packer; 15 | using Microsoft.VisualStudio.TestTools.UnitTesting; 16 | 17 | namespace CatLib.Tests.Network.Packer 18 | { 19 | [TestClass] 20 | public class FramePackerTests 21 | { 22 | [TestMethod] 23 | public void InputTests() 24 | { 25 | var packer = new FramePacker(); 26 | Exception ex; 27 | var length = packer.Input(Arr.Merge(BitConverter.GetBytes(14), Encoding.Default.GetBytes("helloworld")), out ex); 28 | Assert.AreEqual(14, length); 29 | } 30 | 31 | [TestMethod] 32 | public void DecodeTest() 33 | { 34 | var packer = new FramePacker(); 35 | Exception ex; 36 | var data = packer.Decode(Arr.Merge(BitConverter.GetBytes(14), Encoding.Default.GetBytes("helloworld")), out ex); 37 | Assert.AreEqual("helloworld", Encoding.Default.GetString((byte[])data)); 38 | } 39 | 40 | [TestMethod] 41 | public void EncodeTest() 42 | { 43 | var packer = new FramePacker(); 44 | Exception ex; 45 | var data = packer.Encode(Encoding.Default.GetBytes("helloworld"), out ex); 46 | Assert.AreEqual("14helloworld", 47 | BitConverter.ToInt32(Arr.Slice(data, 0, 4), 0) + Encoding.Default.GetString(Arr.Slice(data, 4))); 48 | } 49 | 50 | [TestMethod] 51 | public void TestEncodeNullData() 52 | { 53 | var packer = new FramePacker(); 54 | Exception ex; 55 | var data = packer.Encode(null, out ex); 56 | 57 | Assert.AreEqual(null, data); 58 | Assert.AreNotEqual(null, ex); 59 | } 60 | 61 | [TestMethod] 62 | public void TestInputNullData() 63 | { 64 | var packer = new FramePacker(); 65 | Exception ex; 66 | var data = packer.Input(null, out ex); 67 | 68 | Assert.AreEqual(0, data); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Network/Packer/TextPackerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using System.Text; 14 | using CatLib.Network.Packer; 15 | using Microsoft.VisualStudio.TestTools.UnitTesting; 16 | 17 | namespace CatLib.Tests.Network.Packer 18 | { 19 | [TestClass] 20 | public class TextPackerTests 21 | { 22 | [TestMethod] 23 | public void InputTests() 24 | { 25 | var packer = new TextPacker(); 26 | Exception ex; 27 | var length = packer.Input(Encoding.Default.GetBytes("hello\nworld"), out ex); 28 | Assert.AreEqual(6, length); 29 | 30 | length = packer.Input(Encoding.Default.GetBytes("helloworld"), out ex); 31 | Assert.AreEqual(0, length); 32 | } 33 | 34 | [TestMethod] 35 | public void DecodeTest() 36 | { 37 | var packer = new TextPacker(); 38 | Exception ex; 39 | var data = packer.Decode(Encoding.Default.GetBytes("hello\n"), out ex); 40 | Assert.AreEqual("hello", Encoding.Default.GetString((byte[])data)); 41 | } 42 | 43 | [TestMethod] 44 | public void EncodeTest() 45 | { 46 | var packer = new TextPacker(); 47 | Exception ex; 48 | var data = packer.Encode(Encoding.Default.GetBytes("helloworld"), out ex); 49 | Assert.AreEqual("helloworld\n", Encoding.Default.GetString((byte[])data)); 50 | } 51 | 52 | [TestMethod] 53 | public void MulDataInput() 54 | { 55 | var packer = new TextPacker(); 56 | Exception ex; 57 | var data = packer.Input(Encoding.Default.GetBytes("hello"), out ex); 58 | Assert.AreEqual(0, data); 59 | data = packer.Input(Encoding.Default.GetBytes("helloworld\n"), out ex); 60 | Assert.AreEqual(11, data); 61 | } 62 | 63 | [TestMethod] 64 | public void TestEncodeNullData() 65 | { 66 | var packer = new TextPacker(); 67 | Exception ex; 68 | var data = packer.Encode(null, out ex); 69 | 70 | Assert.AreEqual(null, data); 71 | Assert.AreNotEqual(null, ex); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Network/ReceiveStateTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using System.Text; 14 | using CatLib.Network; 15 | using CatLib.Network.Packer; 16 | using Microsoft.VisualStudio.TestTools.UnitTesting; 17 | 18 | namespace CatLib.Tests.Network 19 | { 20 | [TestClass] 21 | public class ReceiveStateTests 22 | { 23 | [TestMethod] 24 | public void MulReceiveTests() 25 | { 26 | var state = new ReceiveState(new TextPacker()); 27 | Exception ex; 28 | var result = state.Input(Encoding.Default.GetBytes("hello"), out ex); 29 | Assert.AreEqual(null, result); 30 | result = state.Input(Encoding.Default.GetBytes("world\n"), out ex); 31 | Assert.AreEqual("helloworld", Encoding.Default.GetString((byte[])result[0])); 32 | result = state.Input(Encoding.Default.GetBytes("hello"), out ex); 33 | Assert.AreEqual(null, result); 34 | result = state.Input(Encoding.Default.GetBytes("shanghai\n"), out ex); 35 | Assert.AreEqual("helloshanghai", Encoding.Default.GetString((byte[])result[0])); 36 | 37 | result = state.Input(Encoding.Default.GetBytes("shanghai\nchina\n"), out ex); 38 | Assert.AreEqual("shanghai", Encoding.Default.GetString((byte[])result[0])); 39 | Assert.AreEqual("china", Encoding.Default.GetString((byte[])result[1])); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.Reflection; 13 | using System.Runtime.InteropServices; 14 | 15 | [assembly: AssemblyTitle("CatLib.Tests")] 16 | [assembly: AssemblyDescription("CatLib Unit Tests")] 17 | [assembly: AssemblyConfiguration("")] 18 | [assembly: AssemblyCompany("CatLib")] 19 | [assembly: AssemblyProduct("CatLib.Tests")] 20 | [assembly: AssemblyCopyright("Copyright © 2017")] 21 | [assembly: AssemblyTrademark("")] 22 | [assembly: AssemblyCulture("")] 23 | 24 | [assembly: ComVisible(false)] 25 | 26 | [assembly: Guid("8d8774b0-b6ce-4571-89f6-f3707fffc167")] 27 | 28 | [assembly: AssemblyVersion("1.1.2.0")] 29 | [assembly: AssemblyFileVersion("1.1.2.0")] 30 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/AttrCompilerRouting.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; 14 | 15 | namespace CatLib.Tests.Routing 16 | { 17 | [Routed] 18 | public class AttrCompilerRouting 19 | { 20 | [Routed("routed://first-compiler-then-group/{str?}", Group = "DefaultGroup")] 21 | public void FirstCompilerThenAddGroup(IRequest request, IResponse response) 22 | { 23 | response.SetContext(request["str"]); 24 | } 25 | 26 | [Routed("routed://use-group-and-local-defaults/{str?}", Group = "DefaultGroup2", Defaults = "str=>hello world")] 27 | public void UseGroupAndLocalDefaults(IRequest request, IResponse response) 28 | { 29 | response.SetContext(request["str"]); 30 | } 31 | 32 | // 可变类型测试 33 | public class VariantType : IVariant 34 | { 35 | public string Value; 36 | public VariantType(int data) 37 | { 38 | Value = data < 100 ? "less 100" : "bigger 100"; 39 | } 40 | } 41 | 42 | [Routed("routed://autoinject/{key}/{value}")] 43 | public string TestAutoInject(string key, VariantType value) 44 | { 45 | Assert.AreEqual("hello", key); 46 | return value.Value; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/OptionsParamsAttrRouting.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Tests.Routing 15 | { 16 | /// 17 | /// 可选的参数接受 18 | /// 19 | [Routed] 20 | public class OptionsParamsAttrRouting 21 | { 22 | [Routed] 23 | public void Call(IRequest request) 24 | { 25 | 26 | } 27 | 28 | [Routed] 29 | public void CallNull() 30 | { 31 | 32 | } 33 | 34 | [Routed] 35 | public void CallResponseAndApp(IApplication app, IResponse response) 36 | { 37 | response.SetContext(app.ToString()); 38 | } 39 | 40 | [Routed] 41 | public void CallResponse(IResponse response) 42 | { 43 | response.SetContext("OptionsParamsAttrRouting.CallResponse"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/ParamsAttrRouting.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Tests.Routing 15 | { 16 | //1.越接近方法的路由定义的优先级越高 17 | //2.代码中的参数定义要比组的优先级高,如果违反第1条那么使用第1条规则 18 | 19 | //定义了类的路由约束,如果在方法上没有覆盖这些参数那么将会使用类的路由约束 20 | [Routed(Defaults = "str=>world,val=>hello", Where = "age=>[0-9]+,val=>[0-9]+")] 21 | public class ParamsAttrRouting 22 | { 23 | //您也可以在路由方法中强制指定scheme,这样她会忽略来自class中定义的scheme。 24 | //与此同时我们还为age定义了正则约束,如果您填写了age这个参数那么他必须受到正则约束才能匹配 25 | //age是必须参数所以没有必要定义default值。 26 | [Routed("catlib://params-attr-routing/params-call/{age}/{val?}/{str?}", 27 | Defaults = "str=>catlib")] 28 | public void ParamsCall(IRequest request, IResponse response) 29 | { 30 | response.SetContext("ParamsAttrRouting.ParamsCall." + request["age"] + "." + request["val"] + "." + request["str"]); 31 | } 32 | 33 | [Routed("catlib://params-attr-routing/params-call-with-group/{age}/{val?}/{str?}", Group = "default-group")] 34 | public void ParamsCallWithGroup(IRequest request, IResponse response) 35 | { 36 | response.SetContext("ParamsAttrRouting.ParamsCall." + request["age"] + "." + request["val"] + "." + request["str"]); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/RouteCompilerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | using CatLib.Routing; 14 | using Microsoft.VisualStudio.TestTools.UnitTesting; 15 | 16 | namespace CatLib.Tests.Routing 17 | { 18 | [TestClass] 19 | public class RouteCompilerTests 20 | { 21 | /// 22 | /// 触发编译异常的测试 23 | /// 24 | [TestMethod] 25 | public void ThrowErrorCompilerTest() 26 | { 27 | var route = new Route(new Uri("catlib://hello/{10name}"), new RouteAction()); 28 | ExceptionAssert.Throws(() => 29 | { 30 | RouteCompiler.Compile(route); 31 | }); 32 | 33 | route = new Route(new Uri("catlib://hello/{name}/{name}"), new RouteAction()); 34 | ExceptionAssert.Throws(() => 35 | { 36 | RouteCompiler.Compile(route); 37 | }); 38 | 39 | route = new Route(new Uri("catlib://hello/{namejajskajskajskajskajskajskajskauqjsuqkqsuqjs}"), new RouteAction()); 40 | ExceptionAssert.Throws(() => 41 | { 42 | RouteCompiler.Compile(route); 43 | }); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/RoutingMiddleware.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Tests.Routing 15 | { 16 | [Routed("rm://")] 17 | public class RoutingMiddleware : IMiddleware 18 | { 19 | /// 20 | /// 中间件 21 | /// 22 | public IFilterChain Middleware 23 | { 24 | get 25 | { 26 | var filter = new FilterChain(); 27 | filter.Add((req, res, next) => 28 | { 29 | next(req, res); 30 | res.SetContext(res.GetContext() + "[with middleware]"); 31 | }); 32 | return filter; 33 | } 34 | } 35 | 36 | [Routed("call")] 37 | public void Call(IRequest request, IResponse response) 38 | { 39 | response.SetContext("RoutingMiddleware.Call"); 40 | } 41 | 42 | [Routed(Group = "RoutingMiddleware.ClassMiddlewareThenRouteMiddleTest")] 43 | public void ClassMiddlewareThenRouteMiddleTest(IRequest request, IResponse response) 44 | { 45 | response.SetContext("ClassMiddlewareThenRouteMiddleTest"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/RoutingPriortityMiddleware.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Tests.Routing 15 | { 16 | [Routed] 17 | class RoutingPriortityMiddleware : IMiddleware 18 | { 19 | /// 20 | /// 中间件 21 | /// 22 | public IFilterChain Middleware 23 | { 24 | get 25 | { 26 | var filter = new FilterChain(); 27 | filter.Add((req, res, next) => 28 | { 29 | next(req, res); 30 | res.SetContext(res.GetContext() + "[with middleware 15]"); 31 | }, 15); 32 | filter.Add((req, res, next) => 33 | { 34 | next(req, res); 35 | res.SetContext(res.GetContext() + "[with middleware 20]"); 36 | }, 20); 37 | filter.Add((req, res, next) => 38 | { 39 | next(req, res); 40 | res.SetContext(res.GetContext() + "[with middleware 10]"); 41 | }, 10); 42 | return filter; 43 | } 44 | } 45 | 46 | [Routed("call")] 47 | public void Call(IRequest request, IResponse response) 48 | { 49 | response.SetContext("RoutingPriortityMiddleware.Call"); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/TestMiddlewareException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using System.Reflection; 14 | using CatLib.API.Routing; 15 | using CatLib.Routing; 16 | using Microsoft.VisualStudio.TestTools.UnitTesting; 17 | 18 | namespace CatLib.Tests.Routing 19 | { 20 | [TestClass] 21 | public class TestMiddlewareException 22 | { 23 | [TestMethod] 24 | [ExpectedException(typeof(TargetInvocationException))] 25 | public void TestMiddlewareThrow() 26 | { 27 | var app = new Application(); 28 | app.Bootstrap(); 29 | app.OnFindType((t) => 30 | { 31 | return Type.GetType(t); 32 | }); 33 | app.Register(new RoutingProvider()); 34 | var router = app.Make(); 35 | router.Reg("test://throw", () => 36 | { 37 | string str = null; 38 | var l = str.Length; 39 | }); 40 | 41 | router.Dispatch("test://throw"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/UTAttrRoutingSimple.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Tests.Routing 15 | { 16 | // 路由的最简使用方式 17 | // 如果类或者方法没有给定名字那么会自动使用类名或者方法名作为路由路径 18 | // 如下面的路由会被默认给定名字:utattr-routing-simple/call 19 | [Routed] 20 | public class UTAttrRoutingSimple 21 | { 22 | [Routed] 23 | public void Call(IRequest request, IResponse response) 24 | { 25 | response.SetContext("UTAttrRoutingSimple.Call"); 26 | } 27 | 28 | //连续的大写会被视作一个整体最终的路由路径就是:catlib://utattr-routing-simple/call-mtest 29 | [Routed] 30 | public void CallMTest(IRequest request, IResponse response) 31 | { 32 | response.SetContext("UTAttrRoutingSimple.CallMTest"); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/UTMultAttrRoutingSimple.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Tests.Routing 15 | { 16 | // CatLib 路由系统允许添加多个路由名 17 | [Routed] // catlib://utmult-attr-routing-simple 18 | [Routed("uthello-world")] // catlib://hello-world 19 | [Routed("cat://utmult-attr-routing-simple")] // cat://mult-attr-routing-simple 20 | public class UTMultAttrRoutingSimple 21 | { 22 | // catlib://mult-attr-routing-simple/call 23 | // catlib://hello-world/call 24 | // cat://mult-attr-routing-simple/call 25 | [Routed] 26 | // catlib://mult-attr-routing-simple/my-hello 27 | // catlib://hello-world/my-hello 28 | // cat://mult-attr-routing-simple/my-hello 29 | [Routed("my-hello")] 30 | // dog://myname/call 31 | [Routed("dog://utmyname/call")] 32 | public void Call(IRequest request, IResponse response) 33 | { 34 | response.SetContext("UTMultAttrRoutingSimple.Call"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Routing/UriTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.Routing; 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; 14 | 15 | namespace CatLib.Tests.Routing 16 | { 17 | /// 18 | /// Uri测试 19 | /// 20 | [TestClass] 21 | public class UriTests 22 | { 23 | [TestMethod] 24 | public void UriTest() 25 | { 26 | var uri = new Uri("catlib://user:pass@hello/world?get=123#nihao"); 27 | Assert.AreEqual("catlib://hello/world", uri.NoParamFullPath); 28 | int i = 0; 29 | foreach (var s in new[] { "/", "world" }) 30 | { 31 | Assert.AreEqual(s, uri.Segments[i++]); 32 | } 33 | Assert.AreEqual("user:pass", uri.UserInfo); 34 | 35 | uri = new Uri(new System.Uri("catlib://user:pass@hello/world?get=123#nihao")); 36 | Assert.AreEqual("catlib://hello/world", uri.NoParamFullPath); 37 | i = 0; 38 | foreach (var s in new[] { "/", "world" }) 39 | { 40 | Assert.AreEqual(s, uri.Segments[i++]); 41 | } 42 | Assert.AreEqual("user:pass", uri.UserInfo); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/Socket/Util.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.Threading; 13 | 14 | namespace CatLib.Socket.Tests 15 | { 16 | /// 17 | /// 18 | /// 19 | public static class Util 20 | { 21 | /// 22 | /// 等待完成 23 | /// 24 | /// 25 | /// 26 | /// 27 | /// 28 | public static bool Wait(IAwait wait, int maxWaitTimeMs, int sleep = 1) 29 | { 30 | var time = 0; 31 | while (!wait.IsDone && time < maxWaitTimeMs) 32 | { 33 | Thread.Sleep(sleep); 34 | time += sleep; 35 | } 36 | 37 | return wait.IsDone; 38 | } 39 | 40 | public static bool Wait(ref T[] arr, int maxWaitTimeMs, int sleep = 1) 41 | { 42 | var time = 0; 43 | while (arr != null && arr.Length <= 0 && time < maxWaitTimeMs) 44 | { 45 | Thread.Sleep(sleep); 46 | time += sleep; 47 | } 48 | 49 | return arr != null && arr.Length > 0; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/CatLib.Framework.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Common/SevenZip/CBindPair.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.SharpCompress.Common.SevenZip 2 | { 3 | internal class CBindPair 4 | { 5 | internal int InIndex; 6 | internal int OutIndex; 7 | } 8 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Common/SevenZip/CCoderInfo.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.SharpCompress.Common.SevenZip 2 | { 3 | internal class CCoderInfo 4 | { 5 | internal CMethodId MethodId; 6 | internal byte[] Props; 7 | internal int NumInStreams; 8 | internal int NumOutStreams; 9 | } 10 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Common/SevenZip/CMethodId.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.SharpCompress.Common.SevenZip 2 | { 3 | internal struct CMethodId 4 | { 5 | public const ulong kCopyId = 0; 6 | public const ulong kLzmaId = 0x030101; 7 | public const ulong kLzma2Id = 0x21; 8 | public const ulong kAESId = 0x06F10701; 9 | 10 | public static readonly CMethodId kCopy = new CMethodId(kCopyId); 11 | public static readonly CMethodId kLzma = new CMethodId(kLzmaId); 12 | public static readonly CMethodId kLzma2 = new CMethodId(kLzma2Id); 13 | public static readonly CMethodId kAES = new CMethodId(kAESId); 14 | 15 | public readonly ulong Id; 16 | 17 | public CMethodId(ulong id) 18 | { 19 | Id = id; 20 | } 21 | 22 | public override int GetHashCode() 23 | { 24 | return Id.GetHashCode(); 25 | } 26 | 27 | public override bool Equals(object obj) 28 | { 29 | return obj is CMethodId && (CMethodId)obj == this; 30 | } 31 | 32 | public bool Equals(CMethodId other) 33 | { 34 | return Id == other.Id; 35 | } 36 | 37 | public static bool operator ==(CMethodId left, CMethodId right) 38 | { 39 | return left.Id == right.Id; 40 | } 41 | 42 | public static bool operator !=(CMethodId left, CMethodId right) 43 | { 44 | return left.Id != right.Id; 45 | } 46 | 47 | public int GetLength() 48 | { 49 | int bytes = 0; 50 | for (ulong value = Id; value != 0; value >>= 8) 51 | { 52 | bytes++; 53 | } 54 | return bytes; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Compressors/CompressionMode.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.SharpCompress.Compressors 2 | { 3 | /// 4 | /// 5 | /// 6 | public enum CompressionMode 7 | { 8 | /// 9 | /// 10 | /// 11 | Compress = 0, 12 | 13 | /// 14 | /// 15 | /// 16 | Decompress = 1 17 | } 18 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Compressors/LZMA/LZ/CRC.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.SharpCompress.Compressors.LZMA.LZ 2 | { 3 | internal class CRC 4 | { 5 | public static readonly uint[] Table; 6 | 7 | static CRC() 8 | { 9 | Table = new uint[256]; 10 | const uint kPoly = 0xEDB88320; 11 | for (uint i = 0; i < 256; i++) 12 | { 13 | uint r = i; 14 | for (int j = 0; j < 8; j++) 15 | { 16 | if ((r & 1) != 0) 17 | { 18 | r = (r >> 1) ^ kPoly; 19 | } 20 | else 21 | { 22 | r >>= 1; 23 | } 24 | } 25 | Table[i] = r; 26 | } 27 | } 28 | 29 | private uint _value = 0xFFFFFFFF; 30 | 31 | public void Init() 32 | { 33 | _value = 0xFFFFFFFF; 34 | } 35 | 36 | public void UpdateByte(byte b) 37 | { 38 | _value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8); 39 | } 40 | 41 | public void Update(byte[] data, uint offset, uint size) 42 | { 43 | for (uint i = 0; i < size; i++) 44 | { 45 | _value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8); 46 | } 47 | } 48 | 49 | public uint GetDigest() 50 | { 51 | return _value ^ 0xFFFFFFFF; 52 | } 53 | 54 | private static uint CalculateDigest(byte[] data, uint offset, uint size) 55 | { 56 | CRC crc = new CRC(); 57 | 58 | // crc.Init(); 59 | crc.Update(data, offset, size); 60 | return crc.GetDigest(); 61 | } 62 | 63 | private static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size) 64 | { 65 | return (CalculateDigest(data, offset, size) == digest); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Compressors/LZMA/Log.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace CatLib._3rd.SharpCompress.Compressors.LZMA 6 | { 7 | internal static class Log 8 | { 9 | private static readonly Stack _indent = new Stack(); 10 | private static bool _needsIndent = true; 11 | 12 | static Log() 13 | { 14 | _indent.Push(""); 15 | } 16 | 17 | public static void PushIndent(string indent = " ") 18 | { 19 | _indent.Push(_indent.Peek() + indent); 20 | } 21 | 22 | public static void PopIndent() 23 | { 24 | if (_indent.Count == 1) 25 | { 26 | throw new InvalidOperationException(); 27 | } 28 | 29 | _indent.Pop(); 30 | } 31 | 32 | private static void EnsureIndent() 33 | { 34 | if (_needsIndent) 35 | { 36 | _needsIndent = false; 37 | } 38 | } 39 | 40 | public static void Write(object value) 41 | { 42 | EnsureIndent(); 43 | } 44 | 45 | public static void Write(string text) 46 | { 47 | EnsureIndent(); 48 | } 49 | 50 | public static void Write(string format, params object[] args) 51 | { 52 | EnsureIndent(); 53 | } 54 | 55 | public static void WriteLine() 56 | { 57 | Debug.WriteLine(""); 58 | _needsIndent = true; 59 | } 60 | 61 | public static void WriteLine(object value) 62 | { 63 | EnsureIndent(); 64 | Debug.WriteLine(value); 65 | _needsIndent = true; 66 | } 67 | 68 | public static void WriteLine(string text) 69 | { 70 | EnsureIndent(); 71 | Debug.WriteLine(text); 72 | _needsIndent = true; 73 | } 74 | 75 | public static void WriteLine(string format, params object[] args) 76 | { 77 | EnsureIndent(); 78 | Debug.WriteLine(string.Format(format, args)); 79 | _needsIndent = true; 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Compressors/LZMA/Registry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using CatLib._3rd.SharpCompress.Common.SevenZip; 5 | using CatLib._3rd.SharpCompress.Compressors.LZMA.Utilites; 6 | 7 | namespace CatLib._3rd.SharpCompress.Compressors.LZMA 8 | { 9 | internal static class DecoderRegistry 10 | { 11 | private const uint k_Copy = 0x0; 12 | private const uint k_LZMA2 = 0x21; 13 | private const uint k_LZMA = 0x030101; 14 | private const uint k_BCJ2 = 0x0303011B; 15 | 16 | internal static Stream CreateDecoderStream(CMethodId id, Stream[] inStreams, byte[] info, IPasswordProvider pass, 17 | long limit) 18 | { 19 | switch (id.Id) 20 | { 21 | case k_Copy: 22 | if (info != null) 23 | { 24 | throw new NotSupportedException(); 25 | } 26 | return inStreams.Single(); 27 | case k_LZMA: 28 | case k_LZMA2: 29 | return new LzmaStream(info, inStreams.Single(), -1, limit); 30 | #if !NO_CRYPTO 31 | case CMethodId.kAESId: 32 | return new AesDecoderStream(inStreams.Single(), info, pass, limit); 33 | #endif 34 | case k_BCJ2: 35 | return new Bcj2DecoderStream(inStreams, info, limit); 36 | default: 37 | throw new NotSupportedException(); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/Compressors/LZMA/Utilites/IPasswordProvider.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.SharpCompress.Compressors.LZMA.Utilites 2 | { 3 | internal interface IPasswordProvider 4 | { 5 | string CryptoGetTextPassword(); 6 | } 7 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpCompress/IO/CountingWritableSubStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace CatLib._3rd.SharpCompress.IO 5 | { 6 | internal class CountingWritableSubStream : Stream 7 | { 8 | private readonly Stream writableStream; 9 | 10 | internal CountingWritableSubStream(Stream stream) 11 | { 12 | writableStream = stream; 13 | } 14 | 15 | public ulong Count { get; private set; } 16 | 17 | public override bool CanRead 18 | { 19 | get { return false; } 20 | } 21 | 22 | public override bool CanSeek 23 | { 24 | get { return false; } 25 | } 26 | 27 | public override bool CanWrite 28 | { 29 | get { return true; } 30 | } 31 | 32 | public override void Flush() 33 | { 34 | writableStream.Flush(); 35 | } 36 | 37 | public override long Length 38 | { 39 | get { throw new NotSupportedException(); } 40 | } 41 | 42 | public override long Position 43 | { 44 | get { throw new NotSupportedException(); } 45 | set { throw new NotSupportedException(); } 46 | } 47 | 48 | public override int Read(byte[] buffer, int offset, int count) 49 | { 50 | throw new NotSupportedException(); 51 | } 52 | 53 | public override long Seek(long offset, SeekOrigin origin) 54 | { 55 | throw new NotSupportedException(); 56 | } 57 | 58 | public override void SetLength(long value) 59 | { 60 | throw new NotSupportedException(); 61 | } 62 | 63 | public override void Write(byte[] buffer, int offset, int count) 64 | { 65 | writableStream.Write(buffer, offset, count); 66 | Count += (uint)count; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Checksum.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f5c912e1322c8a74aa7e10b4e2a643c4 3 | folderAsset: yes 4 | timeCreated: 1503583449 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Checksum/Adler32.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6453759b10540d42b4b3c5c4275bd61 3 | timeCreated: 1503583460 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Checksum/Crc32.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6732b24feaaf62c4aa3a963847627a12 3 | timeCreated: 1503583455 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Checksum/IChecksum.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.Checksum 2 | { 3 | /// 4 | /// Interface to compute a data checksum used by checked input/output streams. 5 | /// A data checksum can be updated by one byte or with a byte array. After each 6 | /// update the value of the current checksum can be returned by calling 7 | /// getValue. The complete checksum object can also be reset 8 | /// so it can be used again with new data. 9 | /// 10 | public interface IChecksum 11 | { 12 | /// 13 | /// Resets the data checksum as if no update was ever called. 14 | /// 15 | void Reset(); 16 | 17 | /// 18 | /// Returns the data checksum computed so far. 19 | /// 20 | long Value { 21 | get; 22 | } 23 | 24 | /// 25 | /// Adds one byte to the data checksum. 26 | /// 27 | /// 28 | /// the data value to add. The high byte of the int is ignored. 29 | /// 30 | void Update(int bval); 31 | 32 | /// 33 | /// Updates the data checksum with the bytes taken from the array. 34 | /// 35 | /// 36 | /// buffer an array of bytes 37 | /// 38 | void Update(byte[] buffer); 39 | 40 | /// 41 | /// Adds the byte array to the data checksum. 42 | /// 43 | /// 44 | /// The buffer which contains the data 45 | /// 46 | /// 47 | /// The offset in the buffer where the data starts 48 | /// 49 | /// 50 | /// the number of data bytes to add. 51 | /// 52 | void Update(byte[] buffer, int offset, int count); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Checksum/IChecksum.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e8d7ea2fdcfd87e4d83cfecb67c5a9c3 3 | timeCreated: 1503583463 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1bccb7fd40280e4c8e9a59aefd9053d 3 | folderAsset: yes 4 | timeCreated: 1503583449 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/FileSystemScanner.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ead0e911571f83449d51f7ef2f7e15d 3 | timeCreated: 1503583457 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/INameTransform.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.Core 2 | { 3 | /// 4 | /// INameTransform defines how file system names are transformed for use with archives, or vice versa. 5 | /// 6 | public interface INameTransform 7 | { 8 | /// 9 | /// Given a file name determine the transformed value. 10 | /// 11 | /// The name to transform. 12 | /// The transformed file name. 13 | string TransformFile(string name); 14 | 15 | /// 16 | /// Given a directory name determine the transformed value. 17 | /// 18 | /// The name to transform. 19 | /// The transformed directory name 20 | string TransformDirectory(string name); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/INameTransform.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4d744c0b29c7374f8f1768377847154 3 | timeCreated: 1503583459 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/IScanFilter.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.Core 2 | { 3 | /// 4 | /// Scanning filters support filtering of names. 5 | /// 6 | public interface IScanFilter 7 | { 8 | /// 9 | /// Test a name to see if it 'matches' the filter. 10 | /// 11 | /// The name to test. 12 | /// Returns true if the name matches the filter, false if it does not match. 13 | bool IsMatch(string name); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/IScanFilter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db063ba2334f7954786a4a81f9b3d2db 3 | timeCreated: 1503583462 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/NameFilter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e9e318f2a3b5e54f91e0a3340828984 3 | timeCreated: 1503583457 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/PathFilter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf436f22dfa0aec4d8918b283d41f2b3 3 | timeCreated: 1503583461 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/StreamUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6de96760b130f1a458c0e22435c13c34 3 | timeCreated: 1503583455 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/WindowsPathUtils.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.Core 2 | { 3 | /// 4 | /// WindowsPathUtils provides simple utilities for handling windows paths. 5 | /// 6 | public abstract class WindowsPathUtils 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | internal WindowsPathUtils() 12 | { 13 | } 14 | 15 | /// 16 | /// Remove any path root present in the path 17 | /// 18 | /// A containing path information. 19 | /// The path with the root removed if it was present; path otherwise. 20 | /// Unlike the class the path isnt otherwise checked for validity. 21 | public static string DropPathRoot(string path) 22 | { 23 | string result = path; 24 | 25 | if (!string.IsNullOrEmpty(path)) { 26 | if ((path[0] == '\\') || (path[0] == '/')) { 27 | // UNC name ? 28 | if ((path.Length > 1) && ((path[1] == '\\') || (path[1] == '/'))) { 29 | int index = 2; 30 | int elements = 2; 31 | 32 | // Scan for two separate elements \\machine\share\restofpath 33 | while ((index <= path.Length) && 34 | (((path[index] != '\\') && (path[index] != '/')) || (--elements > 0))) { 35 | index++; 36 | } 37 | 38 | index++; 39 | 40 | if (index < path.Length) { 41 | result = path.Substring(index); 42 | } else { 43 | result = ""; 44 | } 45 | } 46 | } else if ((path.Length > 1) && (path[1] == ':')) { 47 | int dropCount = 2; 48 | if ((path.Length > 2) && ((path[2] == '\\') || (path[2] == '/'))) { 49 | dropCount = 3; 50 | } 51 | result = result.Remove(0, dropCount); 52 | } 53 | } 54 | return result; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Core/WindowsPathUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df4da814438cd7044b558d87165f2f39 3 | timeCreated: 1503583462 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Encryption.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 41a39b2338f6e5344852d8cd3a77b62e 3 | folderAsset: yes 4 | timeCreated: 1503583448 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Encryption/PkzipClassic.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6e32ba138f7a5648a8a9e24982a6eb2 3 | timeCreated: 1503583460 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Encryption/ZipAESTransform.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 828194a14757e10458d4c24006a56775 3 | timeCreated: 1503583457 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ddcd8ee5cfa01d940bb702e9102be938 3 | folderAsset: yes 4 | timeCreated: 1503583449 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip/GZip.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ad1aeda81559fb458bdbae072fc9819 3 | timeCreated: 1503583450 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip/GZipConstants.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.GZip 2 | { 3 | /// 4 | /// This class contains constants used for gzip. 5 | /// 6 | sealed public class GZipConstants 7 | { 8 | /// 9 | /// Magic number found at start of GZIP header 10 | /// 11 | public const int GZIP_MAGIC = 0x1F8B; 12 | 13 | /* The flag byte is divided into individual bits as follows: 14 | 15 | bit 0 FTEXT 16 | bit 1 FHCRC 17 | bit 2 FEXTRA 18 | bit 3 FNAME 19 | bit 4 FCOMMENT 20 | bit 5 reserved 21 | bit 6 reserved 22 | bit 7 reserved 23 | */ 24 | 25 | /// 26 | /// Flag bit mask for text 27 | /// 28 | public const int FTEXT = 0x1; 29 | 30 | /// 31 | /// Flag bitmask for Crc 32 | /// 33 | public const int FHCRC = 0x2; 34 | 35 | /// 36 | /// Flag bit mask for extra 37 | /// 38 | public const int FEXTRA = 0x4; 39 | 40 | /// 41 | /// flag bitmask for name 42 | /// 43 | public const int FNAME = 0x8; 44 | 45 | /// 46 | /// flag bit mask indicating comment is present 47 | /// 48 | public const int FCOMMENT = 0x10; 49 | 50 | /// 51 | /// Initialise default instance. 52 | /// 53 | /// Constructor is private to prevent instances being created. 54 | GZipConstants() 55 | { 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip/GZipConstants.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e44a440ca5f9984098ac44749153a40 3 | timeCreated: 1503583451 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip/GZipException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.GZip 4 | { 5 | /// 6 | /// GZipException represents exceptions specific to GZip classes and code. 7 | /// 8 | public class GZipException : SharpZipBaseException 9 | { 10 | /// 11 | /// Initialise a new instance of . 12 | /// 13 | public GZipException() 14 | { 15 | } 16 | 17 | /// 18 | /// Initialise a new instance of with its message string. 19 | /// 20 | /// A that describes the error. 21 | public GZipException(string message) 22 | : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// Initialise a new instance of . 28 | /// 29 | /// A that describes the error. 30 | /// The that caused this exception. 31 | public GZipException(string message, Exception innerException) 32 | : base(message, innerException) 33 | { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip/GZipException.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d3668c8b702f0c54ca137d2ba715befb 3 | timeCreated: 1503583461 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip/GzipInputStream.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ace0d3b13ddcab49b3383d5d4127482 3 | timeCreated: 1503583453 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/GZip/GzipOutputStream.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ceec472cdb9e24a4f8207387659abccd 3 | timeCreated: 1503583461 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/SharpZipBaseException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CatLib._3rd.ICSharpCode.SharpZipLib 4 | { 5 | /// 6 | /// SharpZipBaseException is the base exception class for SharpZipLib. 7 | /// All library exceptions are derived from this. 8 | /// 9 | /// NOTE: Not all exceptions thrown will be derived from this class. 10 | /// A variety of other exceptions are possible for example 11 | public class SharpZipBaseException : Exception 12 | { 13 | /// 14 | /// Initializes a new instance of the SharpZipBaseException class. 15 | /// 16 | public SharpZipBaseException() 17 | { 18 | } 19 | 20 | /// 21 | /// Initializes a new instance of the SharpZipBaseException class with a specified error message. 22 | /// 23 | /// A message describing the exception. 24 | public SharpZipBaseException(string message) 25 | : base(message) 26 | { 27 | } 28 | 29 | /// 30 | /// Initializes a new instance of the SharpZipBaseException class with a specified 31 | /// error message and a reference to the inner exception that is the cause of this exception. 32 | /// 33 | /// A message describing the exception. 34 | /// The inner exception 35 | public SharpZipBaseException(string message, Exception innerException) 36 | : base(message, innerException) 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/SharpZipBaseException.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d2df7836feedbb4b832ebaca93e5ef4 3 | timeCreated: 1503583453 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22356ee9acab813418446f25c731b602 3 | folderAsset: yes 4 | timeCreated: 1503583448 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d26e99bbb4973242a35c0bc2be23f9e 3 | folderAsset: yes 4 | timeCreated: 1503583449 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/Deflater.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e4bcf3167e1bb245871b74ef57d1bcb 3 | timeCreated: 1503583451 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/DeflaterConstants.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71086e71f48a8dc4fa48c73e4821dc64 3 | timeCreated: 1503583456 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/DeflaterEngine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 47fd46818a944514b92608a9e526c698 3 | timeCreated: 1503583453 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/DeflaterHuffman.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6ce1c48ec550ef241891cd949f2ff6c4 3 | timeCreated: 1503583455 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/DeflaterPending.cs: -------------------------------------------------------------------------------- 1 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.Zip.Compression 2 | { 3 | /// 4 | /// This class stores the pending output of the Deflater. 5 | /// 6 | /// author of the original java version : Jochen Hoenicke 7 | /// 8 | public class DeflaterPending : PendingBuffer 9 | { 10 | /// 11 | /// Construct instance with default buffer size 12 | /// 13 | public DeflaterPending() : base(DeflaterConstants.PENDING_BUF_SIZE) 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/DeflaterPending.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fc969c4880ceae544a4893b461908883 3 | timeCreated: 1503583463 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/Inflater.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1344a30ca2bac5a45bab093272b520bb 3 | timeCreated: 1503583450 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/InflaterDynHeader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5700f504d35dc944a7a886cedbabfee 3 | timeCreated: 1503583462 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/InflaterHuffmanTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13d01b3cb95617b459ffd8a880d1f1d9 3 | timeCreated: 1503583450 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/PendingBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3f64a109f406e5428f02b71937d28e6 3 | timeCreated: 1503583460 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/Streams.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fbd79e6ad3ecbc9419a1cc0ef1c7d7b6 3 | folderAsset: yes 4 | timeCreated: 1503583449 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/Streams/DeflaterOutputStream.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18acc668a3332c74a83634c9f2811f21 3 | timeCreated: 1503583451 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/Streams/InflaterInputStream.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 20e8bbf16959d7142898412fd49bd20d 3 | timeCreated: 1503583451 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/Streams/OutputWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c11dac9b7c366a46bb28ad4904e1560 3 | timeCreated: 1503583452 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/Compression/Streams/StreamManipulator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1457679fc65b35048a86e0f18ca10a73 3 | timeCreated: 1503583450 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/ZipConstants.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6ecb85ddcfbe68348b21780830b04bca 3 | timeCreated: 1503583456 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/ZipEntry.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf54d426801ab2a459fb18c276d40eef 3 | timeCreated: 1503583461 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/ZipException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CatLib._3rd.ICSharpCode.SharpZipLib.Zip 4 | { 5 | /// 6 | /// ZipException represents exceptions specific to Zip classes and code. 7 | /// 8 | public class ZipException : SharpZipBaseException 9 | { 10 | 11 | /// 12 | /// Initialise a new instance of . 13 | /// 14 | public ZipException() 15 | { 16 | } 17 | 18 | /// 19 | /// Initialise a new instance of with its message string. 20 | /// 21 | /// A that describes the error. 22 | public ZipException(string message) 23 | : base(message) 24 | { 25 | } 26 | 27 | /// 28 | /// Initialise a new instance of . 29 | /// 30 | /// A that describes the error. 31 | /// The that caused this exception. 32 | public ZipException(string message, Exception innerException) 33 | : base(message, innerException) 34 | { 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/ZipException.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1714c8ea9ea0e5948942e14f41453123 3 | timeCreated: 1503583450 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/ZipExtraData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02d2bea757adf2d4ca95e9b00dfaf7a7 3 | timeCreated: 1503583449 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/3rd/SharpZipLib/Zip/ZipHelperStream.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75da8d21eeddda646bd80960582d92bd 3 | timeCreated: 1503583456 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/CompressManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Compress; 13 | 14 | namespace CatLib.Compress 15 | { 16 | /// 17 | /// 压缩解压缩 18 | /// 19 | internal sealed class CompressManager : SingleManager, ICompressManager 20 | { 21 | /// 22 | /// 压缩 23 | /// 24 | /// 需要压缩的字节流 25 | /// 使用的压缩解压缩名字 26 | /// 压缩后的结果 27 | public byte[] Compress(byte[] bytes, string name = null) 28 | { 29 | return Get(name).Compress(bytes); 30 | } 31 | 32 | /// 33 | /// 解压缩 34 | /// 35 | /// 需要解压缩的字节流 36 | /// 使用的压缩解压缩名字 37 | /// 解压缩的结果 38 | public byte[] Decomporess(byte[] bytes, string name = null) 39 | { 40 | return Get(name).Decompress(bytes); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/CompressProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | #if CATLIB 13 | using CatLib.API.Compress; 14 | 15 | namespace CatLib.Compress 16 | { 17 | /// 18 | /// 压缩解压缩服务提供者 19 | /// 20 | public sealed class CompressProvider : IServiceProvider 21 | { 22 | /// 23 | /// 默认压缩等级 24 | /// 25 | public int DefaultLevel { get; set; } 26 | 27 | /// 28 | /// 压缩解压缩服务提供者 29 | /// 30 | public CompressProvider() 31 | { 32 | DefaultLevel = 6; 33 | } 34 | 35 | /// 36 | /// 服务提供者初始化 37 | /// 38 | public void Init() 39 | { 40 | } 41 | 42 | /// 43 | /// 当注册服务提供者 44 | /// 45 | public void Register() 46 | { 47 | App.Singleton().Alias().OnResolving(instance => 48 | { 49 | var manager = (CompressManager)instance; 50 | manager.Extend(() => new GZipAdapter(DefaultLevel)); 51 | manager.Extend(() => new LzmaAdapter(), "lzma"); 52 | manager.Extend(() => manager.Get(), "gzip"); 53 | }); 54 | 55 | App.Singleton((_, __) => App.Make().Default); 56 | } 57 | } 58 | } 59 | #endif -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/GZipAdapter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.IO; 13 | using CatLib.API.Compress; 14 | using CatLib._3rd.ICSharpCode.SharpZipLib.GZip; 15 | 16 | namespace CatLib.Compress 17 | { 18 | /// 19 | /// Gzip压缩解压缩 20 | /// 21 | public sealed class GZipAdapter : ICompress 22 | { 23 | /// 24 | /// 压缩等级 25 | /// 26 | private readonly int level; 27 | 28 | /// 29 | /// 压缩解压缩 30 | /// 31 | /// 压缩等级 32 | public GZipAdapter(int level = 6) 33 | { 34 | this.level = level; 35 | } 36 | 37 | /// 38 | /// 压缩 39 | /// 40 | /// 需要压缩的字节流 41 | /// 压缩后的结果 42 | public byte[] Compress(byte[] bytes) 43 | { 44 | using (var ms = new MemoryStream()) 45 | { 46 | var gzip = new GZipOutputStream(ms); 47 | gzip.Write(bytes, 0, bytes.Length); 48 | gzip.SetLevel(level); 49 | gzip.Close(); 50 | 51 | return ms.ToArray(); 52 | } 53 | } 54 | 55 | /// 56 | /// 解压缩 57 | /// 58 | /// 需要解压缩的字节流 59 | /// 解压缩的结果 60 | public byte[] Decompress(byte[] bytes) 61 | { 62 | using (var ms = new MemoryStream()) 63 | { 64 | var gzip = new GZipInputStream(new MemoryStream(bytes)); 65 | var count = 0; 66 | var data = new byte[4096]; 67 | while ((count = gzip.Read(data, 0, data.Length)) != 0) 68 | { 69 | ms.Write(data, 0, count); 70 | } 71 | return ms.ToArray(); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Compress/LzmaAdapter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Compress; 13 | using CatLib._3rd.SharpCompress.Compressors; 14 | using CatLib._3rd.SharpCompress.Compressors.LZMA; 15 | using System.IO; 16 | 17 | namespace CatLib.Compress 18 | { 19 | /// 20 | /// Lzma压缩解压缩 21 | /// 22 | public sealed class LzmaAdapter : ICompress 23 | { 24 | /// 25 | /// 压缩 26 | /// 27 | /// 需要压缩的字节流 28 | /// 压缩后的结果 29 | public byte[] Compress(byte[] bytes) 30 | { 31 | using (var ms = new MemoryStream()) 32 | { 33 | var lzma = new LZipStream(ms, CompressionMode.Compress, true); 34 | lzma.Write(bytes, 0, bytes.Length); 35 | lzma.Close(); 36 | return ms.ToArray(); 37 | } 38 | } 39 | 40 | /// 41 | /// 解压缩 42 | /// 43 | /// 需要解压缩的字节流 44 | /// 解压缩的结果 45 | public byte[] Decompress(byte[] bytes) 46 | { 47 | using (var ms = new MemoryStream()) 48 | { 49 | var lzma = new LZipStream(new MemoryStream(bytes), CompressionMode.Decompress, true); 50 | var count = 0; 51 | var data = new byte[4096]; 52 | while ((count = lzma.Read(data, 0, data.Length)) != 0) 53 | { 54 | ms.Write(data, 0, count); 55 | } 56 | lzma.Close(); 57 | return ms.ToArray(); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/Log/Handler/StdOutLogHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Debugger; 13 | using System; 14 | using System.Collections.Generic; 15 | 16 | namespace CatLib.Debugger.Log.Handler 17 | { 18 | /// 19 | /// 标准输出日志处理器 20 | /// 21 | public sealed class StdOutLogHandler : ILogHandler 22 | { 23 | /// 24 | /// 实际处理方法 25 | /// 26 | private readonly Dictionary> mapping; 27 | 28 | /// 29 | /// 标准输出日志处理器 30 | /// 31 | public StdOutLogHandler() 32 | { 33 | mapping = new Dictionary> 34 | { 35 | {LogLevels.Emergency, Console.WriteLine}, 36 | {LogLevels.Alert, Console.WriteLine}, 37 | {LogLevels.Critical, Console.WriteLine}, 38 | {LogLevels.Error, Console.WriteLine}, 39 | {LogLevels.Warning, Console.WriteLine}, 40 | {LogLevels.Notice, Console.WriteLine}, 41 | {LogLevels.Info, Console.WriteLine}, 42 | {LogLevels.Debug, Console.WriteLine} 43 | }; 44 | } 45 | 46 | /// 47 | /// 日志处理器 48 | /// 49 | /// 日志条目 50 | public void Handler(ILogEntry log) 51 | { 52 | Action handler; 53 | if (mapping.TryGetValue(log.Level, out handler)) 54 | { 55 | handler.Invoke(log.Message); 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/Log/ILogEntry.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Debugger; 13 | using System; 14 | 15 | namespace CatLib.Debugger.Log 16 | { 17 | /// 18 | /// 日志条目 19 | /// 20 | public interface ILogEntry 21 | { 22 | /// 23 | /// 条目id 24 | /// 25 | long Id { get; } 26 | 27 | /// 28 | /// 日志等级 29 | /// 30 | LogLevels Level { get; } 31 | 32 | /// 33 | /// 日志内容 34 | /// 35 | string Message { get; } 36 | 37 | /// 38 | /// 命名空间 39 | /// 40 | string Namespace { get; } 41 | 42 | /// 43 | /// 记录时间 44 | /// 45 | long Time { get; } 46 | 47 | /// 48 | /// 获取调用堆栈 49 | /// 50 | /// 程序集是否符合输出条件 51 | /// 调用堆栈 52 | string[] GetStackTrace(Predicate assemblyMatch = null); 53 | 54 | /// 55 | /// 是否可以被忽略 56 | /// 57 | /// 处理器类型 58 | /// 是否可以忽略这个处理器 59 | bool IsIgnore(Type type); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/Log/ILogHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Debugger.Log 13 | { 14 | /// 15 | /// 日志处理器 16 | /// 17 | public interface ILogHandler 18 | { 19 | /// 20 | /// 日志处理器 21 | /// 22 | /// 日志条目 23 | void Handler(ILogEntry log); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/Log/LogUtil.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.Threading; 13 | 14 | namespace CatLib.Debugger.Log 15 | { 16 | /// 17 | /// Log通用工具 18 | /// 19 | public static class LogUtil 20 | { 21 | /// 22 | /// 日志LastId 23 | /// 24 | private static long lastId; 25 | 26 | /// 27 | /// 获取日志LastId 28 | /// 29 | /// 日志LastId 30 | public static long GetLastId() 31 | { 32 | return Interlocked.Increment(ref lastId); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebConsole/BaseProtocol.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Debugger.WebConsole 13 | { 14 | /// 15 | /// 基础协议 16 | /// 17 | internal sealed class BaseProtocol 18 | { 19 | /// 20 | /// 数据 21 | /// 22 | public object Response; 23 | 24 | /// 25 | /// 基础协议 26 | /// 27 | /// 响应 28 | public BaseProtocol(object response) 29 | { 30 | Response = response; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebConsole/IWebConsoleResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Debugger.WebConsole 13 | { 14 | /// 15 | /// Web控制台响应 16 | /// 17 | public interface IWebConsoleResponse 18 | { 19 | /// 20 | /// 响应 21 | /// 22 | object Response { get; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebConsole/Protocol/GetGuid.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Debugger.WebConsole.Protocol 13 | { 14 | /// 15 | /// GetGuid API 16 | /// 17 | internal sealed class GetGuid : IWebConsoleResponse 18 | { 19 | /// 20 | /// 响应 21 | /// 22 | public object Response { get; private set; } 23 | 24 | /// 25 | /// GetGuid API 26 | /// 27 | /// 响应 28 | public GetGuid(object response) 29 | { 30 | Response = response; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebLog/Controller/Log.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | using CatLib.Debugger.WebLog.Protocol; 14 | 15 | namespace CatLib.Debugger.WebLog.Controller 16 | { 17 | /// 18 | /// 日志 19 | /// 20 | [Routed("debug://log")] 21 | public sealed class Log 22 | { 23 | /// 24 | /// 获取日志 25 | /// 26 | /// 请求 27 | /// 响应 28 | /// 日志存储 29 | [Routed("get-log/{clientId}")] 30 | public void GetLog(IRequest request, IResponse response, LogStore logStore) 31 | { 32 | var outputs = new WebConsoleOutputs(); 33 | foreach (var log in logStore.GetUnloadEntrysByClientId(request.Get("clientId"))) 34 | { 35 | outputs.WriteLine(log); 36 | } 37 | response.SetContext(outputs); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebLog/Controller/Util.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Debugger; 13 | using CatLib.API.Routing; 14 | 15 | namespace CatLib.Debugger.WebLog.Controller 16 | { 17 | /// 18 | /// 通用 19 | /// 20 | [Routed("debug://util")] 21 | public class Util 22 | { 23 | /// 24 | /// 回显 25 | /// 26 | /// 请求 27 | /// 响应 28 | /// 日志系统 29 | [Routed("echo/{msg?}")] 30 | public void Echo(IRequest request, IResponse response, ILogger logger) 31 | { 32 | if (logger != null) 33 | { 34 | logger.Debug(request.Get("msg")); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebLog/LogHandler/WebLogHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.Debugger.Log; 13 | using System; 14 | 15 | namespace CatLib.Debugger.WebLog.LogHandler 16 | { 17 | /// 18 | /// Web日志处理器 19 | /// 20 | public class WebLogHandler : ILogHandler 21 | { 22 | /// 23 | /// 日志存储 24 | /// 25 | private readonly LogStore store; 26 | 27 | /// 28 | /// 网络日志处理器 29 | /// 30 | /// 31 | public WebLogHandler(LogStore store) 32 | { 33 | Guard.Requires(store != null); 34 | this.store = store; 35 | } 36 | 37 | /// 38 | /// 日志处理器 39 | /// 40 | /// 日志条目 41 | public void Handler(ILogEntry log) 42 | { 43 | store.Log(log); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebMonitor/Handler/OnceRecordMonitorHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.Debugger.WebMonitor.Handler 15 | { 16 | /// 17 | /// 监控处理器 18 | /// 19 | public sealed class OnceRecordMonitorHandler : IMonitorHandler 20 | { 21 | /// 22 | /// 标签 23 | /// 24 | public string[] Tags { get; private set; } 25 | 26 | /// 27 | /// 监控的名字 28 | /// 29 | public string Name { get; private set; } 30 | 31 | /// 32 | /// 监控值的单位描述 33 | /// 34 | public string Unit { get; private set; } 35 | 36 | /// 37 | /// 实时的监控值 38 | /// 39 | public string Value 40 | { 41 | get 42 | { 43 | return callback.Invoke().ToString(); 44 | } 45 | } 46 | 47 | /// 48 | /// 回调获取结果 49 | /// 50 | private readonly Func callback; 51 | 52 | /// 53 | /// 单次记录监控处理器 54 | /// 55 | /// 标题 56 | /// 单位值 57 | /// tags 58 | /// 回调 59 | public OnceRecordMonitorHandler(string name, string unit , string[] tags , Func callback) 60 | { 61 | Guard.NotEmptyOrNull(name, "name"); 62 | Guard.Requires(unit != null); 63 | Guard.Requires(tags != null); 64 | Guard.Requires(callback != null); 65 | Name = name; 66 | Unit = unit; 67 | Tags = tags; 68 | this.callback = callback; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebMonitor/IMonitor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Debugger 13 | { 14 | /// 15 | /// 监控 16 | /// 17 | public interface IMonitor 18 | { 19 | /// 20 | /// 增加监控 21 | /// 22 | /// 监控句柄 23 | void Monitor(IMonitorHandler handler); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebMonitor/IMonitorHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Debugger 13 | { 14 | /// 15 | /// 监控句柄 16 | /// 17 | public interface IMonitorHandler 18 | { 19 | /// 20 | /// 监控的名字 21 | /// 22 | string Name { get; } 23 | 24 | /// 25 | /// 标签(第0位:分类) 26 | /// 27 | string[] Tags { get; } 28 | 29 | /// 30 | /// 监控值的单位 31 | /// 32 | string Unit { get; } 33 | 34 | /// 35 | /// 监控值 36 | /// 37 | string Value { get; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Debugger/WebMonitor/Protocol/GetMonitors.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.Debugger.WebConsole; 13 | using System; 14 | using System.Collections.Generic; 15 | 16 | namespace CatLib.Debugger.WebMonitor.Protocol 17 | { 18 | /// 19 | /// 获取监控信息 20 | /// 21 | internal sealed class GetMonitors : IWebConsoleResponse 22 | { 23 | /// 24 | /// 响应 25 | /// 26 | public object Response 27 | { 28 | get { return outputs; } 29 | } 30 | 31 | /// 32 | /// 输出 33 | /// 34 | private readonly IList> outputs; 35 | 36 | /// 37 | /// 获取分组API 38 | /// 39 | public GetMonitors() 40 | { 41 | outputs = new List>(); 42 | } 43 | 44 | /// 45 | /// 写入一条监控信息 46 | /// 47 | /// 处理器 48 | public void WriteLine(IMonitorHandler handler) 49 | { 50 | try 51 | { 52 | outputs.Add(new Dictionary 53 | { 54 | {"name", handler.Name}, 55 | {"value", handler.Value}, 56 | {"unit", handler.Unit}, 57 | {"tags", handler.Tags}, 58 | }); 59 | } 60 | catch (TypeLoadException) 61 | { 62 | WriteNotSupportLine(handler); 63 | } 64 | catch (MissingMethodException) 65 | { 66 | WriteNotSupportLine(handler); 67 | } 68 | } 69 | 70 | /// 71 | /// 写入未支持行 72 | /// 73 | /// 处理器 74 | private void WriteNotSupportLine(IMonitorHandler handler) 75 | { 76 | outputs.Add(new Dictionary 77 | { 78 | {"name", handler.Name}, 79 | {"value", "code.notSupport"}, 80 | {"unit", string.Empty}, 81 | {"tags", handler.Tags}, 82 | }); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Encryption/Encrypter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib._3rd.Elliptic; 13 | using CatLib.API.Encryption; 14 | using System; 15 | using System.Security.Cryptography; 16 | 17 | namespace CatLib.Encryption 18 | { 19 | /// 20 | /// 加解密 21 | /// 22 | public sealed class Encrypter : SingleManager , IEncryptionManager 23 | { 24 | /// 25 | /// 加密 26 | /// 27 | /// 加密数据 28 | /// 加密后的数据 29 | public string Encrypt(byte[] content) 30 | { 31 | return Default.Encrypt(content); 32 | } 33 | 34 | /// 35 | /// 解密 36 | /// 37 | /// 被加密的内容 38 | /// 解密内容 39 | public byte[] Decrypt(string payload) 40 | { 41 | return Default.Decrypt(payload); 42 | } 43 | 44 | /// 45 | /// 交换密钥 46 | /// 47 | /// 交换流程(输入值是我方公钥,返回值是对端公钥) 48 | /// 密钥 49 | public byte[] ExchangeSecret(Func exchange) 50 | { 51 | Guard.Requires(exchange != null); 52 | var randBytes = new byte[32]; 53 | RandomNumberGenerator.Create().GetBytes(randBytes); 54 | var privateKey = Curve25519.ClampPrivateKey(randBytes); 55 | var publicKey = Curve25519.GetPublicKey(privateKey); 56 | return Curve25519.GetSharedSecret(privateKey, exchange.Invoke(publicKey)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Encryption/EncryptionProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | #if CATLIB 13 | using CatLib.API.Encryption; 14 | 15 | namespace CatLib.Encryption 16 | { 17 | /// 18 | /// 加解密服务 19 | /// 20 | public sealed class EncryptionProvider : IServiceProvider 21 | { 22 | /// 23 | /// 密钥 24 | /// 25 | public string Key { get; set; } 26 | 27 | /// 28 | /// 加密类型 29 | /// 30 | public string Cipher { get; set; } 31 | 32 | /// 33 | /// 加解密服务 34 | /// 35 | public EncryptionProvider() 36 | { 37 | Cipher = "AES-128-CBC"; 38 | } 39 | 40 | /// 41 | /// 服务提供者初始化 42 | /// 43 | public void Init() 44 | { 45 | } 46 | 47 | /// 48 | /// 当注册服务提供者 49 | /// 50 | public void Register() 51 | { 52 | App.Singleton().OnResolving(instance => 53 | { 54 | var encrypter = (Encrypter)instance; 55 | encrypter.Extend(() => MakeEncrypter(Key, Cipher)); 56 | }).Alias().Alias(); 57 | } 58 | 59 | /// 60 | /// 根据加密方式生成加密器 61 | /// 62 | /// 使用的key 63 | /// 加密方式 64 | private AesEncrypter MakeEncrypter(string key, string cipher) 65 | { 66 | if (string.IsNullOrEmpty(Key)) 67 | { 68 | throw new RuntimeException("Please set config [EncryptionProvider.Key]"); 69 | } 70 | return new AesEncrypter(key, cipher == "AES-128-CBC" ? 128 : 256); 71 | } 72 | } 73 | } 74 | #endif -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Compress.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Compress; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 压缩器 18 | /// 19 | public sealed class Compress : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Dispatcher.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Facade 13 | { 14 | /// 15 | /// 全局事件调度器 16 | /// 17 | public sealed class Dispatcher : Facade 18 | { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Encrypter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Encryption; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 加密器 18 | /// 19 | public sealed class Encrypter : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/FileSystem.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.FileSystem; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 文件系统管理器 18 | /// 19 | public sealed class FileSystem : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Hashing.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Hashing; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 随机数 18 | /// 19 | public sealed class Hashing : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/I18N.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Translation; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 国际化I18N 18 | /// 19 | public sealed class I18N : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Json.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Json; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// Json 18 | /// 19 | public sealed class Json : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Network.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Network; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 网络 18 | /// 19 | public sealed class Network : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Random.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Random; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 随机数 18 | /// 19 | public sealed class Random : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Router.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 路由 18 | /// 19 | public sealed class Router : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Facade/Socket.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Socket; 13 | 14 | namespace CatLib.Facade 15 | { 16 | /// 17 | /// 套接字 18 | /// 19 | public sealed class Socket : Facade 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CatLib.Framework/FileSystem/Directory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.FileSystem; 13 | 14 | namespace CatLib.FileSystem 15 | { 16 | /// 17 | /// 文件夹 18 | /// 19 | public sealed class Directory : Handler, IDirectory 20 | { 21 | /// 22 | /// 文件夹 23 | /// 24 | /// 文件系统 25 | /// 文件夹路径 26 | public Directory(FileSystem fileSystem, string path) : 27 | base(fileSystem, path) 28 | { 29 | } 30 | 31 | /// 32 | /// 获取文件夹下的文件/文件夹列表(不会迭代子文件夹) 33 | /// 34 | /// 指定目录下的文件夹句柄和文件句柄列表 35 | public IHandler[] GetList() 36 | { 37 | return FileSystem.GetList(Path); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CatLib.Framework/FileSystem/File.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.FileSystem; 13 | 14 | namespace CatLib.FileSystem 15 | { 16 | /// 17 | /// 文件 18 | /// 19 | public sealed class File : Handler, IFile 20 | { 21 | /// 22 | /// 文件 23 | /// 24 | /// 文件系统 25 | /// 文件路径 26 | public File(FileSystem fileSystem, string path) : 27 | base(fileSystem, path) 28 | { 29 | } 30 | 31 | /// 32 | /// 写入数据 33 | /// 如果数据已经存在则覆盖 34 | /// 35 | /// 写入数据 36 | public void Write(byte[] contents) 37 | { 38 | FileSystem.Write(Path, contents); 39 | } 40 | 41 | /// 42 | /// 读取文件 43 | /// 44 | /// 读取的数据 45 | public byte[] Read() 46 | { 47 | return FileSystem.Read(Path); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/CatLib.Framework/FileSystem/FileSystemManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.FileSystem; 13 | using System; 14 | 15 | namespace CatLib.FileSystem 16 | { 17 | /// 18 | /// 文件系统管理器 19 | /// 20 | internal sealed class FileSystemManager : SingleManager, IFileSystemManager 21 | { 22 | /// 23 | /// 默认名字 24 | /// 25 | private string name = "local"; 26 | 27 | /// 28 | /// 设定默认驱动名字 29 | /// 30 | /// 默认驱动名字 31 | public void SetDefaultDevice(string name) 32 | { 33 | Guard.Requires(name != null); 34 | this.name = name; 35 | } 36 | 37 | /// 38 | /// 获取一个文件系统(磁盘) 39 | /// 40 | /// 名字 41 | /// 文件系统 42 | public IFileSystem Disk(string name = null) 43 | { 44 | return Get(name); 45 | } 46 | 47 | /// 48 | /// 获取默认的文件系统名字 49 | /// 50 | /// 默认的文件系统名字 51 | protected override string GetDefaultName() 52 | { 53 | return name; 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Hashing/3rd/BCrypt/SaltParseException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace CatLib._3rd.BCrypt.Net 5 | { 6 | /// Exception for signalling parse errors. 7 | public class SaltParseException : ApplicationException 8 | { 9 | /// Default constructor. 10 | public SaltParseException() 11 | { 12 | } 13 | 14 | /// Initializes a new instance of . 15 | /// The message. 16 | public SaltParseException(string message) 17 | : base(message) 18 | { 19 | } 20 | 21 | /// Initializes a new instance of . 22 | /// The message. 23 | /// The inner exception. 24 | public SaltParseException(string message, Exception innerException) 25 | : base(message, innerException) 26 | { 27 | } 28 | 29 | /// Initializes a new instance of . 30 | /// The information. 31 | /// The context. 32 | protected SaltParseException(SerializationInfo info, StreamingContext context) 33 | : base(info, context) 34 | { 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Hashing/3rd/MurmurHash/Murmur32ManagedX86.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Darren Kopp 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using System.Runtime.CompilerServices; 17 | 18 | namespace CatLib._3rd.Murmur 19 | { 20 | internal class Murmur32ManagedX86 : Murmur32 21 | { 22 | public Murmur32ManagedX86(uint seed = 0) 23 | : base(seed) 24 | { 25 | } 26 | 27 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 28 | { 29 | Length += cbSize; 30 | Body(array, ibStart, cbSize); 31 | } 32 | 33 | #if NETFX45 34 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 35 | #endif 36 | private void Body(byte[] data, int start, int length) 37 | { 38 | int remainder = length & 3; 39 | int alignedLength = start + (length - remainder); 40 | 41 | for (int i = start; i < alignedLength; i += 4) 42 | H1 = (((H1 ^ (((data.ToUInt32(i) * C1).RotateLeft(15)) * C2)).RotateLeft(13)) * 5) + 0xe6546b64; 43 | 44 | if (remainder > 0) 45 | Tail(data, alignedLength, remainder); 46 | } 47 | 48 | #if NETFX45 49 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 50 | #endif 51 | private void Tail(byte[] tail, int position, int remainder) 52 | { 53 | // create our keys and initialize to 0 54 | uint k1 = 0; 55 | 56 | // determine how many bytes we have left to work with based on length 57 | switch (remainder) 58 | { 59 | case 3: k1 ^= (uint)tail[position + 2] << 16; goto case 2; 60 | case 2: k1 ^= (uint)tail[position + 1] << 8; goto case 1; 61 | case 1: k1 ^= tail[position]; break; 62 | } 63 | 64 | H1 ^= (k1 * C1).RotateLeft(15) * C2; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Hashing/Checksum/IChecksum.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Hashing.Checksum 13 | { 14 | /// 15 | /// 校验接口 16 | /// 17 | public interface IChecksum 18 | { 19 | /// 20 | /// 重置数据校验,恢复到初始状态 21 | /// 22 | void Reset(); 23 | 24 | /// 25 | /// 返回到目前为止计算的数据校验和 26 | /// 27 | long Value { get; } 28 | 29 | /// 30 | /// 增加一个字节的校验 31 | /// 32 | /// 要添加的数据,int的高字节被忽略 33 | void Update(int bval); 34 | 35 | /// 36 | /// 使用传入的字节数组更新数据校验和 37 | /// 38 | /// 字节数组 39 | void Update(byte[] buffer); 40 | 41 | /// 42 | /// 将字节数组添加到数据校验和 43 | /// 44 | /// 字节数组 45 | /// 起始偏移量 46 | /// 多少长度会被添加到数据校验 47 | void Update(byte[] buffer, int offset, int count); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Hashing/Checksum/Murmur32.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using CatLib._3rd.Murmur; 14 | 15 | namespace CatLib.Hashing.Checksum 16 | { 17 | /// 18 | /// Murmur32 19 | /// 20 | internal sealed class Murmur32 : Murmur32ManagedX86, IChecksum 21 | { 22 | /// 23 | /// 初始化 24 | /// 25 | public override void Initialize() 26 | { 27 | } 28 | 29 | /// 30 | /// 重置数据校验,恢复到初始状态 31 | /// 32 | void IChecksum.Reset() 33 | { 34 | base.Initialize(); 35 | } 36 | 37 | /// 38 | /// 返回到目前为止计算的数据校验和 39 | /// 40 | long IChecksum.Value 41 | { 42 | get 43 | { 44 | return BitConverter.ToUInt32(Hash, 0); 45 | } 46 | } 47 | 48 | /// 49 | /// 增加一个字节的校验 50 | /// 51 | /// 要添加的数据,int的高字节被忽略 52 | public void Update(int bval) 53 | { 54 | Update(BitConverter.GetBytes(bval)); 55 | } 56 | 57 | /// 58 | /// 使用传入的字节数组更新数据校验和 59 | /// 60 | /// 字节数组 61 | public void Update(byte[] buffer) 62 | { 63 | Guard.Requires(buffer != null); 64 | Update(buffer, 0, buffer.Length); 65 | } 66 | 67 | /// 68 | /// 将字节数组添加到数据校验和 69 | /// 70 | /// 字节数组 71 | /// 起始偏移量 72 | /// 多少长度会被添加到数据校验 73 | public void Update(byte[] buffer, int offset, int count) 74 | { 75 | HashingGuard.BufferOffsetCount(buffer, offset, count); 76 | ComputeHash(buffer, offset, count); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Hashing/HashingGuard.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | 14 | namespace CatLib.Hashing 15 | { 16 | /// 17 | /// 守卫 18 | /// 19 | internal static class HashingGuard 20 | { 21 | /// 22 | /// 校验BufferOffsetCount 23 | /// 24 | /// buffer 25 | /// 偏移量 26 | /// 多少长度会被添加到数据校验 27 | public static void BufferOffsetCount(byte[] buffer, int offset, int count) 28 | { 29 | Guard.Requires(buffer != null); 30 | Guard.Requires(offset >= 0); 31 | Guard.Requires(offset < buffer.Length); 32 | Guard.Requires(count >= 0); 33 | Guard.Requires(offset + count <= buffer.Length); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Hashing/HashingProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | #if CATLIB 13 | using System.Text; 14 | using CatLib.API.Hashing; 15 | using CatLib.Hashing.Checksum; 16 | 17 | namespace CatLib.Hashing 18 | { 19 | /// 20 | /// 哈希服务提供者 21 | /// 22 | public sealed class HashingProvider : IServiceProvider 23 | { 24 | /// 25 | /// 默认的校验类 26 | /// 27 | public string DefaultChecksum { get; set; } 28 | 29 | /// 30 | /// 默认的编码 31 | /// 32 | public Encoding DefaultEncoding { get; set; } 33 | 34 | /// 35 | /// 哈希服务提供者 36 | /// 37 | public HashingProvider() 38 | { 39 | DefaultChecksum = Checksums.Crc32; 40 | DefaultEncoding = Encoding.Default; 41 | } 42 | 43 | /// 44 | /// 服务提供者初始化 45 | /// 46 | public void Init() 47 | { 48 | } 49 | 50 | /// 51 | /// 当注册服务提供者 52 | /// 53 | public void Register() 54 | { 55 | App.Singleton((_, __) => new Hashing(DefaultChecksum, DefaultEncoding)) 56 | .Alias().OnResolving(instance => 57 | { 58 | var hashing = (Hashing)instance; 59 | 60 | hashing.Extend(Checksums.Crc32, () => new Crc32()); 61 | hashing.Extend(Checksums.Adler32, () => new Adler32()); 62 | hashing.Extend(Checksums.Djb, () => new Djb()); 63 | hashing.Extend(Checksums.Murmur32, () => new Murmur32()); 64 | }); 65 | } 66 | } 67 | } 68 | #endif -------------------------------------------------------------------------------- /src/CatLib.Framework/Json/3rd/LitJson/IJsonWrapper.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Collections; 3 | using System.Collections.Specialized; 4 | 5 | 6 | namespace LitJson 7 | { 8 | public enum JsonType 9 | { 10 | None, 11 | 12 | Object, 13 | Array, 14 | String, 15 | Int, 16 | Long, 17 | Double, 18 | Boolean 19 | } 20 | 21 | public interface IJsonWrapper : IList, IOrderedDictionary 22 | { 23 | bool IsArray { get; } 24 | bool IsBoolean { get; } 25 | bool IsDouble { get; } 26 | bool IsInt { get; } 27 | bool IsLong { get; } 28 | bool IsObject { get; } 29 | bool IsString { get; } 30 | 31 | bool GetBoolean (); 32 | double GetDouble (); 33 | int GetInt (); 34 | JsonType GetJsonType (); 35 | long GetLong (); 36 | string GetString (); 37 | 38 | void SetBoolean (bool val); 39 | void SetDouble (double val); 40 | void SetInt (int val); 41 | void SetJsonType (JsonType type); 42 | void SetLong (long val); 43 | void SetString (string val); 44 | 45 | string ToJson (); 46 | void ToJson (JsonWriter writer); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Json/3rd/LitJson/JsonException.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | 5 | namespace LitJson 6 | { 7 | public class JsonException : 8 | #if NETSTANDARD1_5 9 | Exception 10 | #else 11 | ApplicationException 12 | #endif 13 | { 14 | public JsonException () : base () 15 | { 16 | } 17 | 18 | internal JsonException (ParserToken token) : 19 | base (String.Format ( 20 | "Invalid token '{0}' in input string", token)) 21 | { 22 | } 23 | 24 | internal JsonException (ParserToken token, 25 | Exception inner_exception) : 26 | base (String.Format ( 27 | "Invalid token '{0}' in input string", token), 28 | inner_exception) 29 | { 30 | } 31 | 32 | internal JsonException (int c) : 33 | base (String.Format ( 34 | "Invalid character '{0}' in input string", (char) c)) 35 | { 36 | } 37 | 38 | internal JsonException (int c, Exception inner_exception) : 39 | base (String.Format ( 40 | "Invalid character '{0}' in input string", (char) c), 41 | inner_exception) 42 | { 43 | } 44 | 45 | 46 | public JsonException (string message) : base (message) 47 | { 48 | } 49 | 50 | public JsonException (string message, Exception inner_exception) : 51 | base (message, inner_exception) 52 | { 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Json/3rd/LitJson/Netstandard15Polyfill.cs: -------------------------------------------------------------------------------- 1 | #if NETSTANDARD1_5 2 | using System; 3 | using System.Reflection; 4 | namespace LitJson 5 | { 6 | internal static class Netstandard15Polyfill 7 | { 8 | internal static Type GetInterface(this Type type, string name) 9 | { 10 | return type.GetTypeInfo().GetInterface(name); 11 | } 12 | 13 | internal static bool IsClass(this Type type) 14 | { 15 | return type.GetTypeInfo().IsClass; 16 | } 17 | 18 | internal static bool IsEnum(this Type type) 19 | { 20 | return type.GetTypeInfo().IsEnum; 21 | } 22 | } 23 | } 24 | #endif -------------------------------------------------------------------------------- /src/CatLib.Framework/Json/3rd/LitJson/ParserToken.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace LitJson 3 | { 4 | internal enum ParserToken 5 | { 6 | // Lexer tokens (see section A.1.1. of the manual) 7 | None = System.Char.MaxValue + 1, 8 | Number, 9 | True, 10 | False, 11 | Null, 12 | CharSeq, 13 | // Single char 14 | Char, 15 | 16 | // Parser Rules (see section A.2.1 of the manual) 17 | Text, 18 | Object, 19 | ObjectPrime, 20 | Pair, 21 | PairRest, 22 | Array, 23 | ArrayPrime, 24 | Value, 25 | ValueRest, 26 | String, 27 | 28 | // End of input 29 | End, 30 | 31 | // The empty rule 32 | Epsilon 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Json/JsonProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | #if CATLIB 13 | using CatLib.API.Json; 14 | 15 | namespace CatLib.Json 16 | { 17 | /// 18 | /// Json 服务 19 | /// 20 | public sealed class JsonProvider : IServiceProvider 21 | { 22 | /// 23 | /// 初始化 24 | /// 25 | public void Init() 26 | { 27 | } 28 | 29 | /// 30 | /// 当注册服务提供者 31 | /// 32 | public void Register() 33 | { 34 | App.Singleton().OnResolving(instance => 35 | { 36 | var jsonUtility = (JsonUtility)instance; 37 | jsonUtility.SetJson(new LitJsonAdapter()); 38 | }).Alias().Alias(); 39 | } 40 | } 41 | } 42 | #endif -------------------------------------------------------------------------------- /src/CatLib.Framework/Json/LitJsonAdapter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using CatLib.API.Json; 14 | using LitJson; 15 | 16 | namespace CatLib.Json 17 | { 18 | /// 19 | /// Facebook Simple Json 适配器 20 | /// 21 | internal sealed class LitJsonAdapter : IJson 22 | { 23 | /// 24 | /// 反序列化 25 | /// 26 | /// 类型 27 | /// json数据 28 | /// 反序列化的类型 29 | public T Decode(string json) 30 | { 31 | return (T)Decode(json, typeof(T)); 32 | } 33 | 34 | /// 35 | /// 反序列化 36 | /// 37 | /// json数据 38 | /// 反序列化的类型 39 | /// 反序列化的结果 40 | public object Decode(string json, Type type) 41 | { 42 | return JsonMapper.ToObject(json, type); 43 | } 44 | 45 | /// 46 | /// 序列化 47 | /// 48 | /// 需要序列化的对象 49 | /// json数据 50 | public string Encode(object item) 51 | { 52 | return JsonMapper.ToJson(item); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Network/Packer/FramePacker.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using CatLib.API.Network; 14 | 15 | namespace CatLib.Network.Packer 16 | { 17 | /// 18 | /// Frame协议 19 | /// 协议格式为 总包长+包体,其中包长(总包长+包体)为4字节网络字节序的整数,包体可以是普通文本或者二进制数据。 20 | /// 21 | public sealed class FramePacker : IPacker 22 | { 23 | /// 24 | /// 检查包的完整性 25 | /// 如果能够得到包长,则返回包的在buffer中的长度(包含包头),否则返回0继续等待数据 26 | /// 如果协议有问题,则填入ex参数,当前连接会因此断开 27 | /// 28 | /// 29 | /// 30 | /// 31 | public int Input(byte[] source, out Exception ex) 32 | { 33 | ex = null; 34 | try 35 | { 36 | return source == null || source.Length < 4 ? 0 : BitConverter.ToInt32(Arr.Slice(source, 0, 4), 0); 37 | } 38 | catch (Exception e) 39 | { 40 | ex = e; 41 | return 0; 42 | } 43 | } 44 | 45 | /// 46 | /// 序列化消息包。 47 | /// 48 | /// 要序列化的消息包。 49 | /// 用户自定义异常 50 | /// 序列化后的消息包字节流。 51 | public byte[] Encode(object packet, out Exception ex) 52 | { 53 | var data = packet as byte[]; 54 | ex = data == null ? new RuntimeException("packet is Invalid") : null; 55 | if (data != null && data.Length > 0) 56 | { 57 | data = Arr.Merge(BitConverter.GetBytes(data.Length + 4), data); 58 | } 59 | return data == null || data.Length <= 0 ? null : data; 60 | } 61 | 62 | /// 63 | /// 反序列化消息包(包体)。 64 | /// 65 | /// 反序列化的数据。 66 | /// 用户自定义错误数据。 67 | /// 反序列化后的消息包。 68 | public object Decode(byte[] source, out Exception ex) 69 | { 70 | ex = null; 71 | return Arr.Slice(source, 4); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Network/Packer/TextPacker.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using CatLib.API.Network; 14 | 15 | namespace CatLib.Network.Packer 16 | { 17 | /// 18 | /// Text协议 19 | /// 协议格式为 数据包+换行符(\n),即在每个数据包末尾加上一个换行符表示包的结束 20 | /// 21 | public sealed class TextPacker : IPacker 22 | { 23 | /// 24 | /// 换行符 25 | /// 26 | private readonly byte[] lineFeed = { 10 }; 27 | 28 | /// 29 | /// 检查包的完整性 30 | /// 如果能够得到包长,则返回包的在buffer中的长度(包含包头),否则返回0继续等待数据 31 | /// 如果协议有问题,则填入ex参数,当前连接会因此断开 32 | /// 33 | /// 34 | /// 35 | /// 36 | public int Input(byte[] source, out Exception ex) 37 | { 38 | ex = null; 39 | var index = Arr.IndexOf(source, lineFeed); 40 | if (index < 0) 41 | { 42 | return 0; 43 | } 44 | return index + lineFeed.Length; 45 | } 46 | 47 | /// 48 | /// 序列化消息包。 49 | /// 50 | /// 要序列化的消息包。 51 | /// 用户自定义异常 52 | /// 序列化后的消息包字节流。 53 | public byte[] Encode(object packet, out Exception ex) 54 | { 55 | var data = packet as byte[]; 56 | ex = data == null ? new RuntimeException("packet is Invalid") : null; 57 | return data == null || data.Length <= 0 ? null : Arr.Merge(data, lineFeed); 58 | } 59 | 60 | /// 61 | /// 反序列化消息包(包体)。 62 | /// 63 | /// 反序列化的数据。 64 | /// 用户自定义错误数据。 65 | /// 反序列化后的消息包。 66 | public object Decode(byte[] source, out Exception ex) 67 | { 68 | ex = null; 69 | return Arr.Slice(source, 0, -lineFeed.Length); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System.Reflection; 13 | using System.Runtime.CompilerServices; 14 | using System.Runtime.InteropServices; 15 | 16 | [assembly: AssemblyTitle("CatLib.Framework")] 17 | [assembly: AssemblyDescription("CatLib Component-Based Framework")] 18 | [assembly: AssemblyConfiguration("")] 19 | [assembly: AssemblyCompany("CatLib")] 20 | [assembly: AssemblyProduct("CatLib.Framework")] 21 | [assembly: AssemblyCopyright("Copyright © CatLib 2017")] 22 | [assembly: AssemblyTrademark("")] 23 | [assembly: AssemblyCulture("")] 24 | 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | [assembly: Guid("bbb2dae2-638b-4419-9591-3cecca312e4e")] 29 | 30 | [assembly: AssemblyVersion("1.1.2.0")] 31 | [assembly: AssemblyFileVersion("1.1.2.0")] 32 | 33 | [assembly: InternalsVisibleTo("Assembly-CSharp-Editor"), 34 | InternalsVisibleTo("Assembly-CSharp-Editor-firstpass"), 35 | InternalsVisibleTo("CatLib.Framework.Tests")] -------------------------------------------------------------------------------- /src/CatLib.Framework/Random/3rd/MathNet/Random/RandomSeed.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CatLib._3rd.MathNet.Numerics.Random 4 | { 5 | /// 6 | /// Random seed 7 | /// 8 | public static class RandomSeed 9 | { 10 | static readonly object Lock = new object(); 11 | 12 | #if PORTABLE 13 | static readonly System.Random MasterRng = new System.Random(); 14 | #else 15 | static readonly System.Security.Cryptography.RandomNumberGenerator MasterRng = new System.Security.Cryptography.RNGCryptoServiceProvider(); 16 | #endif 17 | 18 | /// 19 | /// Provides a time-dependent seed value, matching the default behavior of System.Random. 20 | /// WARNING: There is no randomness in this seed and quick repeated calls can cause 21 | /// the same seed value. Do not use for cryptography! 22 | /// 23 | public static int Time() 24 | { 25 | return Environment.TickCount; 26 | } 27 | 28 | /// 29 | /// Provides a seed based on time and unique GUIDs. 30 | /// WARNING: There is only low randomness in this seed, but at least quick repeated 31 | /// calls will result in different seed values. Do not use for cryptography! 32 | /// 33 | public static int Guid() 34 | { 35 | return Environment.TickCount ^ System.Guid.NewGuid().GetHashCode(); 36 | } 37 | 38 | /// 39 | /// Provides a seed based on an internal random number generator (crypto if available), time and unique GUIDs. 40 | /// WARNING: There is only medium randomness in this seed, but quick repeated 41 | /// calls will result in different seed values. Do not use for cryptography! 42 | /// 43 | public static int Robust() 44 | { 45 | lock (Lock) 46 | { 47 | #if PORTABLE 48 | return MasterRng.NextFullRangeInt32() ^ Environment.TickCount ^ System.Guid.NewGuid().GetHashCode(); 49 | #else 50 | var bytes = new byte[4]; 51 | MasterRng.GetBytes(bytes); 52 | return BitConverter.ToInt32(bytes, 0); 53 | #endif 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Random/RandomAdaptor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using CatLib.API.Random; 14 | 15 | namespace CatLib.Random 16 | { 17 | /// 18 | /// 随机算法适配器 19 | /// 20 | public sealed class RandomAdaptor : IRandom 21 | { 22 | /// 23 | /// 随机算法 24 | /// 25 | private readonly System.Random random; 26 | 27 | /// 28 | /// 随机算法适配器 29 | /// 30 | /// 随机算法 31 | public RandomAdaptor(System.Random random) 32 | { 33 | Guard.Requires(random != null); 34 | this.random = random; 35 | } 36 | 37 | /// 38 | /// 返回一个随机数 39 | /// 40 | /// 随机数 41 | public int Next() 42 | { 43 | return random.Next(); 44 | } 45 | 46 | /// 47 | /// 返回一个随机数 48 | /// 49 | /// 最小值 50 | /// 随机数 51 | public int Next(int maxValue) 52 | { 53 | return random.Next(maxValue); 54 | } 55 | 56 | /// 57 | /// 返回一个随机数 58 | /// 59 | /// 最小值 60 | /// 最大值 61 | /// 随机数 62 | public int Next(int minValue, int maxValue) 63 | { 64 | return random.Next(minValue, maxValue); 65 | } 66 | 67 | /// 68 | /// 生成随机数填充流 69 | /// 70 | /// 流 71 | public void NextBytes(byte[] buffer) 72 | { 73 | random.NextBytes(buffer); 74 | } 75 | 76 | /// 77 | /// 返回一个介于0到1之间的随机数 78 | /// 79 | /// 随机数 80 | public double NextDouble() 81 | { 82 | return random.NextDouble(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Random/RandomProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | #if CATLIB 13 | using CatLib.API.Random; 14 | using CatLib._3rd.MathNet.Numerics.Random; 15 | 16 | namespace CatLib.Random 17 | { 18 | /// 19 | /// 随机算法服务提供者 20 | /// 21 | public sealed class RandomProvider : IServiceProvider 22 | { 23 | /// 24 | /// 默认的随机算法 25 | /// 26 | public string DefaultRandomType { get; set; } 27 | 28 | /// 29 | /// 随机算法服务提供者 30 | /// 31 | public RandomProvider() 32 | { 33 | DefaultRandomType = RandomTypes.MersenneTwister; 34 | } 35 | 36 | /// 37 | /// 服务提供者初始化 38 | /// 39 | public void Init() 40 | { 41 | } 42 | 43 | /// 44 | /// 当注册服务提供者 45 | /// 46 | public void Register() 47 | { 48 | App.Singleton((_, __) => new RandomFactory(DefaultRandomType)) 49 | .Alias().Alias().OnResolving(instance => 50 | { 51 | var math = (RandomFactory)instance; 52 | InitedRandom(math); 53 | }); 54 | } 55 | 56 | /// 57 | /// 初始化随机库 58 | /// 59 | /// 随机库 60 | private void InitedRandom(RandomFactory randomFactory) 61 | { 62 | randomFactory.RegisterRandom(RandomTypes.MersenneTwister, (seed) => new RandomAdaptor(new MersenneTwister(seed))); 63 | randomFactory.RegisterRandom(RandomTypes.Xorshift, (seed) => new RandomAdaptor(new Xorshift(seed))); 64 | randomFactory.RegisterRandom(RandomTypes.WH2006, (seed) => new RandomAdaptor(new WH2006(seed))); 65 | randomFactory.RegisterRandom(RandomTypes.Mrg32k3a, (seed) => new RandomAdaptor(new Mrg32k3a(seed))); 66 | } 67 | } 68 | } 69 | #endif -------------------------------------------------------------------------------- /src/CatLib.Framework/Routing/Response.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using CatLib.API.Routing; 13 | 14 | namespace CatLib.Routing 15 | { 16 | /// 17 | /// 响应 18 | /// 19 | internal sealed class Response : IResponse 20 | { 21 | /// 22 | /// 上下文 23 | /// 24 | private object context; 25 | 26 | /// 27 | /// 设定上下文 28 | /// 29 | /// 上下文 30 | public object GetContext() 31 | { 32 | return context; 33 | } 34 | 35 | /// 36 | /// 设定上下文 37 | /// 38 | /// 上下文 39 | public void SetContext(object context) 40 | { 41 | this.context = context; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Routing/RouteAction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | using System; 13 | using System.Reflection; 14 | 15 | namespace CatLib.Routing 16 | { 17 | /// 18 | /// 路由行为 19 | /// 20 | internal sealed class RouteAction 21 | { 22 | /// 23 | /// 路由行为类型 24 | /// 25 | public enum RouteTypes 26 | { 27 | /// 28 | /// 回调形路由 29 | /// 30 | CallBack, 31 | 32 | /// 33 | /// 控制器调用 34 | /// 35 | ControllerCall, 36 | } 37 | 38 | /// 39 | /// 类型 40 | /// 41 | public RouteTypes Type { get; set; } 42 | 43 | /// 44 | /// 调用目标 45 | /// 46 | public object Target { get; set; } 47 | 48 | /// 49 | /// 调用方法 50 | /// 51 | public MethodInfo MethodInfo { get; set; } 52 | 53 | /// 54 | /// 控制器 55 | /// 56 | public Type Controller { get; set; } 57 | 58 | /// 59 | /// 调度函数名 60 | /// 61 | public string Method { get; set; } 62 | } 63 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Routing/RouterEvents.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Routing 13 | { 14 | /// 15 | /// 路由事件 16 | /// 17 | public sealed class RouterEvents 18 | { 19 | /// 20 | /// 当属性路由编译之前 21 | /// 22 | public static readonly string OnBeforeRouterAttrCompiler = "Router.OnBeforeRouterAttrCompiler"; 23 | 24 | /// 25 | /// 当路由调度之前 26 | /// 27 | public static readonly string OnDispatcher = "Router.OnDispatcher"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Routing/Validators/HostValidator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Routing 13 | { 14 | /// 15 | /// Host验证器 16 | /// 17 | internal sealed class HostValidator : IValidators 18 | { 19 | /// 20 | /// 是否匹配 21 | /// 22 | /// 路由条目 23 | /// 请求 24 | /// 是否匹配 25 | public bool Matches(Route route, Request request) 26 | { 27 | return route.Compiled.HostRegex.IsMatch(request.RouteUri.Host); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Routing/Validators/IValidators.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Routing 13 | { 14 | /// 15 | /// 验证器 16 | /// 17 | internal interface IValidators 18 | { 19 | /// 20 | /// 是否匹配 21 | /// 22 | /// 路由条目 23 | /// 请求 24 | /// 是否匹配 25 | bool Matches(Route route, Request request); 26 | } 27 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Routing/Validators/UriValidator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Routing 13 | { 14 | /// 15 | /// 统一资源定位符验证器 16 | /// 17 | internal sealed class UriValidator : IValidators 18 | { 19 | /// 20 | /// 是否匹配 21 | /// 22 | /// 路由条目 23 | /// 请求 24 | /// 是否匹配 25 | public bool Matches(Route route, Request request) 26 | { 27 | return route.Compiled.RouteRegex.IsMatch(request.RouteUri.NoParamFullPath); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Socket/3rd/kcp/switch_queue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace CatLib._3rd.Kcp 5 | { 6 | public class Utility 7 | { 8 | 9 | public static void Swap(ref QT t1, ref QT t2) 10 | { 11 | 12 | QT temp = t1; 13 | t1 = t2; 14 | t2 = temp; 15 | } 16 | } 17 | 18 | public class SwitchQueue where T : class 19 | { 20 | 21 | private Queue mConsumeQueue; 22 | private Queue mProduceQueue; 23 | 24 | public SwitchQueue() 25 | { 26 | mConsumeQueue = new Queue(16); 27 | mProduceQueue = new Queue(16); 28 | } 29 | 30 | public SwitchQueue(int capcity) 31 | { 32 | mConsumeQueue = new Queue(capcity); 33 | mProduceQueue = new Queue(capcity); 34 | } 35 | 36 | // producer 37 | public void Push(T obj) 38 | { 39 | lock (mProduceQueue) 40 | { 41 | mProduceQueue.Enqueue(obj); 42 | } 43 | } 44 | 45 | // consumer. 46 | public T Pop() 47 | { 48 | 49 | return (T) mConsumeQueue.Dequeue(); 50 | } 51 | 52 | public bool Empty() 53 | { 54 | return 0 == mConsumeQueue.Count; 55 | } 56 | 57 | public void Switch() 58 | { 59 | lock (mProduceQueue) 60 | { 61 | Utility.Swap(ref mConsumeQueue, ref mProduceQueue); 62 | } 63 | } 64 | 65 | public void Clear() 66 | { 67 | lock (mProduceQueue) 68 | { 69 | mConsumeQueue.Clear(); 70 | mProduceQueue.Clear(); 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Socket/ITick.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Socket 13 | { 14 | /// 15 | /// 需要定期调用 16 | /// 17 | internal interface ITick 18 | { 19 | /// 20 | /// 定时激活 21 | /// 22 | void Tick(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Tick/TickProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Tick 13 | { 14 | /// 15 | /// 时间摆钟服务提供者 16 | /// 17 | public sealed class TickProvider : IServiceProvider 18 | { 19 | /// 20 | /// Fps 21 | /// 22 | public int Fps { get; set; } 23 | 24 | /// 25 | /// 时间摆钟服务提供者 26 | /// 27 | public TickProvider() 28 | { 29 | Fps = 60; 30 | } 31 | 32 | /// 33 | /// 初始化服务提供者 34 | /// 35 | [Priority(5)] 36 | public void Init() 37 | { 38 | App.Make(Fps); 39 | } 40 | 41 | /// 42 | /// 注册服务提供者 43 | /// 44 | public void Register() 45 | { 46 | App.Singleton().OnRelease(instance => 47 | { 48 | var ticker = (TimeTicker)instance; 49 | ticker.Dispose(); 50 | }); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/CatLib.Framework/Translation/ISelector.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | namespace CatLib.Translation 13 | { 14 | /// 15 | /// 选择器 16 | /// 17 | public interface ISelector 18 | { 19 | /// 20 | /// 对翻译进行处理 21 | /// 22 | /// 语言字符串 23 | /// 数量 24 | /// 语言 25 | /// 处理后的字符串 26 | string Choose(string line, int number, string locale); 27 | } 28 | } -------------------------------------------------------------------------------- /src/CatLib.Framework/Translation/TranslationProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CatLib package. 3 | * 4 | * (c) Yu Bin 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | * 9 | * Document: http://catlib.io/ 10 | */ 11 | 12 | #if CATLIB 13 | using CatLib.API.Translation; 14 | 15 | namespace CatLib.Translation 16 | { 17 | /// 18 | /// 国际化服务提供者 19 | /// 20 | public sealed class TranslationProvider : IServiceProvider 21 | { 22 | /// 23 | /// 默认语言 24 | /// 25 | public string DefaultLanguage { get; set; } 26 | 27 | /// 28 | /// 备选语言 29 | /// 30 | public string FallbackLanguage { get; set; } 31 | 32 | /// 33 | /// 国际化服务提供者 34 | /// 35 | public TranslationProvider() 36 | { 37 | DefaultLanguage = Languages.Chinese; 38 | FallbackLanguage = Languages.Chinese; 39 | } 40 | 41 | /// 42 | /// 初始化 43 | /// 44 | public void Init() 45 | { 46 | } 47 | 48 | /// 49 | /// 当注册国际化服务时 50 | /// 51 | public void Register() 52 | { 53 | App.Singleton().Alias().OnResolving(instance => 54 | { 55 | var tran = (Translator)instance; 56 | tran.SetSelector(new Selector()); 57 | 58 | tran.SetLocale(DefaultLanguage); 59 | tran.SetFallback(FallbackLanguage); 60 | }); 61 | } 62 | } 63 | } 64 | #endif -------------------------------------------------------------------------------- /src/CatLib.Framework/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/settings.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | .*\.core\.dll$ 11 | .*\.api\.dll$ 12 | .*\.tests\.dll$ 13 | 14 | 15 | 16 | 17 | .*\.ExcludeFromCodeCoverageAttribute$ 18 | 19 | 20 | 21 | 22 | .*\\3rd\\.* 23 | .*\\Facade\\.* 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | --------------------------------------------------------------------------------