├── .gitattributes ├── .gitignore ├── Example ├── Assembly-CSharp-firstpass.csproj ├── Assembly-CSharp.csproj ├── Assets │ ├── Example │ │ ├── Readme.txt │ │ ├── Scenes │ │ │ └── SampleScene.unity │ │ └── Scripts │ │ │ ├── Handlers │ │ │ ├── Actor_TestHandler.cs │ │ │ ├── Frame_ClickMapHandler.cs │ │ │ └── TestHotfixSubscribMonoEvent_LogString.cs │ │ │ └── Init.cs │ └── Plugins │ │ └── ETClient.dll ├── ETClient.sln ├── Example.sln └── ProjectSettings │ ├── AudioManager.asset │ ├── ClusterInputManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── PresetManager.asset │ ├── ProjectSettings.asset │ ├── ProjectVersion.txt │ ├── QualitySettings.asset │ ├── TagManager.asset │ ├── TimeManager.asset │ └── UnityConnectSettings.asset ├── README.md └── Source ├── Base ├── DoubleMap.cs ├── Event │ ├── Env.cs │ ├── EnvKey.cs │ ├── EventAttribute.cs │ ├── EventIdType.cs │ └── IEvent.cs ├── Helper │ ├── ByteHelper.cs │ ├── EnumHelper.cs │ ├── FileHelper.cs │ ├── IdGenerater.cs │ ├── JsonHelper.cs │ ├── MD5Helper.cs │ ├── MethodInfoHelper.cs │ ├── NetHelper.cs │ ├── ObjectHelper.cs │ ├── RandomHelper.cs │ ├── StringHelper.cs │ └── TimeHelper.cs ├── Log.cs ├── LogType.cs ├── Math │ ├── AcosLookupTable.cs │ ├── Atan2LookupTable.cs │ ├── IntMath.cs │ ├── SinCosLookupTable.cs │ ├── VFactor.cs │ ├── VInt.cs │ ├── VInt2.cs │ ├── VInt3.cs │ ├── VLine.cs │ └── VRect.cs ├── MultiMap.cs ├── Object │ ├── BaseAttribute.cs │ ├── Component.cs │ ├── ComponentFactory.cs │ ├── ComponentWithId.cs │ ├── Entity.cs │ ├── EntityEventAttribute.cs │ ├── EventProxy.cs │ ├── EventSystem.cs │ ├── IAwakeSystem.cs │ ├── IChangeSystem.cs │ ├── IComponentSerialize.cs │ ├── IDestroySystem.cs │ ├── ILateUpdateSystem.cs │ ├── ILoadSystem.cs │ ├── ISerializeToEntity.cs │ ├── IStartSystem.cs │ ├── IUpdateSystem.cs │ ├── Object.cs │ ├── ObjectPool.cs │ └── ObjectSystemAttribute.cs ├── OneThreadSynchronizationContext.cs ├── QueueDictionary.cs ├── RecyclableMemoryStream │ ├── Events.cs │ ├── RecyclableMemoryStream.cs │ └── RecyclableMemoryStreamManager.cs ├── TryLocker.cs └── UnOrderMultiMap.cs ├── Component ├── SceneChangeComponent.cs └── TimerComponent.cs ├── ETClient.csproj ├── Entity ├── Game.cs ├── Scene.cs ├── UnityWebRequestAsync.cs └── WWWAsync.cs ├── Helper ├── ActionHelper.cs ├── Dumper.cs ├── GameObjectHelper.cs ├── PathHelper.cs ├── PositionHelper.cs └── ResourcesHelper.cs ├── Module ├── Actor │ └── IActorMessage.cs ├── ActorLocation │ └── IActorLocationMessage.cs ├── Filter │ ├── FilterAttribute.cs │ ├── FilterComponent.cs │ ├── FilterEntity.cs │ └── IFilter.cs ├── FrameSync │ ├── AnimatorComponent.cs │ ├── CameraComponent.cs │ ├── ClientFrameComponent.cs │ ├── FrameMessage.cs │ ├── FrameOpcode.cs │ ├── MoveComponent.cs │ ├── Player.cs │ ├── PlayerComponent.cs │ ├── PlayerFactory.cs │ ├── SessionComponent.cs │ ├── Unit.cs │ └── UnitComponent.cs ├── Message │ ├── AMHandler.cs │ ├── ErrorCode.cs │ ├── HotfixMessage.cs │ ├── HotfixOpcode.cs │ ├── IMHandler.cs │ ├── IMessage.cs │ ├── IMessageDispatcher.cs │ ├── IMessagePacker.cs │ ├── MessageAttribute.cs │ ├── MessageDispatherComponent.cs │ ├── MessageHandlerAttribute.cs │ ├── MessageInfo.cs │ ├── MessagePool.cs │ ├── MessageProxy.cs │ ├── NetOuterComponent.cs │ ├── NetOuterComponentSystem.cs │ ├── Network │ │ ├── AChannel.cs │ │ ├── AService.cs │ │ ├── Circularbuffer.cs │ │ ├── KCP │ │ │ ├── KChannel.cs │ │ │ ├── KService.cs │ │ │ └── Kcp.cs │ │ ├── NetworkHelper.cs │ │ ├── TCP │ │ │ ├── PacketParser.cs │ │ │ ├── TChannel.cs │ │ │ └── TService.cs │ │ └── WebSocket │ │ │ ├── WChannel.cs │ │ │ └── WService.cs │ ├── NetworkComponent.cs │ ├── Opcode.cs │ ├── OpcodeHelper.cs │ ├── OpcodeTypeComponent.cs │ ├── OuterMessage.cs │ ├── OuterMessageDispatcher.cs │ ├── OuterOpcode.cs │ ├── ProtobufHelper.cs │ ├── ProtobufPacker.cs │ ├── RpcException.cs │ ├── Session.cs │ └── SessionCallbackComponent.cs ├── Numeric │ ├── INumericWatcher.cs │ ├── NumericChangeEvent_NotifyWatcher.cs │ ├── NumericComponent.cs │ ├── NumericType.cs │ ├── NumericWatcherAttribute.cs │ ├── NumericWatcherComponent.cs │ └── NumericWatcher_Hp_ShowUI.cs └── UI │ ├── CanvasConfig.cs │ ├── IUIFactory.cs │ ├── LayerNames.cs │ ├── UI.cs │ ├── UIComponent.cs │ ├── UIFactoryAttribute.cs │ └── UIType.cs ├── Other ├── AppType.cs ├── Define.cs ├── ECSView.cs ├── IInstanceMethod.cs ├── MonoMethod.cs ├── MotionType.cs └── ReferenceCollector.cs ├── Properties └── AssemblyInfo.cs └── ThirdParty ├── Google.Protobuf ├── ByteArray.cs ├── ByteString.cs ├── CodedInputStream.cs ├── CodedOutputStream.ComputeSize.cs ├── CodedOutputStream.cs ├── FieldCodec.cs ├── ICustomDiagnosticMessage.cs ├── IMessage.cs ├── InvalidProtocolBufferException.cs ├── LimitedInputStream.cs ├── MessageExtensions.cs ├── MessageParser.cs ├── PropertyInfoExtensions.cs ├── ProtoPreconditions.cs ├── RepeatedField.cs ├── StreamExtensions.cs └── WireFormat.cs ├── Lib ├── UnityEngine.AnimationModule.dll ├── UnityEngine.AnimationModule.xml ├── UnityEngine.CoreModule.dll ├── UnityEngine.CoreModule.xml ├── UnityEngine.UI.dll ├── UnityEngine.UnityWebRequestModule.dll ├── UnityEngine.UnityWebRequestModule.xml ├── UnityEngine.UnityWebRequestWWWModule.dll ├── UnityEngine.UnityWebRequestWWWModule.xml ├── UnityEngine.dll └── UnityEngine.xml ├── LitJson ├── IJsonWrapper.cs ├── JsonData.cs ├── JsonException.cs ├── JsonMapper.cs ├── JsonMockWrapper.cs ├── JsonReader.cs ├── JsonWriter.cs ├── Lexer.cs └── ParserToken.cs └── MongoDB ├── MongoDB.Bson ├── BsonConstants.cs ├── BsonDefaults.cs ├── BsonExtensionMethods.cs ├── BsonUtils.cs ├── Exceptions │ ├── BsonException.cs │ ├── BsonInternalException.cs │ ├── BsonSerializationException.cs │ ├── DuplicateBsonMemberMapAttributeException.cs │ └── TruncationException.cs ├── IO │ ├── ArrayElementNameAccelerator.cs │ ├── BsonBinaryReader.cs │ ├── BsonBinaryReaderBookmark.cs │ ├── BsonBinaryReaderContext.cs │ ├── BsonBinaryReaderSettings.cs │ ├── BsonBinaryWriter.cs │ ├── BsonBinaryWriterContext.cs │ ├── BsonBinaryWriterSettings.cs │ ├── BsonChunkPool.cs │ ├── BsonDocumentReader.cs │ ├── BsonDocumentReaderBookmark.cs │ ├── BsonDocumentReaderContext.cs │ ├── BsonDocumentReaderSettings.cs │ ├── BsonDocumentWriter.cs │ ├── BsonDocumentWriterContext.cs │ ├── BsonDocumentWriterSettings.cs │ ├── BsonReader.cs │ ├── BsonReaderBookmark.cs │ ├── BsonReaderSettings.cs │ ├── BsonReaderState.cs │ ├── BsonStream.cs │ ├── BsonStreamAdapter.cs │ ├── BsonStreamExtensions.cs │ ├── BsonTrie.cs │ ├── BsonWriter.cs │ ├── BsonWriterSettings.cs │ ├── BsonWriterState.cs │ ├── ByteArrayBuffer.cs │ ├── ByteArrayChunk.cs │ ├── ByteBufferFactory.cs │ ├── ByteBufferSlice.cs │ ├── ByteBufferStream.cs │ ├── CStringUtf8Encoding.cs │ ├── ContextType.cs │ ├── IBsonChunk.cs │ ├── IBsonChunkSource.cs │ ├── IBsonReader.cs │ ├── IBsonReaderExtensions.cs │ ├── IBsonWriter.cs │ ├── IBsonWriterExtensions.cs │ ├── IByteBuffer.cs │ ├── IElementNameValidator.cs │ ├── INameDecoder.cs │ ├── InputBufferChunkSource.cs │ ├── JsonBuffer.cs │ ├── JsonConvert.cs │ ├── JsonOutputMode.cs │ ├── JsonReader.cs │ ├── JsonReaderBookmark.cs │ ├── JsonReaderContext.cs │ ├── JsonReaderSettings.cs │ ├── JsonScanner.cs │ ├── JsonToken.cs │ ├── JsonWriter.cs │ ├── JsonWriterContext.cs │ ├── JsonWriterSettings.cs │ ├── MultiChunkBuffer.cs │ ├── NoOpElementNameValidator.cs │ ├── OutputBufferChunkSource.cs │ ├── SingleChunkBuffer.cs │ ├── TrieNameDecoder.cs │ ├── Utf8Encodings.cs │ ├── Utf8Helper.cs │ └── Utf8NameDecoder.cs ├── ObjectModel │ ├── BsonArray.cs │ ├── BsonBinaryData.cs │ ├── BsonBinarySubType.cs │ ├── BsonBoolean.cs │ ├── BsonDateTime.cs │ ├── BsonDecimal128.cs │ ├── BsonDocument.cs │ ├── BsonDocumentWrapper.cs │ ├── BsonDouble.cs │ ├── BsonElement.cs │ ├── BsonInt32.cs │ ├── BsonInt64.cs │ ├── BsonJavaScript.cs │ ├── BsonJavaScriptWithScope.cs │ ├── BsonMaxKey.cs │ ├── BsonMinKey.cs │ ├── BsonNull.cs │ ├── BsonObjectId.cs │ ├── BsonRegularExpression.cs │ ├── BsonString.cs │ ├── BsonSymbol.cs │ ├── BsonSymbolTable.cs │ ├── BsonTimestamp.cs │ ├── BsonType.cs │ ├── BsonTypeMapper.cs │ ├── BsonTypeMapperOptions.cs │ ├── BsonUndefined.cs │ ├── BsonValue.cs │ ├── Decimal128.cs │ ├── GuidConverter.cs │ ├── GuidRepresentation.cs │ ├── IConvertibleToBsonDocument.cs │ ├── ICustomBsonTypeMapper.cs │ ├── LazyBsonArray.cs │ ├── LazyBsonDocument.cs │ ├── MaterializedOnDemandBsonArray.cs │ ├── MaterializedOnDemandBsonDocument.cs │ ├── ObjectId.cs │ ├── RawBsonArray.cs │ ├── RawBsonDocument.cs │ └── UInt128.cs ├── PowerOf2.cs └── Serialization │ ├── AttributedSerializationProvider.cs │ ├── Attributes │ ├── BsonConstructorAttribute.cs │ ├── BsonDateTimeOptionsAttribute.cs │ ├── BsonDefaultValueAttribute.cs │ ├── BsonDictionaryOptionsAttribute.cs │ ├── BsonDiscriminatorAttribute.cs │ ├── BsonElementAttribute.cs │ ├── BsonExtraElementsAttribute.cs │ ├── BsonFactoryMethodAttribute.cs │ ├── BsonIdAttribute.cs │ ├── BsonIgnoreAttribute.cs │ ├── BsonIgnoreExtraElementsAttribute.cs │ ├── BsonIgnoreIfDefaultAttribute.cs │ ├── BsonIgnoreIfNullAttribute.cs │ ├── BsonKnownTypesAttribute.cs │ ├── BsonMemberMapAttributeUsageAttribute.cs │ ├── BsonNoIdAttribute.cs │ ├── BsonRepresentationAttribute.cs │ ├── BsonRequiredAttribute.cs │ ├── BsonSerializationOptionsAttribute.cs │ ├── BsonSerializerAttribute.cs │ ├── BsonTimeSpanOptionsAttribute.cs │ ├── IBsonClassMapAttribute.cs │ ├── IBsonCreatorMapAttribute.cs │ ├── IBsonMemberMapAttribute.cs │ └── IBsonPostProcessingAttribute.cs │ ├── BsonClassMap.cs │ ├── BsonClassMapSerializationProvider.cs │ ├── BsonCreatorMap.cs │ ├── BsonDeserializationArgs.cs │ ├── BsonDeserializationContext.cs │ ├── BsonDocumentBackedClass.cs │ ├── BsonMemberMap.cs │ ├── BsonObjectModelSerializationProvider.cs │ ├── BsonSerializationArgs.cs │ ├── BsonSerializationContext.cs │ ├── BsonSerializationInfo.cs │ ├── BsonSerializationProviderBase.cs │ ├── BsonSerializer.cs │ ├── BsonSerializerRegistry.cs │ ├── CollectionsSerializationProvider.cs │ ├── Conventions │ ├── AttributeConventionPack.cs │ ├── CamelCaseElementNameConvention.cs │ ├── ConventionBase.cs │ ├── ConventionPack.cs │ ├── ConventionRegistry.cs │ ├── ConventionRunner.cs │ ├── DefaultConventionPack.cs │ ├── DelegateClassMapConvention.cs │ ├── DelegateMemberMapConvention.cs │ ├── DelegatePostProcessingConvention.cs │ ├── EnumRepresentationConvention.cs │ ├── HierarchicalDiscriminatorConvention.cs │ ├── IClassMapConvention.cs │ ├── IConvention.cs │ ├── IConventionPack.cs │ ├── ICreatorMapConvention.cs │ ├── IDiscriminatorConvention.cs │ ├── IMemberMapConvention.cs │ ├── IPostProcessingConvention.cs │ ├── IgnoreExtraElementsConvention.cs │ ├── IgnoreIfDefaultConvention.cs │ ├── IgnoreIfNullConvention.cs │ ├── ImmutableTypeClassMapConvention.cs │ ├── LookupIdGeneratorConvention.cs │ ├── MemberDefaultValueConvention.cs │ ├── MemberNameElementNameConvention.cs │ ├── NamedExtraElementsMemberConvention.cs │ ├── NamedIdMemberConvention.cs │ ├── NamedParameterCreatorMapConvention.cs │ ├── NoIdMemberConvention.cs │ ├── ObjectDiscriminatorConvention.cs │ ├── ReadWriteMemberFinderConvention.cs │ ├── ResetClassMapConvention.cs │ ├── ResetMemberMapsConvention.cs │ ├── ScalarDiscriminatorConvention.cs │ ├── StandardDiscriminatorConvention.cs │ └── StringObjectIdIdGeneratorConvention.cs │ ├── CreatorMapDelegateCompiler.cs │ ├── DiscriminatedInterfaceSerializationProvider.cs │ ├── ExpressionVisitor.cs │ ├── IBsonArraySerializer.cs │ ├── IBsonDictionarySerializer.cs │ ├── IBsonDocumentSerializer.cs │ ├── IBsonIdProvider.cs │ ├── IBsonPolymorphicSerializer.cs │ ├── IBsonSerializationProvider.cs │ ├── IBsonSerializer.cs │ ├── IBsonSerializerExtensions.cs │ ├── IBsonSerializerRegistry.cs │ ├── IChildSerializerConfigurable.cs │ ├── ICreatorSelector.cs │ ├── IDictionaryRepresentationConfigurable.cs │ ├── IIdGenerator.cs │ ├── IRepresentationConfigurable.cs │ ├── IRepresentationConverterConfigurable.cs │ ├── IdGenerators │ ├── AscendingGuidGenerator.cs │ ├── BsonBinaryDataGuidGenerator.cs │ ├── BsonObjectIdGenerator.cs │ ├── CombGuidGenerator.cs │ ├── GuidGenerator.cs │ ├── NullIdChecker.cs │ ├── ObjectIdGenerator.cs │ ├── StringObjectIdGenerator.cs │ └── ZeroIdChecker.cs │ ├── MostArgumentsCreatorSelector.cs │ ├── Options │ ├── DictionaryRepresentation.cs │ ├── RepresentationConverter.cs │ └── TimeSpanUnits.cs │ ├── PrimitiveSerializationProvider.cs │ ├── Serializers │ ├── AbstractClassSerializer.cs │ ├── ArraySerializer.cs │ ├── BitArraySerializer.cs │ ├── BooleanSerializer.cs │ ├── BsonArraySerializer.cs │ ├── BsonBinaryDataSerializer.cs │ ├── BsonBooleanSerializer.cs │ ├── BsonClassMapSerializer.cs │ ├── BsonDateTimeSerializer.cs │ ├── BsonDecimal128Serializer.cs │ ├── BsonDocumentBackedClassSerializer.cs │ ├── BsonDocumentSerializer.cs │ ├── BsonDocumentWrapperSerializer.cs │ ├── BsonDoubleSerializer.cs │ ├── BsonInt32Serializer.cs │ ├── BsonInt64Serializer.cs │ ├── BsonJavaScriptSerializer.cs │ ├── BsonJavaScriptWithScopeSerializer.cs │ ├── BsonMaxKeySerializer.cs │ ├── BsonMinKeySerializer.cs │ ├── BsonNullSerializer.cs │ ├── BsonObjectIdSerializer.cs │ ├── BsonRegularExpressionSerializer.cs │ ├── BsonStringSerializer.cs │ ├── BsonSymbolSerializer.cs │ ├── BsonTimestampSerializer.cs │ ├── BsonUndefinedSerializer.cs │ ├── BsonValueCSharpNullSerializer.cs │ ├── BsonValueSerializer.cs │ ├── BsonValueSerializerBase.cs │ ├── ByteArraySerializer.cs │ ├── ByteSerializer.cs │ ├── CharSerializer.cs │ ├── ClassSerializerBase.cs │ ├── CultureInfoSerializer.cs │ ├── DateTimeOffsetSerializer.cs │ ├── DateTimeSerializer.cs │ ├── Decimal128Serializer.cs │ ├── DecimalSerializer.cs │ ├── DictionaryInterfaceImplementerSerializer.cs │ ├── DictionarySerializerBase.cs │ ├── DiscriminatedInterfaceSerializer.cs │ ├── DiscriminatedWrapperSerializer.cs │ ├── DoubleSerializer.cs │ ├── DynamicDocumentBaseSerializer.cs │ ├── EnumSerializer.cs │ ├── EnumerableInterfaceImplementerSerializer.cs │ ├── EnumerableInterfaceImplementerSerializerBase.cs │ ├── EnumerableSerializerBase.cs │ ├── ExpandoObjectSerializer.cs │ ├── GuidSerializer.cs │ ├── IPAddressSerializer.cs │ ├── IPEndPointSerializer.cs │ ├── ImpliedImplementationInterfaceSerializer.cs │ ├── Int16Serializer.cs │ ├── Int32Serializer.cs │ ├── Int64Serializer.cs │ ├── KeyValuePairSerializer.cs │ ├── LazyBsonArraySerializer.cs │ ├── LazyBsonDocumentSerializer.cs │ ├── NullableGenericSerializer.cs │ ├── ObjectIdSerializer.cs │ ├── ObjectSerializer.cs │ ├── PartiallyRawBsonDocumentSerializer.cs │ ├── ProjectingDeserializer.cs │ ├── QueueSerializer.cs │ ├── RawBsonArraySerializer.cs │ ├── RawBsonDocumentSerializer.cs │ ├── ReadOnlyCollectionSerializer.cs │ ├── ReadOnlyCollectionSubclassSerializer.cs │ ├── SByteSerializer.cs │ ├── SealedClassSerializerBase.cs │ ├── SerializeAsNominalTypeSerializer.cs │ ├── SerializerBase.cs │ ├── SerializerHelper.cs │ ├── SingleSerializer.cs │ ├── StackSerializer.cs │ ├── StringSerializer.cs │ ├── StructSerializerBase.cs │ ├── ThreeDimensionalArraySerializer.cs │ ├── TimeSpanSerializer.cs │ ├── TupleSerializers.cs │ ├── TwoDimensionalArraySerializer.cs │ ├── UInt16Serializer.cs │ ├── UInt32Serializer.cs │ ├── UInt64Serializer.cs │ ├── UndiscriminatedActualTypeSerializer.cs │ ├── UriSerializer.cs │ └── VersionSerializer.cs │ ├── TypeMappingSerializationProvider.cs │ └── TypeNameDiscriminator.cs └── MongoDB.Shared ├── ApplicationNameHelper.cs ├── CanonicalDisposableClass.cs ├── CanonicalDisposableDerivedClass.cs ├── CanonicalDisposableStruct.cs ├── CanonicalEquatableClass.cs ├── CanonicalEquatableDerivedClass.cs ├── CanonicalEquatableStruct.cs ├── Hasher.cs └── IncrementalMD5.cs /Example/Assets/Example/Readme.txt: -------------------------------------------------------------------------------- 1 | ET客户端组件整理:kkc 2 | ET客户端组件开源地址:https://github.com/kkc001/ETClient 3 | 4 | ET源框架地址:https://github.com/egametang/ET 5 | 讨论QQ群 : 474643097 6 | 7 | ETClient版本说明 8 | 1.这是基于ET 4.0 ET客户端的组件版本,适合于学习,或附加其他项目使用 9 | 2.只供学习交流使用 10 | 3.只有一个极小的开发包dll,导入项目即可使用,基于C# 4.5开发请确认项目开启了C# 4.X的支持 11 | 12 | ETClient组件使用方法 13 | 1.使用Unity打开并导入组件,确认项目开启了C# 4.X的支持,运行Example下测试场景 14 | 2.服务端版本保持参考源框架 15 | -------------------------------------------------------------------------------- /Example/Assets/Example/Scripts/Handlers/Actor_TestHandler.cs: -------------------------------------------------------------------------------- 1 | using ETModel; 2 | 3 | [MessageHandler] 4 | public class Actor_TestHandler : AMHandler 5 | { 6 | protected override void Run(ETModel.Session session, Actor_Test message) 7 | { 8 | Log.Debug(message.Info); 9 | } 10 | } -------------------------------------------------------------------------------- /Example/Assets/Example/Scripts/Handlers/Frame_ClickMapHandler.cs: -------------------------------------------------------------------------------- 1 | using ETModel; 2 | using UnityEngine; 3 | 4 | [MessageHandler] 5 | public class Frame_ClickMapHandler : AMHandler 6 | { 7 | protected override void Run(ETModel.Session session, Frame_ClickMap message) 8 | { 9 | Unit unit = ETModel.Game.Scene.GetComponent().Get(message.Id); 10 | MoveComponent moveComponent = unit.GetComponent(); 11 | Vector3 dest = new Vector3(message.X / 1000f, 0, message.Z / 1000f); 12 | moveComponent.MoveToDest(dest, 1); 13 | moveComponent.Turn2D(dest - unit.Position); 14 | } 15 | } -------------------------------------------------------------------------------- /Example/Assets/Example/Scripts/Handlers/TestHotfixSubscribMonoEvent_LogString.cs: -------------------------------------------------------------------------------- 1 | using ETModel; 2 | 3 | // 分发数值监听 4 | [Event(ETModel.EventIdType.TestHotfixSubscribMonoEvent)] 5 | public class TestHotfixSubscribMonoEvent_LogString : AEvent 6 | { 7 | public override void Run(string info) 8 | { 9 | Log.Info(info); 10 | } 11 | } -------------------------------------------------------------------------------- /Example/Assets/Plugins/ETClient.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Example/Assets/Plugins/ETClient.dll -------------------------------------------------------------------------------- /Example/ETClient.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ETClient", "Assembly-CSharp.csproj", "{0232A416-5A37-FBDD-BB6B-BF4F64772C51}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ETClient", "Assembly-CSharp-firstpass.csproj", "{03055DC9-59FB-D067-4A90-C0211D6719D0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0232A416-5A37-FBDD-BB6B-BF4F64772C51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0232A416-5A37-FBDD-BB6B-BF4F64772C51}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0232A416-5A37-FBDD-BB6B-BF4F64772C51}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0232A416-5A37-FBDD-BB6B-BF4F64772C51}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {03055DC9-59FB-D067-4A90-C0211D6719D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {03055DC9-59FB-D067-4A90-C0211D6719D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {03055DC9-59FB-D067-4A90-C0211D6719D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {03055DC9-59FB-D067-4A90-C0211D6719D0}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /Example/Example.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Assembly-CSharp.csproj", "{CC8ECD15-D248-3044-CBD9-85E15547FD38}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {CC8ECD15-D248-3044-CBD9-85E15547FD38}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Example/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 1024 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_SpatializerPlugin: 15 | m_AmbisonicDecoderPlugin: 16 | m_DisableAudio: 0 17 | m_VirtualizeEffects: 1 18 | -------------------------------------------------------------------------------- /Example/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /Example/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 1 23 | m_ClothInterCollisionSettingsToggle: 0 24 | m_ContactPairsMode: 0 25 | m_BroadphaseType: 0 26 | m_WorldBounds: 27 | m_Center: {x: 0, y: 0, z: 0} 28 | m_Extent: {x: 250, y: 250, z: 250} 29 | m_WorldSubdivisions: 8 30 | -------------------------------------------------------------------------------- /Example/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: 8 | - enabled: 1 9 | path: Assets/Scenes/SampleScene.unity 10 | guid: 2cda990e2423bbf4892e6590ba056729 11 | m_configObjects: {} 12 | -------------------------------------------------------------------------------- /Example/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 1 11 | m_SpritePackerMode: 4 12 | m_SpritePackerPaddingPower: 1 13 | m_EtcTextureCompressorBehavior: 1 14 | m_EtcTextureFastCompressor: 1 15 | m_EtcTextureNormalCompressor: 2 16 | m_EtcTextureBestCompressor: 4 17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd 18 | m_ProjectGenerationRootNamespace: 19 | m_UserGeneratedProjectSuffix: 20 | m_CollabEditorSettings: 21 | inProgressEnabled: 1 22 | -------------------------------------------------------------------------------- /Example/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /Example/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /Example/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_AutoSimulation: 1 23 | m_QueriesHitTriggers: 1 24 | m_QueriesStartInColliders: 1 25 | m_ChangeStopsCallbacks: 0 26 | m_CallbacksOnDisable: 1 27 | m_AutoSyncTransforms: 1 28 | m_AlwaysShowColliders: 0 29 | m_ShowColliderSleep: 1 30 | m_ShowColliderContacts: 0 31 | m_ShowColliderAABB: 0 32 | m_ContactArrowScale: 0.2 33 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 34 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 35 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 36 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 37 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 38 | -------------------------------------------------------------------------------- /Example/ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | m_DefaultList: 7 | - type: 8 | m_NativeTypeID: 20 9 | m_ManagedTypePPtr: {fileID: 0} 10 | m_ManagedTypeFallback: 11 | defaultPresets: 12 | - m_Preset: {fileID: 2655988077585873504, guid: bfcfc320427f8224bbb7a96f3d3aebad, 13 | type: 2} 14 | -------------------------------------------------------------------------------- /Example/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2018.1.0f2 2 | -------------------------------------------------------------------------------- /Example/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /Example/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.0167 7 | Maximum Allowed Timestep: 0.1 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /Example/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | m_Enabled: 0 7 | m_TestMode: 0 8 | m_TestEventUrl: 9 | m_TestConfigUrl: 10 | m_TestInitMode: 0 11 | CrashReportingSettings: 12 | m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes 13 | m_NativeEventUrl: https://perf-events.cloud.unity3d.com/symbolicate 14 | m_Enabled: 0 15 | m_CaptureEditorExceptions: 1 16 | UnityPurchasingSettings: 17 | m_Enabled: 0 18 | m_TestMode: 0 19 | UnityAnalyticsSettings: 20 | m_Enabled: 1 21 | m_InitializeOnStartup: 1 22 | m_TestMode: 0 23 | m_TestEventUrl: 24 | m_TestConfigUrl: 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### ET客户端组件整理:kkc 2 | ### ET客户端组件开源地址:https://github.com/kkc001/ETClient 3 | 4 | ### ET源框架作者:熊猫,社区参与者 哲学绅士,Justin沙特王子 5 | ### ET源框架地址:https://github.com/egametang/ET 6 | __ET源框架讨论QQ群 : 474643097__ 7 | 8 | ## ETClient版本说明 9 | 1.这是基于ET 4.0 ET客户端的组件版本,适合于学习,或附加其他项目使用 10 | 11 | 2.只供学习交流使用 12 | 13 | 3.只有一个极小的开发包dll,导入项目即可使用,基于C# 4.5开发请确认项目开启了C# 4.X的支持 14 | 15 | ## ETClient运行使用方法 16 | 1.使用Unity打开并导入组件,确认项目开启了C# 4.X的支持,运行Example下测试场景 17 | 18 | 2.服务端版本保持参考源框架 19 | -------------------------------------------------------------------------------- /Source/Base/Event/Env.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using MongoDB.Bson.Serialization.Attributes; 5 | 6 | namespace ETModel 7 | { 8 | public class Env 9 | { 10 | [BsonElement, BsonIgnoreIfNull] 11 | private Dictionary values = new Dictionary(); 12 | 13 | public object this[EnvKey key] 14 | { 15 | get 16 | { 17 | return this.values[key]; 18 | } 19 | set 20 | { 21 | if (this.values == null) 22 | { 23 | this.values = new Dictionary(); 24 | } 25 | this.values[key] = value; 26 | } 27 | } 28 | 29 | public T Get(EnvKey key) 30 | { 31 | if (this.values == null || !this.values.ContainsKey(key)) 32 | { 33 | return default(T); 34 | } 35 | object value = values[key]; 36 | try 37 | { 38 | return (T) value; 39 | } 40 | catch (InvalidCastException e) 41 | { 42 | throw new Exception($"不能把{value.GetType()}转换为{typeof (T)}", e); 43 | } 44 | } 45 | 46 | public void Set(EnvKey key, object obj) 47 | { 48 | if (this.values == null) 49 | { 50 | this.values = new Dictionary(); 51 | } 52 | this.values[key] = obj; 53 | } 54 | 55 | public bool ContainKey(EnvKey key) 56 | { 57 | if (this.values == null) 58 | { 59 | return false; 60 | } 61 | return this.values.ContainsKey(key); 62 | } 63 | 64 | public void Remove(EnvKey key) 65 | { 66 | if (this.values == null) 67 | { 68 | return; 69 | } 70 | this.values.Remove(key); 71 | if (this.values.Count == 0) 72 | { 73 | this.values = null; 74 | } 75 | } 76 | 77 | public void Add(EnvKey key, object value) 78 | { 79 | if (this.values == null) 80 | { 81 | this.values = new Dictionary(); 82 | } 83 | this.values[key] = value; 84 | } 85 | 86 | public IEnumerator GetEnumerator() 87 | { 88 | return this.values.GetEnumerator(); 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /Source/Base/Event/EnvKey.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | /// 4 | /// 一般使用事件名+变量名 5 | /// 6 | public enum EnvKey 7 | { 8 | ChannelError 9 | } 10 | } -------------------------------------------------------------------------------- /Source/Base/Event/EventAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class EventAttribute: BaseAttribute 7 | { 8 | public string Type { get; } 9 | 10 | public EventAttribute(string type) 11 | { 12 | this.Type = type; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Source/Base/Event/EventIdType.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static class EventIdType 4 | { 5 | public const string RecvHotfixMessage = "RecvHotfixMessage"; 6 | public const string BehaviorTreeRunTreeEvent = "BehaviorTreeRunTreeEvent"; 7 | public const string BehaviorTreeOpenEditor = "BehaviorTreeOpenEditor"; 8 | public const string BehaviorTreeClickNode = "BehaviorTreeClickNode"; 9 | public const string BehaviorTreeAfterChangeNodeType = "BehaviorTreeAfterChangeNodeType"; 10 | public const string BehaviorTreeCreateNode = "BehaviorTreeCreateNode"; 11 | public const string BehaviorTreePropertyDesignerNewCreateClick = "BehaviorTreePropertyDesignerNewCreateClick"; 12 | public const string BehaviorTreeMouseInNode = "BehaviorTreeMouseInNode"; 13 | public const string BehaviorTreeConnectState = "BehaviorTreeConnectState"; 14 | public const string BehaviorTreeReplaceClick = "BehaviorTreeReplaceClick"; 15 | public const string BehaviorTreeRightDesignerDrag = "BehaviorTreeRightDesignerDrag"; 16 | public const string SessionRecvMessage = "SessionRecvMessage"; 17 | public const string NumbericChange = "NumbericChange"; 18 | public const string MessageDeserializeFinish = "MessageDeserializeFinish"; 19 | public const string SceneChange = "SceneChange"; 20 | public const string FrameUpdate = "FrameUpdate"; 21 | public const string LoadingBegin = "LoadingBegin"; 22 | public const string LoadingFinish = "LoadingFinish"; 23 | public const string TestHotfixSubscribMonoEvent = "TestHotfixSubscribMonoEvent"; 24 | public const string MaxModelEvent = "MaxModelEvent"; 25 | } 26 | } -------------------------------------------------------------------------------- /Source/Base/Helper/EnumHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public static class EnumHelper 6 | { 7 | public static int EnumIndex(int value) 8 | { 9 | int i = 0; 10 | foreach (object v in Enum.GetValues(typeof (T))) 11 | { 12 | if ((int) v == value) 13 | { 14 | return i; 15 | } 16 | ++i; 17 | } 18 | return -1; 19 | } 20 | 21 | public static T FromString(string str) 22 | { 23 | if (!Enum.IsDefined(typeof(T), str)) 24 | { 25 | return default(T); 26 | } 27 | return (T)Enum.Parse(typeof(T), str); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Source/Base/Helper/FileHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace ETModel 8 | { 9 | public static class FileHelper 10 | { 11 | public static void GetAllFiles(List files, string dir) 12 | { 13 | string[] fls = Directory.GetFiles(dir); 14 | foreach (string fl in fls) 15 | { 16 | files.Add(fl); 17 | } 18 | 19 | string[] subDirs = Directory.GetDirectories(dir); 20 | foreach (string subDir in subDirs) 21 | { 22 | GetAllFiles(files, subDir); 23 | } 24 | } 25 | 26 | public static void CleanDirectory(string dir) 27 | { 28 | foreach (string subdir in Directory.GetDirectories(dir)) 29 | { 30 | Directory.Delete(subdir, true); 31 | } 32 | 33 | foreach (string subFile in Directory.GetFiles(dir)) 34 | { 35 | File.Delete(subFile); 36 | } 37 | } 38 | 39 | public static void CopyDirectory(string srcDir, string tgtDir) 40 | { 41 | DirectoryInfo source = new DirectoryInfo(srcDir); 42 | DirectoryInfo target = new DirectoryInfo(tgtDir); 43 | 44 | if (target.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase)) 45 | { 46 | throw new Exception("父目录不能拷贝到子目录!"); 47 | } 48 | 49 | if (!source.Exists) 50 | { 51 | return; 52 | } 53 | 54 | if (!target.Exists) 55 | { 56 | target.Create(); 57 | } 58 | 59 | FileInfo[] files = source.GetFiles(); 60 | 61 | for (int i = 0; i < files.Length; i++) 62 | { 63 | File.Copy(files[i].FullName, Path.Combine(target.FullName, files[i].Name), true); 64 | } 65 | 66 | DirectoryInfo[] dirs = source.GetDirectories(); 67 | 68 | for (int j = 0; j < dirs.Length; j++) 69 | { 70 | CopyDirectory(dirs[j].FullName, Path.Combine(target.FullName, dirs[j].Name)); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Source/Base/Helper/IdGenerater.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static class IdGenerater 4 | { 5 | public static long AppId { private get; set; } 6 | 7 | private static ushort value; 8 | 9 | public static long GenerateId() 10 | { 11 | long time = TimeHelper.ClientNowSeconds(); 12 | 13 | return (AppId << 48) + (time << 16) + ++value; 14 | } 15 | 16 | public static int GetAppIdFromId(long id) 17 | { 18 | return (int)(id >> 48); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Source/Base/Helper/JsonHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using ETModel.Json; 4 | 5 | namespace ETModel 6 | { 7 | public static class JsonHelper 8 | { 9 | public static string ToJson(object obj) 10 | { 11 | return JsonMapper.ToJson(obj); 12 | } 13 | 14 | public static T FromJson(string str) 15 | { 16 | T t = JsonMapper.ToObject(str); 17 | ISupportInitialize iSupportInitialize = t as ISupportInitialize; 18 | if (iSupportInitialize == null) 19 | { 20 | return t; 21 | } 22 | iSupportInitialize.EndInit(); 23 | return t; 24 | } 25 | 26 | public static object FromJson(Type type, string str) 27 | { 28 | object t = JsonMapper.ToObject(type, str); 29 | ISupportInitialize iSupportInitialize = t as ISupportInitialize; 30 | if (iSupportInitialize == null) 31 | { 32 | return t; 33 | } 34 | iSupportInitialize.EndInit(); 35 | return t; 36 | } 37 | 38 | public static T Clone(T t) 39 | { 40 | return FromJson(ToJson(t)); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Source/Base/Helper/MD5Helper.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Security.Cryptography; 3 | 4 | namespace ETModel 5 | { 6 | public static class MD5Helper 7 | { 8 | public static string FileMD5(string filePath) 9 | { 10 | byte[] retVal; 11 | using (FileStream file = new FileStream(filePath, FileMode.Open)) 12 | { 13 | MD5 md5 = new MD5CryptoServiceProvider(); 14 | retVal = md5.ComputeHash(file); 15 | } 16 | return retVal.ToHex("x2"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/Base/Helper/MethodInfoHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace ETModel 4 | { 5 | public static class MethodInfoHelper 6 | { 7 | public static void Run(this MethodInfo methodInfo, object obj, params object[] param) 8 | { 9 | 10 | if (methodInfo.IsStatic) 11 | { 12 | object[] p = new object[param.Length + 1]; 13 | p[0] = obj; 14 | for (int i = 0; i < param.Length; ++i) 15 | { 16 | p[i + 1] = param[i]; 17 | } 18 | methodInfo.Invoke(null, p); 19 | } 20 | else 21 | { 22 | methodInfo.Invoke(obj, param); 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Source/Base/Helper/NetHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net; 3 | 4 | namespace ETModel 5 | { 6 | public static class NetHelper 7 | { 8 | public static string[] GetAddressIPs() 9 | { 10 | //获取本地的IP地址 11 | List addressIPs = new List(); 12 | foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList) 13 | { 14 | if (address.AddressFamily.ToString() == "InterNetwork") 15 | { 16 | addressIPs.Add(address.ToString()); 17 | } 18 | } 19 | return addressIPs.ToArray(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Base/Helper/ObjectHelper.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static class ObjectHelper 4 | { 5 | public static void Swap(ref T t1, ref T t2) 6 | { 7 | T t3 = t1; 8 | t1 = t2; 9 | t2 = t3; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Source/Base/Helper/RandomHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public static class RandomHelper 6 | { 7 | private static readonly Random random = new Random(); 8 | 9 | public static UInt64 RandUInt64() 10 | { 11 | var bytes = new byte[8]; 12 | random.NextBytes(bytes); 13 | return BitConverter.ToUInt64(bytes, 0); 14 | } 15 | 16 | public static Int64 RandInt64() 17 | { 18 | var bytes = new byte[8]; 19 | random.NextBytes(bytes); 20 | return BitConverter.ToInt64(bytes, 0); 21 | } 22 | 23 | /// 24 | /// 获取lower与Upper之间的随机数 25 | /// 26 | /// 27 | /// 28 | /// 29 | public static int RandomNumber(int lower, int upper) 30 | { 31 | int value = random.Next(lower, upper); 32 | return value; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Source/Base/Helper/StringHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Text; 5 | 6 | namespace ETModel 7 | { 8 | public static class StringHelper 9 | { 10 | public static IEnumerable ToBytes(this string str) 11 | { 12 | byte[] byteArray = Encoding.Default.GetBytes(str); 13 | return byteArray; 14 | } 15 | 16 | public static byte[] ToByteArray(this string str) 17 | { 18 | byte[] byteArray = Encoding.Default.GetBytes(str); 19 | return byteArray; 20 | } 21 | 22 | public static byte[] ToUtf8(this string str) 23 | { 24 | byte[] byteArray = Encoding.UTF8.GetBytes(str); 25 | return byteArray; 26 | } 27 | 28 | public static byte[] HexToBytes(this string hexString) 29 | { 30 | if (hexString.Length % 2 != 0) 31 | { 32 | throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", hexString)); 33 | } 34 | 35 | var hexAsBytes = new byte[hexString.Length / 2]; 36 | for (int index = 0; index < hexAsBytes.Length; index++) 37 | { 38 | string byteValue = ""; 39 | byteValue += hexString[index * 2]; 40 | byteValue += hexString[index * 2 + 1]; 41 | hexAsBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture); 42 | } 43 | return hexAsBytes; 44 | } 45 | 46 | public static string Fmt(this string text, params object[] args) 47 | { 48 | return string.Format(text, args); 49 | } 50 | 51 | public static string ListToString(this List list) 52 | { 53 | StringBuilder sb = new StringBuilder(); 54 | foreach (T t in list) 55 | { 56 | sb.Append(t); 57 | sb.Append(","); 58 | } 59 | return sb.ToString(); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Source/Base/Helper/TimeHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public static class TimeHelper 6 | { 7 | private static readonly long epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks; 8 | /// 9 | /// 客户端时间 10 | /// 11 | /// 12 | public static long ClientNow() 13 | { 14 | return (DateTime.UtcNow.Ticks - epoch) / 10000; 15 | } 16 | 17 | public static long ClientNowSeconds() 18 | { 19 | return (DateTime.UtcNow.Ticks - epoch) / 10000000; 20 | } 21 | 22 | /// 23 | /// 登陆前是客户端时间,登陆后是同步过的服务器时间 24 | /// 25 | /// 26 | public static long Now() 27 | { 28 | return ClientNow(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Source/Base/Log.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public static class Log 6 | { 7 | public static void Trace(string msg) 8 | { 9 | UnityEngine.Debug.Log(msg); 10 | } 11 | 12 | public static void Warning(string msg) 13 | { 14 | UnityEngine.Debug.LogWarning(msg); 15 | } 16 | 17 | public static void Info(string msg) 18 | { 19 | UnityEngine.Debug.Log(msg); 20 | } 21 | 22 | public static void Error(Exception e) 23 | { 24 | UnityEngine.Debug.LogError(e.ToString()); 25 | } 26 | 27 | public static void Error(string msg) 28 | { 29 | UnityEngine.Debug.LogError(msg); 30 | } 31 | 32 | public static void Debug(string msg) 33 | { 34 | UnityEngine.Debug.Log(msg); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Base/LogType.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public enum LogType 4 | { 5 | Warning, 6 | Info, 7 | Debug, 8 | Error, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Source/Base/Math/VInt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [Serializable] 4 | public struct VInt 5 | { 6 | public int i; 7 | 8 | public float scalar 9 | { 10 | get 11 | { 12 | return (float)this.i * 0.001f; 13 | } 14 | } 15 | 16 | public VInt(int i) 17 | { 18 | this.i = i; 19 | } 20 | 21 | public VInt(float f) 22 | { 23 | this.i = (int)Math.Round((double)(f * 1000f)); 24 | } 25 | 26 | public override bool Equals(object o) 27 | { 28 | if (o == null) 29 | { 30 | return false; 31 | } 32 | VInt vInt = (VInt)o; 33 | return this.i == vInt.i; 34 | } 35 | 36 | public override int GetHashCode() 37 | { 38 | return this.i.GetHashCode(); 39 | } 40 | 41 | public static VInt Min(VInt a, VInt b) 42 | { 43 | return new VInt(Math.Min(a.i, b.i)); 44 | } 45 | 46 | public static VInt Max(VInt a, VInt b) 47 | { 48 | return new VInt(Math.Max(a.i, b.i)); 49 | } 50 | 51 | public override string ToString() 52 | { 53 | return this.scalar.ToString(); 54 | } 55 | 56 | public static explicit operator VInt(float f) 57 | { 58 | return new VInt((int)Math.Round((double)(f * 1000f))); 59 | } 60 | 61 | public static implicit operator VInt(int i) 62 | { 63 | return new VInt(i); 64 | } 65 | 66 | public static explicit operator float(VInt ob) 67 | { 68 | return (float)ob.i * 0.001f; 69 | } 70 | 71 | public static explicit operator long(VInt ob) 72 | { 73 | return (long)ob.i; 74 | } 75 | 76 | public static VInt operator +(VInt a, VInt b) 77 | { 78 | return new VInt(a.i + b.i); 79 | } 80 | 81 | public static VInt operator -(VInt a, VInt b) 82 | { 83 | return new VInt(a.i - b.i); 84 | } 85 | 86 | public static bool operator ==(VInt a, VInt b) 87 | { 88 | return a.i == b.i; 89 | } 90 | 91 | public static bool operator !=(VInt a, VInt b) 92 | { 93 | return a.i != b.i; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Source/Base/Math/VLine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public struct VLine 4 | { 5 | public VInt2 point; 6 | 7 | public VInt2 direction; 8 | } 9 | -------------------------------------------------------------------------------- /Source/Base/Object/BaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class BaseAttribute: Attribute 7 | { 8 | public Type AttributeType { get; } 9 | 10 | public BaseAttribute() 11 | { 12 | this.AttributeType = this.GetType(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Source/Base/Object/Component.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using MongoDB.Bson.Serialization.Attributes; 3 | 4 | namespace ETModel 5 | { 6 | [BsonIgnoreExtraElements] 7 | public abstract class Component : Object, IDisposable, IComponentSerialize 8 | { 9 | // 只有Game.EventSystem.Add方法中会设置该值,如果new出来的对象不想加入Game.EventSystem中,则需要自己在构造函数中设置 10 | [BsonIgnore] 11 | public long InstanceId { get; protected set; } 12 | 13 | [BsonIgnore] 14 | private bool isFromPool; 15 | 16 | [BsonIgnore] 17 | public bool IsFromPool 18 | { 19 | get 20 | { 21 | return this.isFromPool; 22 | } 23 | set 24 | { 25 | this.isFromPool = value; 26 | 27 | if (!this.isFromPool) 28 | { 29 | return; 30 | } 31 | 32 | this.InstanceId = IdGenerater.GenerateId(); 33 | Game.EventSystem.Add(this); 34 | } 35 | } 36 | 37 | [BsonIgnore] 38 | public bool IsDisposed 39 | { 40 | get 41 | { 42 | return this.InstanceId == 0; 43 | } 44 | } 45 | 46 | [BsonIgnore] 47 | public Component Parent { get; set; } 48 | 49 | public T GetParent() where T : Component 50 | { 51 | return this.Parent as T; 52 | } 53 | 54 | [BsonIgnore] 55 | public Entity Entity 56 | { 57 | get 58 | { 59 | return this.Parent as Entity; 60 | } 61 | } 62 | 63 | protected Component() 64 | { 65 | } 66 | 67 | public virtual void Dispose() 68 | { 69 | if (this.IsDisposed) 70 | { 71 | return; 72 | } 73 | 74 | // 触发Destroy事件 75 | Game.EventSystem.Destroy(this); 76 | 77 | Game.EventSystem.Remove(this.InstanceId); 78 | 79 | this.InstanceId = 0; 80 | 81 | if (this.IsFromPool) 82 | { 83 | Game.ObjectPool.Recycle(this); 84 | } 85 | } 86 | 87 | public virtual void BeginSerialize() 88 | { 89 | } 90 | 91 | public virtual void EndDeSerialize() 92 | { 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /Source/Base/Object/ComponentWithId.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using MongoDB.Bson.Serialization.Attributes; 3 | 4 | namespace ETModel 5 | { 6 | [BsonIgnoreExtraElements] 7 | public abstract class ComponentWithId : Component 8 | { 9 | [BsonIgnoreIfDefault] 10 | [BsonDefaultValue(0L)] 11 | [BsonElement] 12 | [BsonId] 13 | public long Id { get; set; } 14 | 15 | protected ComponentWithId() 16 | { 17 | } 18 | 19 | protected ComponentWithId(long id) 20 | { 21 | this.Id = id; 22 | } 23 | 24 | public override void Dispose() 25 | { 26 | if (this.IsDisposed) 27 | { 28 | return; 29 | } 30 | 31 | base.Dispose(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Source/Base/Object/EntityEventAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class EntityEventAttribute: Attribute 7 | { 8 | public int ClassType; 9 | 10 | public EntityEventAttribute(int classType) 11 | { 12 | this.ClassType = classType; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Source/Base/Object/EventProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ETModel 5 | { 6 | public class EventProxy: IEvent 7 | { 8 | public Action> action; 9 | public List param = new List(); 10 | 11 | public EventProxy(Action> action) 12 | { 13 | this.action = action; 14 | } 15 | 16 | public void Handle() 17 | { 18 | this.param.Clear(); 19 | this.action.Invoke(this.param); 20 | } 21 | 22 | public void Handle(object a) 23 | { 24 | this.param.Clear(); 25 | this.param.Add(a); 26 | this.action.Invoke(this.param); 27 | } 28 | 29 | public void Handle(object a, object b) 30 | { 31 | this.param.Clear(); 32 | this.param.Add(a); 33 | this.param.Add(b); 34 | this.action.Invoke(this.param); 35 | } 36 | 37 | public void Handle(object a, object b, object c) 38 | { 39 | this.param.Clear(); 40 | this.param.Add(a); 41 | this.param.Add(b); 42 | this.param.Add(c); 43 | this.action.Invoke(this.param); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/Base/Object/IAwakeSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface IAwakeSystem 6 | { 7 | Type Type(); 8 | } 9 | 10 | public interface IAwake 11 | { 12 | void Run(object o); 13 | } 14 | 15 | public interface IAwake 16 | { 17 | void Run(object o, A a); 18 | } 19 | 20 | public interface IAwake 21 | { 22 | void Run(object o, A a, B b); 23 | } 24 | 25 | public interface IAwake 26 | { 27 | void Run(object o, A a, B b, C c); 28 | } 29 | 30 | public abstract class AwakeSystem : IAwakeSystem, IAwake 31 | { 32 | public Type Type() 33 | { 34 | return typeof(T); 35 | } 36 | 37 | public void Run(object o) 38 | { 39 | this.Awake((T)o); 40 | } 41 | 42 | public abstract void Awake(T self); 43 | } 44 | 45 | public abstract class AwakeSystem : IAwakeSystem, IAwake 46 | { 47 | public Type Type() 48 | { 49 | return typeof(T); 50 | } 51 | 52 | public void Run(object o, A a) 53 | { 54 | this.Awake((T)o, a); 55 | } 56 | 57 | public abstract void Awake(T self, A a); 58 | } 59 | 60 | public abstract class AwakeSystem : IAwakeSystem, IAwake 61 | { 62 | public Type Type() 63 | { 64 | return typeof(T); 65 | } 66 | 67 | public void Run(object o, A a, B b) 68 | { 69 | this.Awake((T)o, a, b); 70 | } 71 | 72 | public abstract void Awake(T self, A a, B b); 73 | } 74 | 75 | public abstract class AwakeSystem : IAwakeSystem, IAwake 76 | { 77 | public Type Type() 78 | { 79 | return typeof(T); 80 | } 81 | 82 | public void Run(object o, A a, B b, C c) 83 | { 84 | this.Awake((T)o, a, b, c); 85 | } 86 | 87 | public abstract void Awake(T self, A a, B b, C c); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Source/Base/Object/IChangeSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface IChangeSystem 6 | { 7 | Type Type(); 8 | void Run(object o); 9 | } 10 | 11 | public abstract class ChangeSystem : IChangeSystem 12 | { 13 | public void Run(object o) 14 | { 15 | this.Change((T)o); 16 | } 17 | 18 | public Type Type() 19 | { 20 | return typeof(T); 21 | } 22 | 23 | public abstract void Change(T self); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Base/Object/IComponentSerialize.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | // 在序列化前或者反序列化之后需要做一些操作,可以实现该接口,该接口的方法需要手动调用 4 | // 相比ISupportInitialize接口,BeginSerialize在BeginInit之前调用,EndDeSerialize在EndInit之后调用 5 | // 并且需要手动调用,可以在反序列化之后,在次方法中将注册组件到EventSystem之中等等 6 | public interface IComponentSerialize 7 | { 8 | // 序列化之前调用 9 | void BeginSerialize(); 10 | // 反序列化之后调用 11 | void EndDeSerialize(); 12 | } 13 | } -------------------------------------------------------------------------------- /Source/Base/Object/IDestroySystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface IDestroySystem 6 | { 7 | Type Type(); 8 | void Run(object o); 9 | } 10 | 11 | public abstract class DestroySystem : IDestroySystem 12 | { 13 | public void Run(object o) 14 | { 15 | this.Destroy((T)o); 16 | } 17 | 18 | public Type Type() 19 | { 20 | return typeof(T); 21 | } 22 | 23 | public abstract void Destroy(T self); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Base/Object/ILateUpdateSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface ILateUpdateSystem 6 | { 7 | Type Type(); 8 | void Run(object o); 9 | } 10 | 11 | public abstract class LateUpdateSystem : ILateUpdateSystem 12 | { 13 | public void Run(object o) 14 | { 15 | this.LateUpdate((T)o); 16 | } 17 | 18 | public Type Type() 19 | { 20 | return typeof(T); 21 | } 22 | 23 | public abstract void LateUpdate(T self); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Base/Object/ILoadSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface ILoadSystem 6 | { 7 | Type Type(); 8 | void Run(object o); 9 | } 10 | 11 | public abstract class LoadSystem : ILoadSystem 12 | { 13 | public void Run(object o) 14 | { 15 | this.Load((T)o); 16 | } 17 | 18 | public Type Type() 19 | { 20 | return typeof(T); 21 | } 22 | 23 | public abstract void Load(T self); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Base/Object/ISerializeToEntity.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public interface ISerializeToEntity 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /Source/Base/Object/IStartSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface IStartSystem 6 | { 7 | Type Type(); 8 | void Run(object o); 9 | } 10 | 11 | public abstract class StartSystem : IStartSystem 12 | { 13 | public void Run(object o) 14 | { 15 | this.Start((T)o); 16 | } 17 | 18 | public Type Type() 19 | { 20 | return typeof(T); 21 | } 22 | 23 | public abstract void Start(T self); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Base/Object/IUpdateSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface IUpdateSystem 6 | { 7 | Type Type(); 8 | void Run(object o); 9 | } 10 | 11 | public abstract class UpdateSystem : IUpdateSystem 12 | { 13 | public void Run(object o) 14 | { 15 | this.Update((T)o); 16 | } 17 | 18 | public Type Type() 19 | { 20 | return typeof(T); 21 | } 22 | 23 | public abstract void Update(T self); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Base/Object/Object.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace ETModel 4 | { 5 | public abstract class Object: ISupportInitialize 6 | { 7 | public virtual void BeginInit() 8 | { 9 | } 10 | 11 | public virtual void EndInit() 12 | { 13 | } 14 | 15 | public override string ToString() 16 | { 17 | return JsonHelper.ToJson(this); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Source/Base/Object/ObjectPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ETModel 5 | { 6 | public class ObjectPool 7 | { 8 | private readonly Dictionary> dictionary = new Dictionary>(); 9 | 10 | public Component Fetch(Type type) 11 | { 12 | Queue queue; 13 | if (!this.dictionary.TryGetValue(type, out queue)) 14 | { 15 | queue = new Queue(); 16 | this.dictionary.Add(type, queue); 17 | } 18 | Component obj; 19 | if (queue.Count > 0) 20 | { 21 | obj = queue.Dequeue(); 22 | } 23 | else 24 | { 25 | obj = (Component)Activator.CreateInstance(type); 26 | } 27 | obj.IsFromPool = true; 28 | return obj; 29 | } 30 | 31 | public T Fetch() where T: Component 32 | { 33 | T t = (T) this.Fetch(typeof(T)); 34 | return t; 35 | } 36 | 37 | public void Recycle(Component obj) 38 | { 39 | Type type = obj.GetType(); 40 | Queue queue; 41 | if (!this.dictionary.TryGetValue(type, out queue)) 42 | { 43 | queue = new Queue(); 44 | this.dictionary.Add(type, queue); 45 | } 46 | queue.Enqueue(obj); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Source/Base/Object/ObjectSystemAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class ObjectSystemAttribute: BaseAttribute 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Source/Base/OneThreadSynchronizationContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Threading; 4 | 5 | namespace ETModel 6 | { 7 | public class OneThreadSynchronizationContext : SynchronizationContext 8 | { 9 | public static OneThreadSynchronizationContext Instance { get; } = new OneThreadSynchronizationContext(); 10 | 11 | // 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行 12 | private readonly ConcurrentQueue queue = new ConcurrentQueue(); 13 | 14 | private Action a; 15 | 16 | public void Update() 17 | { 18 | while (true) 19 | { 20 | if (!this.queue.TryDequeue(out a)) 21 | { 22 | return; 23 | } 24 | a(); 25 | } 26 | } 27 | 28 | public override void Post(SendOrPostCallback callback, object state) 29 | { 30 | this.queue.Enqueue(() => { callback(state); }); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Source/Base/QueueDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ETModel 4 | { 5 | public class QueueDictionary 6 | { 7 | private readonly List list = new List(); 8 | private readonly Dictionary dictionary = new Dictionary(); 9 | 10 | public void Enqueue(T t, K k) 11 | { 12 | this.list.Add(t); 13 | this.dictionary.Add(t, k); 14 | } 15 | 16 | public void Dequeue() 17 | { 18 | if (this.list.Count == 0) 19 | { 20 | return; 21 | } 22 | T t = this.list[0]; 23 | this.list.RemoveAt(0); 24 | this.dictionary.Remove(t); 25 | } 26 | 27 | public void Remove(T t) 28 | { 29 | this.list.Remove(t); 30 | this.dictionary.Remove(t); 31 | } 32 | 33 | public bool ContainsKey(T t) 34 | { 35 | return this.dictionary.ContainsKey(t); 36 | } 37 | 38 | public int Count 39 | { 40 | get 41 | { 42 | return this.list.Count; 43 | } 44 | } 45 | 46 | public T FirstKey 47 | { 48 | get 49 | { 50 | return this.list[0]; 51 | } 52 | } 53 | 54 | public K FirstValue 55 | { 56 | get 57 | { 58 | T t = this.list[0]; 59 | return this[t]; 60 | } 61 | } 62 | 63 | public K this[T t] 64 | { 65 | get 66 | { 67 | return this.dictionary[t]; 68 | } 69 | } 70 | 71 | public void Clear() 72 | { 73 | this.list.Clear(); 74 | this.dictionary.Clear(); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Source/Base/TryLocker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace ETModel 5 | { 6 | public class TryLock : IDisposable 7 | { 8 | private object locked; 9 | 10 | public bool HasLock { get; private set; } 11 | 12 | public TryLock(object obj) 13 | { 14 | if (!Monitor.TryEnter(obj)) 15 | { 16 | return; 17 | } 18 | 19 | this.HasLock = true; 20 | this.locked = obj; 21 | } 22 | 23 | public void Dispose() 24 | { 25 | if (!this.HasLock) 26 | { 27 | return; 28 | } 29 | 30 | Monitor.Exit(this.locked); 31 | this.locked = null; 32 | this.HasLock = false; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Source/Component/SceneChangeComponent.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using UnityEngine; 3 | using UnityEngine.SceneManagement; 4 | 5 | namespace ETModel 6 | { 7 | [ObjectSystem] 8 | public class SceneChangeComponentUpdateSystem: UpdateSystem 9 | { 10 | public override void Update(SceneChangeComponent self) 11 | { 12 | if (self.loadMapOperation.isDone) 13 | { 14 | self.tcs.SetResult(true); 15 | } 16 | } 17 | } 18 | 19 | public class SceneChangeComponent: Component 20 | { 21 | public AsyncOperation loadMapOperation; 22 | public TaskCompletionSource tcs; 23 | public float deltaTime; 24 | public int lastProgress = 0; 25 | 26 | public Task ChangeSceneAsync(SceneType sceneEnum) 27 | { 28 | this.tcs = new TaskCompletionSource(); 29 | // 加载map 30 | this.loadMapOperation = SceneManager.LoadSceneAsync(sceneEnum.ToString()); 31 | return this.tcs.Task; 32 | } 33 | 34 | public int Process 35 | { 36 | get 37 | { 38 | if (this.loadMapOperation == null) 39 | { 40 | return 0; 41 | } 42 | return (int)(this.loadMapOperation.progress * 100); 43 | } 44 | } 45 | 46 | public void Finish() 47 | { 48 | this.tcs.SetResult(true); 49 | } 50 | 51 | public override void Dispose() 52 | { 53 | if (this.IsDisposed) 54 | { 55 | return; 56 | } 57 | base.Dispose(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Source/Entity/Game.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static class Game 4 | { 5 | private static Scene scene; 6 | 7 | public static Scene Scene 8 | { 9 | get 10 | { 11 | if (scene != null) 12 | { 13 | return scene; 14 | } 15 | scene = new Scene(); 16 | scene.AddComponent(); 17 | return scene; 18 | } 19 | } 20 | 21 | private static EventSystem eventSystem; 22 | 23 | public static EventSystem EventSystem 24 | { 25 | get 26 | { 27 | return eventSystem ?? (eventSystem = new EventSystem()); 28 | } 29 | } 30 | 31 | private static ObjectPool objectPool; 32 | 33 | public static ObjectPool ObjectPool 34 | { 35 | get 36 | { 37 | return objectPool ?? (objectPool = new ObjectPool()); 38 | } 39 | } 40 | 41 | public static void Close() 42 | { 43 | scene.Dispose(); 44 | eventSystem = null; 45 | scene = null; 46 | objectPool = null; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Source/Entity/Scene.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public enum SceneType 4 | { 5 | Share, 6 | Game, 7 | Login, 8 | Lobby, 9 | Map, 10 | Launcher, 11 | Robot, 12 | BehaviorTreeScene, 13 | RobotClient, 14 | 15 | Realm 16 | } 17 | 18 | public sealed class Scene: Entity 19 | { 20 | public string Name { get; set; } 21 | 22 | public Scene() 23 | { 24 | this.InstanceId = IdGenerater.GenerateId(); 25 | } 26 | 27 | public Scene(long id): base(id) 28 | { 29 | this.InstanceId = IdGenerater.GenerateId(); 30 | } 31 | 32 | public override void Dispose() 33 | { 34 | if (this.IsDisposed) 35 | { 36 | return; 37 | } 38 | 39 | base.Dispose(); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Source/Entity/UnityWebRequestAsync.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using UnityEngine; 5 | using UnityEngine.Networking; 6 | 7 | namespace ETModel 8 | { 9 | [ObjectSystem] 10 | public class UnityWebRequestUpdateSystem : UpdateSystem 11 | { 12 | public override void Update(UnityWebRequestAsync self) 13 | { 14 | self.Update(); 15 | } 16 | } 17 | 18 | public class UnityWebRequestAsync : Component 19 | { 20 | public UnityWebRequest Request; 21 | 22 | public bool isCancel; 23 | 24 | public TaskCompletionSource tcs; 25 | 26 | public override void Dispose() 27 | { 28 | if (this.IsDisposed) 29 | { 30 | return; 31 | } 32 | 33 | base.Dispose(); 34 | 35 | this.Request?.Dispose(); 36 | this.Request = null; 37 | this.isCancel = false; 38 | } 39 | 40 | public float Progress 41 | { 42 | get 43 | { 44 | if (this.Request == null) 45 | { 46 | return 0; 47 | } 48 | return this.Request.downloadProgress; 49 | } 50 | } 51 | 52 | public ulong ByteDownloaded 53 | { 54 | get 55 | { 56 | if (this.Request == null) 57 | { 58 | return 0; 59 | } 60 | return this.Request.downloadedBytes; 61 | } 62 | } 63 | 64 | public void Update() 65 | { 66 | if (this.isCancel) 67 | { 68 | this.tcs.SetResult(false); 69 | return; 70 | } 71 | 72 | if (!this.Request.isDone) 73 | { 74 | return; 75 | } 76 | if (!string.IsNullOrEmpty(this.Request.error)) 77 | { 78 | this.tcs.SetException(new Exception($"request error: {this.Request.error}")); 79 | return; 80 | } 81 | 82 | this.tcs.SetResult(true); 83 | } 84 | 85 | public Task DownloadAsync(string url) 86 | { 87 | this.tcs = new TaskCompletionSource(); 88 | 89 | url = url.Replace(" ", "%20"); 90 | this.Request = UnityWebRequest.Get(url); 91 | this.Request.SendWebRequest(); 92 | 93 | return this.tcs.Task; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Source/Helper/ActionHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine.UI; 3 | 4 | namespace ETModel 5 | { 6 | public static class ActionHelper 7 | { 8 | public static void Add(this Button.ButtonClickedEvent buttonClickedEvent, Action action) 9 | { 10 | buttonClickedEvent.AddListener(()=> { action(); }); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Source/Helper/GameObjectHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace ETModel 5 | { 6 | public static class GameObjectHelper 7 | { 8 | public static T Get(this GameObject gameObject, string key) where T : class 9 | { 10 | try 11 | { 12 | return gameObject.GetComponent().Get(key); 13 | } 14 | catch (Exception e) 15 | { 16 | throw new Exception($"获取{gameObject.name}的ReferenceCollector key失败, key: {key}", e); 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Source/Helper/PathHelper.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ETModel 4 | { 5 | public static class PathHelper 6 | { /// 7 | ///应用程序外部资源路径存放路径(热更新资源路径) 8 | /// 9 | public static string AppHotfixResPath 10 | { 11 | get 12 | { 13 | string game = Application.productName; 14 | string path = AppResPath; 15 | if (Application.isMobilePlatform) 16 | { 17 | path = $"{Application.persistentDataPath}/{game}/"; 18 | } 19 | return path; 20 | } 21 | 22 | } 23 | 24 | /// 25 | /// 应用程序内部资源路径存放路径 26 | /// 27 | public static string AppResPath 28 | { 29 | get 30 | { 31 | return Application.streamingAssetsPath; 32 | } 33 | } 34 | 35 | /// 36 | /// 应用程序内部资源路径存放路径(www/webrequest专用) 37 | /// 38 | public static string AppResPath4Web 39 | { 40 | get 41 | { 42 | #if UNITY_IOS 43 | return $"file://{Application.streamingAssetsPath}"; 44 | #else 45 | return Application.streamingAssetsPath; 46 | #endif 47 | 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Source/Helper/ResourcesHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using UnityEngine; 6 | 7 | #if UNITY_EDITOR 8 | using UnityEditor; 9 | #endif 10 | 11 | namespace ETModel 12 | { 13 | public static class ResourcesHelper 14 | { 15 | public static UnityEngine.Object Load(string path) 16 | { 17 | return Resources.Load(path); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/Module/Actor/IActorMessage.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | // 不需要返回消息 4 | public interface IActorMessage: IMessage 5 | { 6 | long ActorId { get; set; } 7 | } 8 | 9 | public interface IActorRequest : IRequest 10 | { 11 | long ActorId { get; set; } 12 | } 13 | 14 | public interface IActorResponse : IResponse 15 | { 16 | } 17 | 18 | public interface IFrameMessage : IMessage 19 | { 20 | long Id { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/Module/ActorLocation/IActorLocationMessage.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public interface IActorLocationMessage : IActorRequest 4 | { 5 | } 6 | 7 | public interface IActorLocationRequest : IActorRequest 8 | { 9 | } 10 | 11 | public interface IActorLocationResponse : IActorResponse 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /Source/Module/Filter/FilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class FilterAttribute: BaseAttribute 7 | { 8 | // 指定管理器的类型名 9 | public string ManagerTypeName { get; } 10 | 11 | public FilterAttribute(string managerTypeName) 12 | { 13 | this.ManagerTypeName = managerTypeName; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Source/Module/Filter/FilterEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public class FilterEntity: Entity 6 | { 7 | public override Component AddComponent(Component component) 8 | { 9 | base.AddComponent(component); 10 | this.Parent.GetParent().OnAddComponent(this, component.GetType()); 11 | return component; 12 | } 13 | 14 | public override K AddComponent() 15 | { 16 | Component component = base.AddComponent(); 17 | this.Parent.GetParent()?.OnAddComponent(this, component.GetType()); 18 | return (K)component; 19 | } 20 | 21 | public override K AddComponent(P1 p1) 22 | { 23 | Component component = base.AddComponent(p1); 24 | this.Parent.GetParent()?.OnAddComponent(this, component.GetType()); 25 | return (K)component; 26 | } 27 | 28 | public override K AddComponent(P1 p1, P2 p2) 29 | { 30 | Component component = base.AddComponent(p1, p2); 31 | this.Parent.GetParent()?.OnAddComponent(this, component.GetType()); 32 | return (K)component; 33 | } 34 | 35 | public override K AddComponent(P1 p1, P2 p2, P3 p3) 36 | { 37 | Component component = base.AddComponent(p1, p2, p3); 38 | this.Parent.GetParent()?.OnAddComponent(this, component.GetType()); 39 | return (K)component; 40 | } 41 | 42 | public override void RemoveComponent(Type type) 43 | { 44 | base.RemoveComponent(type); 45 | this.Parent.GetParent()?.OnRemoveComponent(this, type); 46 | } 47 | 48 | public override void RemoveComponent() 49 | { 50 | base.RemoveComponent(); 51 | this.Parent.GetParent()?.OnRemoveComponent(this, typeof(K)); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Source/Module/Filter/IFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface IFilter 6 | { 7 | Type[] GetFilter(); 8 | } 9 | 10 | public abstract class AFilter: IFilter 11 | { 12 | public Type[] GetFilter() 13 | { 14 | return new[] { typeof (A) }; 15 | } 16 | } 17 | 18 | public abstract class AFilter: IFilter 19 | { 20 | public Type[] GetFilter() 21 | { 22 | return new[] { typeof (A), typeof(B) }; 23 | } 24 | } 25 | 26 | public abstract class AFilter: IFilter 27 | { 28 | public Type[] GetFilter() 29 | { 30 | return new[] { typeof (A), typeof(B), typeof(C) }; 31 | } 32 | } 33 | 34 | public abstract class AFilter: IFilter 35 | { 36 | public Type[] GetFilter() 37 | { 38 | return new[] { typeof (A), typeof(B), typeof(C), typeof(D) }; 39 | } 40 | } 41 | 42 | public abstract class AFilter: IFilter 43 | { 44 | public Type[] GetFilter() 45 | { 46 | return new[] { typeof (A), typeof(B), typeof(C), typeof(D), typeof(E) }; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Source/Module/FrameSync/CameraComponent.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ETModel 4 | { 5 | [ObjectSystem] 6 | public class CameraComponentAwakeSystem : AwakeSystem 7 | { 8 | public override void Awake(CameraComponent self) 9 | { 10 | self.Awake(); 11 | } 12 | } 13 | 14 | [ObjectSystem] 15 | public class CameraComponentLateUpdateSystem : LateUpdateSystem 16 | { 17 | public override void LateUpdate(CameraComponent self) 18 | { 19 | self.LateUpdate(); 20 | } 21 | } 22 | 23 | public class CameraComponent : Component 24 | { 25 | // 战斗摄像机 26 | public Camera mainCamera; 27 | 28 | public Unit Unit; 29 | 30 | public Camera MainCamera 31 | { 32 | get 33 | { 34 | return this.mainCamera; 35 | } 36 | } 37 | 38 | public void Awake() 39 | { 40 | this.mainCamera = Camera.main; 41 | } 42 | 43 | public void LateUpdate() 44 | { 45 | // 摄像机每帧更新位置 46 | UpdatePosition(); 47 | } 48 | 49 | private void UpdatePosition() 50 | { 51 | Vector3 cameraPos = this.mainCamera.transform.position; 52 | this.mainCamera.transform.position = new Vector3(this.Unit.Position.x, cameraPos.y, this.Unit.Position.z - 1); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Source/Module/FrameSync/FrameOpcode.cs: -------------------------------------------------------------------------------- 1 | using ETModel; 2 | namespace ETModel 3 | { 4 | [Message(FrameOpcode.OneFrameMessage)] 5 | public partial class OneFrameMessage : IActorLocationMessage {} 6 | 7 | [Message(FrameOpcode.FrameMessage)] 8 | public partial class FrameMessage : IActorMessage {} 9 | 10 | } 11 | namespace ETModel 12 | { 13 | public static partial class FrameOpcode 14 | { 15 | public const ushort OneFrameMessage = 11; 16 | public const ushort FrameMessage = 12; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Source/Module/FrameSync/Player.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public sealed class Player : Entity 4 | { 5 | public long UnitId { get; set; } 6 | 7 | public override void Dispose() 8 | { 9 | if (this.IsDisposed) 10 | { 11 | return; 12 | } 13 | 14 | base.Dispose(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Source/Module/FrameSync/PlayerComponent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace ETModel 5 | { 6 | [ObjectSystem] 7 | public class PlayerComponentAwakeSystem : AwakeSystem 8 | { 9 | public override void Awake(PlayerComponent self) 10 | { 11 | self.Awake(); 12 | } 13 | } 14 | 15 | public class PlayerComponent : Component 16 | { 17 | public static PlayerComponent Instance { get; private set; } 18 | 19 | public Player MyPlayer; 20 | 21 | private readonly Dictionary idPlayers = new Dictionary(); 22 | 23 | public void Awake() 24 | { 25 | Instance = this; 26 | } 27 | 28 | public void Add(Player player) 29 | { 30 | this.idPlayers.Add(player.Id, player); 31 | } 32 | 33 | public Player Get(long id) 34 | { 35 | Player player; 36 | this.idPlayers.TryGetValue(id, out player); 37 | return player; 38 | } 39 | 40 | public void Remove(long id) 41 | { 42 | this.idPlayers.Remove(id); 43 | } 44 | 45 | public int Count 46 | { 47 | get 48 | { 49 | return this.idPlayers.Count; 50 | } 51 | } 52 | 53 | public Player[] GetAll() 54 | { 55 | return this.idPlayers.Values.ToArray(); 56 | } 57 | 58 | public override void Dispose() 59 | { 60 | if (this.IsDisposed) 61 | { 62 | return; 63 | } 64 | 65 | base.Dispose(); 66 | 67 | foreach (Player player in this.idPlayers.Values) 68 | { 69 | player.Dispose(); 70 | } 71 | 72 | Instance = null; 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /Source/Module/FrameSync/PlayerFactory.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static class PlayerFactory 4 | { 5 | public static Player Create(long id) 6 | { 7 | Player player = ComponentFactory.CreateWithId(id); 8 | PlayerComponent playerComponent = Game.Scene.GetComponent(); 9 | playerComponent.Add(player); 10 | return player; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Source/Module/FrameSync/SessionComponent.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | [ObjectSystem] 4 | public class SessionComponentAwakeSystem : AwakeSystem 5 | { 6 | public override void Awake(SessionComponent self) 7 | { 8 | self.Awake(); 9 | } 10 | } 11 | 12 | public class SessionComponent: Component 13 | { 14 | public static SessionComponent Instance; 15 | 16 | public Session Session; 17 | 18 | public void Awake() 19 | { 20 | Instance = this; 21 | } 22 | 23 | public override void Dispose() 24 | { 25 | if (this.IsDisposed) 26 | { 27 | return; 28 | } 29 | 30 | base.Dispose(); 31 | 32 | this.Session.Dispose(); 33 | this.Session = null; 34 | Instance = null; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Source/Module/FrameSync/Unit.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ETModel 4 | { 5 | public enum UnitType 6 | { 7 | Hero, 8 | Npc 9 | } 10 | 11 | public sealed class Unit: Entity 12 | { 13 | public VInt3 IntPos; 14 | 15 | public GameObject GameObject; 16 | 17 | public void Awake() 18 | { 19 | } 20 | 21 | public Vector3 Position 22 | { 23 | get 24 | { 25 | return GameObject.transform.position; 26 | } 27 | set 28 | { 29 | GameObject.transform.position = value; 30 | } 31 | } 32 | 33 | public Quaternion Rotation 34 | { 35 | get 36 | { 37 | return GameObject.transform.rotation; 38 | } 39 | set 40 | { 41 | GameObject.transform.rotation = value; 42 | } 43 | } 44 | 45 | public override void Dispose() 46 | { 47 | if (this.IsDisposed) 48 | { 49 | return; 50 | } 51 | 52 | base.Dispose(); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Source/Module/FrameSync/UnitComponent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace ETModel 5 | { 6 | [ObjectSystem] 7 | public class UnitComponentSystem : AwakeSystem 8 | { 9 | public override void Awake(UnitComponent self) 10 | { 11 | self.Awake(); 12 | } 13 | } 14 | 15 | public class UnitComponent: Component 16 | { 17 | public static UnitComponent Instance { get; private set; } 18 | 19 | public Unit MyUnit; 20 | 21 | private readonly Dictionary idUnits = new Dictionary(); 22 | 23 | public void Awake() 24 | { 25 | Instance = this; 26 | } 27 | 28 | public override void Dispose() 29 | { 30 | if (this.IsDisposed) 31 | { 32 | return; 33 | } 34 | base.Dispose(); 35 | 36 | foreach (Unit unit in this.idUnits.Values) 37 | { 38 | unit.Dispose(); 39 | } 40 | 41 | this.idUnits.Clear(); 42 | 43 | Instance = null; 44 | } 45 | 46 | public void Add(Unit unit) 47 | { 48 | this.idUnits.Add(unit.Id, unit); 49 | } 50 | 51 | public Unit Get(long id) 52 | { 53 | Unit unit; 54 | this.idUnits.TryGetValue(id, out unit); 55 | return unit; 56 | } 57 | 58 | public void Remove(long id) 59 | { 60 | Unit unit; 61 | this.idUnits.TryGetValue(id, out unit); 62 | this.idUnits.Remove(id); 63 | unit?.Dispose(); 64 | } 65 | 66 | public void RemoveNoDispose(long id) 67 | { 68 | this.idUnits.Remove(id); 69 | } 70 | 71 | public int Count 72 | { 73 | get 74 | { 75 | return this.idUnits.Count; 76 | } 77 | } 78 | 79 | public Unit[] GetAll() 80 | { 81 | return this.idUnits.Values.ToArray(); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /Source/Module/Message/AMHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public abstract class AMHandler : IMHandler where Message: class 6 | { 7 | protected abstract void Run(Session session, Message message); 8 | 9 | public void Handle(Session session, object msg) 10 | { 11 | Message message = msg as Message; 12 | if (message == null) 13 | { 14 | Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}"); 15 | return; 16 | } 17 | if (session.IsDisposed) 18 | { 19 | Log.Error($"session disconnect {msg}"); 20 | return; 21 | } 22 | this.Run(session, message); 23 | } 24 | 25 | public Type GetMessageType() 26 | { 27 | return typeof(Message); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Source/Module/Message/ErrorCode.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static class ErrorCode 4 | { 5 | public const int ERR_Success = 0; 6 | 7 | // 1-11004 是SocketError请看SocketError定义 8 | 9 | // 100000 以上,避免跟SocketError冲突 10 | public const int ERR_MyErrorCode = 100000; 11 | 12 | 13 | // 小于这个Rpc会抛异常 14 | public const int ERR_Exception = 200000; 15 | 16 | public const int ERR_NotFoundActor = 200002; 17 | public const int ERR_ActorNoMailBoxComponent = 200003; 18 | public const int ERR_ActorRemove = 200004; 19 | public const int ERR_PacketParserError = 200005; 20 | 21 | public const int ERR_AccountOrPasswordError = 200102; 22 | public const int ERR_SessionActorError = 200103; 23 | public const int ERR_NotFoundUnit = 200104; 24 | public const int ERR_ConnectGateKeyError = 200105; 25 | 26 | public const int ERR_RpcFail = 202001; 27 | public const int ERR_SocketDisconnected = 202002; 28 | public const int ERR_ReloadFail = 202003; 29 | public const int ERR_ActorLocationNotFound = 202004; 30 | public const int ERR_KcpCantConnect = 202005; 31 | public const int ERR_KcpChannelTimeout = 202006; 32 | public const int ERR_KcpRemoteDisconnect = 202007; 33 | public const int ERR_PeerDisconnect = 202008; 34 | public const int ERR_SocketCantSend = 202009; 35 | public const int ERR_SocketError = 202010; 36 | public const int ERR_KcpWaitSendSizeTooLarge = 202011; 37 | 38 | public const int ERR_WebsocketPeerReset = 203001; 39 | public const int ERR_WebsocketMessageTooBig = 203002; 40 | public const int ERR_WebsocketError = 203003; 41 | public const int ERR_WebsocketConnectError = 203004; 42 | public const int ERR_WebsocketSendError = 203005; 43 | public const int ERR_WebsocketRecvError = 203006; 44 | 45 | public static bool IsRpcNeedThrowException(int error) 46 | { 47 | if (error == 0) 48 | { 49 | return false; 50 | } 51 | 52 | if (error > ERR_Exception) 53 | { 54 | return false; 55 | } 56 | 57 | return true; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Source/Module/Message/HotfixOpcode.cs: -------------------------------------------------------------------------------- 1 | using ETModel; 2 | namespace ETModel 3 | { 4 | [Message(HotfixOpcode.C2R_Login)] 5 | public partial class C2R_Login : IRequest { } 6 | 7 | [Message(HotfixOpcode.R2C_Login)] 8 | public partial class R2C_Login : IResponse { } 9 | 10 | [Message(HotfixOpcode.C2G_LoginGate)] 11 | public partial class C2G_LoginGate : IRequest { } 12 | 13 | [Message(HotfixOpcode.G2C_LoginGate)] 14 | public partial class G2C_LoginGate : IResponse { } 15 | 16 | [Message(HotfixOpcode.G2C_TestHotfixMessage)] 17 | public partial class G2C_TestHotfixMessage : IMessage { } 18 | 19 | [Message(HotfixOpcode.C2M_TestActorRequest)] 20 | public partial class C2M_TestActorRequest : IActorLocationRequest { } 21 | 22 | [Message(HotfixOpcode.M2C_TestActorResponse)] 23 | public partial class M2C_TestActorResponse : IActorLocationResponse { } 24 | 25 | [Message(HotfixOpcode.PlayerInfo)] 26 | public partial class PlayerInfo : IMessage { } 27 | 28 | [Message(HotfixOpcode.C2G_PlayerInfo)] 29 | public partial class C2G_PlayerInfo : IRequest { } 30 | 31 | [Message(HotfixOpcode.G2C_PlayerInfo)] 32 | public partial class G2C_PlayerInfo : IResponse { } 33 | 34 | } 35 | namespace ETModel 36 | { 37 | public static partial class HotfixOpcode 38 | { 39 | public const ushort C2R_Login = 10001; 40 | public const ushort R2C_Login = 10002; 41 | public const ushort C2G_LoginGate = 10003; 42 | public const ushort G2C_LoginGate = 10004; 43 | public const ushort G2C_TestHotfixMessage = 10005; 44 | public const ushort C2M_TestActorRequest = 10006; 45 | public const ushort M2C_TestActorResponse = 10007; 46 | public const ushort PlayerInfo = 10008; 47 | public const ushort C2G_PlayerInfo = 10009; 48 | public const ushort G2C_PlayerInfo = 10010; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/Module/Message/IMHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public interface IMHandler 6 | { 7 | void Handle(Session session, object message); 8 | Type GetMessageType(); 9 | } 10 | } -------------------------------------------------------------------------------- /Source/Module/Message/IMessage.cs: -------------------------------------------------------------------------------- 1 | using Google.Protobuf; 2 | 3 | namespace ETModel 4 | { 5 | public interface IMessage : Google.Protobuf.IMessage 6 | { } 7 | 8 | public interface IRequest : IMessage 9 | { 10 | int RpcId { get; set; } 11 | } 12 | 13 | public interface IResponse : IMessage 14 | { 15 | int Error { get; set; } 16 | string Message { get; set; } 17 | int RpcId { get; set; } 18 | } 19 | 20 | public class ResponseMessage : IResponse 21 | { 22 | public int Error { get; set; } 23 | public string Message { get; set; } 24 | public int RpcId { get; set; } 25 | 26 | public int CalculateSize() 27 | { 28 | return 0; 29 | } 30 | 31 | public void MergeFrom(CodedInputStream input) 32 | { 33 | } 34 | 35 | public void WriteTo(CodedOutputStream output) 36 | { 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Source/Module/Message/IMessageDispatcher.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public interface IMessageDispatcher 4 | { 5 | void Dispatch(Session session, ushort opcode, object message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Source/Module/Message/IMessagePacker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ETModel 5 | { 6 | public interface IMessagePacker 7 | { 8 | byte[] SerializeTo(object obj); 9 | void SerializeTo(object obj, MemoryStream stream); 10 | object DeserializeFrom(Type type, byte[] bytes, int index, int count); 11 | object DeserializeFrom(object instance, byte[] bytes, int index, int count); 12 | object DeserializeFrom(Type type, MemoryStream stream); 13 | object DeserializeFrom(object instance, MemoryStream stream); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/Module/Message/MessageAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public class MessageAttribute: BaseAttribute 6 | { 7 | public ushort Opcode { get; } 8 | 9 | public MessageAttribute(ushort opcode) 10 | { 11 | this.Opcode = opcode; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/Module/Message/MessageHandlerAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public class MessageHandlerAttribute : BaseAttribute 6 | { 7 | public AppType Type { get; } 8 | 9 | public MessageHandlerAttribute() 10 | { 11 | } 12 | 13 | public MessageHandlerAttribute(AppType appType) 14 | { 15 | this.Type = appType; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Source/Module/Message/MessageInfo.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public struct MessageInfo 4 | { 5 | public ushort Opcode { get; } 6 | public object Message { get; } 7 | 8 | public MessageInfo(ushort opcode, object message) 9 | { 10 | this.Opcode = opcode; 11 | this.Message = message; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/Module/Message/MessagePool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ETModel 5 | { 6 | // 客户端为了0GC需要消息池,服务端消息需要跨协程不需要消息池 7 | public class MessagePool 8 | { 9 | public static MessagePool Instance { get; } = new MessagePool(); 10 | 11 | #if !SERVER 12 | private readonly Dictionary> dictionary = new Dictionary>(); 13 | #endif 14 | 15 | public object Fetch(Type type) 16 | { 17 | #if !SERVER 18 | Queue queue; 19 | if (!this.dictionary.TryGetValue(type, out queue)) 20 | { 21 | queue = new Queue(); 22 | this.dictionary.Add(type, queue); 23 | } 24 | 25 | object obj; 26 | if (queue.Count > 0) 27 | { 28 | obj = queue.Dequeue(); 29 | } 30 | else 31 | { 32 | obj = Activator.CreateInstance(type); 33 | } 34 | 35 | return obj; 36 | #else 37 | return Activator.CreateInstance(type); 38 | #endif 39 | } 40 | 41 | public T Fetch() where T : class 42 | { 43 | T t = (T) this.Fetch(typeof (T)); 44 | return t; 45 | } 46 | 47 | public void Recycle(object obj) 48 | { 49 | #if !SERVER 50 | Type type = obj.GetType(); 51 | Queue queue; 52 | if (!this.dictionary.TryGetValue(type, out queue)) 53 | { 54 | queue = new Queue(); 55 | this.dictionary.Add(type, queue); 56 | } 57 | 58 | queue.Enqueue(obj); 59 | #endif 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Source/Module/Message/MessageProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public class MessageProxy: IMHandler 6 | { 7 | private readonly Type type; 8 | private readonly Action action; 9 | 10 | public MessageProxy(Type type, Action action) 11 | { 12 | this.type = type; 13 | this.action = action; 14 | } 15 | 16 | public void Handle(Session session, object message) 17 | { 18 | this.action.Invoke(session, message); 19 | } 20 | 21 | public Type GetMessageType() 22 | { 23 | return this.type; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Source/Module/Message/NetOuterComponent.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public class NetOuterComponent : NetworkComponent 4 | { 5 | public NetworkProtocol Protocol = NetworkProtocol.TCP; 6 | } 7 | } -------------------------------------------------------------------------------- /Source/Module/Message/NetOuterComponentSystem.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net; 3 | using ETModel; 4 | 5 | namespace ETModel 6 | { 7 | [ObjectSystem] 8 | public class NetOuterComponentAwakeSystem : AwakeSystem 9 | { 10 | public override void Awake(NetOuterComponent self) 11 | { 12 | self.Awake(self.Protocol); 13 | self.MessagePacker = new ProtobufPacker(); 14 | self.MessageDispatcher = new OuterMessageDispatcher(); 15 | } 16 | } 17 | 18 | [ObjectSystem] 19 | public class NetOuterComponentAwake1System : AwakeSystem 20 | { 21 | public override void Awake(NetOuterComponent self, string address) 22 | { 23 | self.Awake(self.Protocol, address); 24 | self.MessagePacker = new ProtobufPacker(); 25 | self.MessageDispatcher = new OuterMessageDispatcher(); 26 | } 27 | } 28 | 29 | [ObjectSystem] 30 | public class NetOuterComponentLoadSystem : LoadSystem 31 | { 32 | public override void Load(NetOuterComponent self) 33 | { 34 | self.MessagePacker = new ProtobufPacker(); 35 | self.MessageDispatcher = new OuterMessageDispatcher(); 36 | } 37 | } 38 | 39 | [ObjectSystem] 40 | public class NetOuterComponentUpdateSystem : UpdateSystem 41 | { 42 | public override void Update(NetOuterComponent self) 43 | { 44 | self.Update(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Source/Module/Message/Network/AChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | 5 | namespace ETModel 6 | { 7 | public enum ChannelType 8 | { 9 | Connect, 10 | Accept, 11 | } 12 | 13 | public abstract class AChannel: ComponentWithId 14 | { 15 | public ChannelType ChannelType { get; } 16 | 17 | protected AService service; 18 | 19 | public abstract MemoryStream Stream { get; } 20 | 21 | public int Error { get; set; } 22 | 23 | public IPEndPoint RemoteAddress { get; protected set; } 24 | 25 | private Action errorCallback; 26 | 27 | public event Action ErrorCallback 28 | { 29 | add 30 | { 31 | this.errorCallback += value; 32 | } 33 | remove 34 | { 35 | this.errorCallback -= value; 36 | } 37 | } 38 | 39 | private Action readCallback; 40 | 41 | public event Action ReadCallback 42 | { 43 | add 44 | { 45 | this.readCallback += value; 46 | } 47 | remove 48 | { 49 | this.readCallback -= value; 50 | } 51 | } 52 | 53 | protected void OnRead(MemoryStream memoryStream) 54 | { 55 | this.readCallback.Invoke(memoryStream); 56 | } 57 | 58 | protected void OnError(int e) 59 | { 60 | this.Error = e; 61 | this.errorCallback?.Invoke(this, e); 62 | } 63 | 64 | protected AChannel(AService service, ChannelType channelType) 65 | { 66 | this.Id = IdGenerater.GenerateId(); 67 | this.ChannelType = channelType; 68 | this.service = service; 69 | } 70 | 71 | public abstract void Start(); 72 | 73 | public abstract void Send(MemoryStream stream); 74 | 75 | public override void Dispose() 76 | { 77 | if (this.IsDisposed) 78 | { 79 | return; 80 | } 81 | 82 | base.Dispose(); 83 | 84 | this.service.Remove(this.Id); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /Source/Module/Message/Network/AService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace ETModel 5 | { 6 | public enum NetworkProtocol 7 | { 8 | KCP, 9 | TCP, 10 | WebSocket, 11 | } 12 | 13 | public abstract class AService: Component 14 | { 15 | public abstract AChannel GetChannel(long id); 16 | 17 | private Action acceptCallback; 18 | 19 | public event Action AcceptCallback 20 | { 21 | add 22 | { 23 | this.acceptCallback += value; 24 | } 25 | remove 26 | { 27 | this.acceptCallback -= value; 28 | } 29 | } 30 | 31 | protected void OnAccept(AChannel channel) 32 | { 33 | this.acceptCallback.Invoke(channel); 34 | } 35 | 36 | public abstract AChannel ConnectChannel(IPEndPoint ipEndPoint); 37 | 38 | public abstract AChannel ConnectChannel(string address); 39 | 40 | public abstract void Remove(long channelId); 41 | 42 | public abstract void Update(); 43 | } 44 | } -------------------------------------------------------------------------------- /Source/Module/Message/Network/NetworkHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace ETModel 4 | { 5 | public static class NetworkHelper 6 | { 7 | public static IPEndPoint ToIPEndPoint(string host, int port) 8 | { 9 | return new IPEndPoint(IPAddress.Parse(host), port); 10 | } 11 | 12 | public static IPEndPoint ToIPEndPoint(string address) 13 | { 14 | int index = address.LastIndexOf(':'); 15 | string host = address.Substring(0, index); 16 | string p = address.Substring(index + 1); 17 | int port = int.Parse(p); 18 | return ToIPEndPoint(host, port); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/Module/Message/Opcode.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static partial class Opcode 4 | { 5 | public const ushort ActorResponse = 1; 6 | public const ushort FrameMessage = 2; 7 | public const ushort OneFrameMessage = 3; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Source/Module/Message/OpcodeHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ETModel 4 | { 5 | public static class OpcodeHelper 6 | { 7 | private static readonly HashSet needDebugLogMessageSet = new HashSet { 1 }; 8 | 9 | public static bool IsNeedDebugLogMessage(ushort opcode) 10 | { 11 | //return true; 12 | if (opcode > 1000) 13 | { 14 | return true; 15 | } 16 | 17 | if (needDebugLogMessageSet.Contains(opcode)) 18 | { 19 | return true; 20 | } 21 | 22 | return false; 23 | } 24 | 25 | public static bool IsClientHotfixMessage(ushort opcode) 26 | { 27 | return opcode > 10000; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Source/Module/Message/OuterMessageDispatcher.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public class OuterMessageDispatcher: IMessageDispatcher 4 | { 5 | public void Dispatch(Session session, ushort opcode, object message) 6 | { 7 | // 如果是帧同步消息,交给ClientFrameComponent处理 8 | FrameMessage frameMessage = message as FrameMessage; 9 | if (frameMessage != null) 10 | { 11 | Game.Scene.GetComponent().Add(session, frameMessage); 12 | return; 13 | } 14 | 15 | // 普通消息或者是Rpc请求消息 16 | MessageInfo messageInfo = new MessageInfo(opcode, message); 17 | Game.Scene.GetComponent().Handle(session, messageInfo); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/Module/Message/ProtobufPacker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ETModel 5 | { 6 | public class ProtobufPacker : IMessagePacker 7 | { 8 | public byte[] SerializeTo(object obj) 9 | { 10 | return ProtobufHelper.ToBytes(obj); 11 | } 12 | 13 | public void SerializeTo(object obj, MemoryStream stream) 14 | { 15 | ProtobufHelper.ToStream(obj, stream); 16 | } 17 | 18 | public object DeserializeFrom(Type type, byte[] bytes, int index, int count) 19 | { 20 | return ProtobufHelper.FromBytes(type, bytes, index, count); 21 | } 22 | 23 | public object DeserializeFrom(object instance, byte[] bytes, int index, int count) 24 | { 25 | return ProtobufHelper.FromBytes(instance, bytes, index, count); 26 | } 27 | 28 | public object DeserializeFrom(Type type, MemoryStream stream) 29 | { 30 | return ProtobufHelper.FromStream(type, stream); 31 | } 32 | 33 | public object DeserializeFrom(object instance, MemoryStream stream) 34 | { 35 | return ProtobufHelper.FromStream(instance, stream); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Source/Module/Message/RpcException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | /// 6 | /// RPC异常,带ErrorCode 7 | /// 8 | [Serializable] 9 | public class RpcException: Exception 10 | { 11 | public int Error { get; private set; } 12 | 13 | public RpcException(int error, string message): base($"Error: {error} Message: {message}") 14 | { 15 | this.Error = error; 16 | } 17 | 18 | public RpcException(int error, string message, Exception e): base($"Error: {error} Message: {message}", e) 19 | { 20 | this.Error = error; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Module/Message/SessionCallbackComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ETModel 5 | { 6 | public class SessionCallbackComponent: Component 7 | { 8 | public Action MessageCallback; 9 | public Action DisposeCallback; 10 | 11 | public override void Dispose() 12 | { 13 | if (this.IsDisposed) 14 | { 15 | return; 16 | } 17 | base.Dispose(); 18 | 19 | this.DisposeCallback?.Invoke(this.GetParent()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Module/Numeric/INumericWatcher.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public interface INumericWatcher 4 | { 5 | void Run(long id, int value); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Source/Module/Numeric/NumericChangeEvent_NotifyWatcher.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | // 分发数值监听 4 | [Event(EventIdType.NumbericChange)] 5 | public class NumericChangeEvent_NotifyWatcher: AEvent 6 | { 7 | public override void Run(NumericType numericType, long id, int value) 8 | { 9 | Game.Scene.GetComponent().Run(numericType, id, value); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/Module/Numeric/NumericType.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public enum NumericType 4 | { 5 | Max = 10000, 6 | 7 | Speed = 1000, 8 | SpeedBase = Speed * 10 + 1, 9 | SpeedAdd = Speed * 10 + 2, 10 | SpeedPct = Speed * 10 + 3, 11 | SpeedFinalAdd = Speed * 10 + 4, 12 | SpeedFinalPct = Speed * 10 + 5, 13 | 14 | Hp = 1001, 15 | HpBase = Hp * 10 + 1, 16 | 17 | MaxHp = 1002, 18 | MaxHpBase = MaxHp * 10 + 1, 19 | MaxHpAdd = MaxHp * 10 + 2, 20 | MaxHpPct = MaxHp * 10 + 3, 21 | MaxHpFinalAdd = MaxHp * 10 + 4, 22 | MaxHpFinalPct = MaxHp * 10 + 5, 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/Module/Numeric/NumericWatcherAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | public class NumericWatcherAttribute : BaseAttribute 6 | { 7 | public NumericType NumericType { get; } 8 | 9 | public NumericWatcherAttribute(NumericType type) 10 | { 11 | this.NumericType = type; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/Module/Numeric/NumericWatcherComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ETModel 5 | { 6 | [ObjectSystem] 7 | public class NumericWatcherComponentAwakeSystem : AwakeSystem 8 | { 9 | public override void Awake(NumericWatcherComponent self) 10 | { 11 | self.Awake(); 12 | } 13 | } 14 | 15 | [ObjectSystem] 16 | public class NumericWatcherComponentLoadSystem : LoadSystem 17 | { 18 | public override void Load(NumericWatcherComponent self) 19 | { 20 | self.Load(); 21 | } 22 | } 23 | 24 | /// 25 | /// 监视数值变化组件,分发监听 26 | /// 27 | public class NumericWatcherComponent : Component 28 | { 29 | private Dictionary> allWatchers; 30 | 31 | public void Awake() 32 | { 33 | this.Load(); 34 | } 35 | 36 | public void Load() 37 | { 38 | this.allWatchers = new Dictionary>(); 39 | 40 | List types = Game.EventSystem.GetTypes(typeof(NumericWatcherAttribute)); 41 | foreach (Type type in types) 42 | { 43 | object[] attrs = type.GetCustomAttributes(typeof(NumericWatcherAttribute), false); 44 | 45 | foreach (object attr in attrs) 46 | { 47 | NumericWatcherAttribute numericWatcherAttribute = (NumericWatcherAttribute)attr; 48 | INumericWatcher obj = (INumericWatcher)Activator.CreateInstance(type); 49 | if (!this.allWatchers.ContainsKey(numericWatcherAttribute.NumericType)) 50 | { 51 | this.allWatchers.Add(numericWatcherAttribute.NumericType, new List()); 52 | } 53 | this.allWatchers[numericWatcherAttribute.NumericType].Add(obj); 54 | } 55 | } 56 | } 57 | 58 | public void Run(NumericType numericType, long id, int value) 59 | { 60 | List list; 61 | if (!this.allWatchers.TryGetValue(numericType, out list)) 62 | { 63 | return; 64 | } 65 | foreach (INumericWatcher numericWatcher in list) 66 | { 67 | numericWatcher.Run(id, value); 68 | } 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /Source/Module/Numeric/NumericWatcher_Hp_ShowUI.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | /// 4 | /// 监视hp数值变化,改变血条值 5 | /// 6 | [NumericWatcher(NumericType.Hp)] 7 | public class NumericWatcher_Hp_ShowUI : INumericWatcher 8 | { 9 | public void Run(long id, int value) 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Source/Module/UI/CanvasConfig.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ETModel 4 | { 5 | public class CanvasConfig: MonoBehaviour 6 | { 7 | public string CanvasName; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Source/Module/UI/IUIFactory.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ETModel 4 | { 5 | public interface IUIFactory 6 | { 7 | UI Create(Scene scene, string type, GameObject parent); 8 | void Remove(string type); 9 | } 10 | } -------------------------------------------------------------------------------- /Source/Module/UI/LayerNames.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ETModel 4 | { 5 | public static class LayerNames 6 | { 7 | /// 8 | /// UI层 9 | /// 10 | public const string UI = "UI"; 11 | 12 | /// 13 | /// 游戏单位层 14 | /// 15 | public const string UNIT = "Unit"; 16 | 17 | /// 18 | /// 地形层 19 | /// 20 | public const string MAP = "Map"; 21 | 22 | /// 23 | /// 默认层 24 | /// 25 | public const string DEFAULT = "Default"; 26 | 27 | /// 28 | /// 通过Layers名字得到对应层 29 | /// 30 | /// 31 | /// 32 | public static int GetLayerInt(string name) 33 | { 34 | return LayerMask.NameToLayer(name); 35 | } 36 | 37 | public static string GetLayerStr(int name) 38 | { 39 | return LayerMask.LayerToName(name); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Source/Module/UI/UI.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace ETModel 5 | { 6 | [ObjectSystem] 7 | public class UiAwakeSystem : AwakeSystem 8 | { 9 | public override void Awake(UI self, GameObject gameObject) 10 | { 11 | self.Awake(gameObject); 12 | } 13 | } 14 | 15 | public sealed class UI: Entity 16 | { 17 | public string Name 18 | { 19 | get 20 | { 21 | return this.GameObject.name; 22 | } 23 | } 24 | 25 | public GameObject GameObject { get; private set; } 26 | 27 | public Dictionary children = new Dictionary(); 28 | 29 | public void Awake(GameObject gameObject) 30 | { 31 | this.children.Clear(); 32 | this.GameObject = gameObject; 33 | } 34 | 35 | public override void Dispose() 36 | { 37 | if (this.IsDisposed) 38 | { 39 | return; 40 | } 41 | 42 | base.Dispose(); 43 | 44 | foreach (UI ui in this.children.Values) 45 | { 46 | ui.Dispose(); 47 | } 48 | 49 | UnityEngine.Object.Destroy(GameObject); 50 | children.Clear(); 51 | this.Parent = null; 52 | } 53 | 54 | public void SetAsFirstSibling() 55 | { 56 | this.GameObject.transform.SetAsFirstSibling(); 57 | } 58 | 59 | public void Add(UI ui) 60 | { 61 | this.children.Add(ui.Name, ui); 62 | ui.Parent = this; 63 | } 64 | 65 | public void Remove(string name) 66 | { 67 | UI ui; 68 | if (!this.children.TryGetValue(name, out ui)) 69 | { 70 | return; 71 | } 72 | this.children.Remove(name); 73 | ui.Dispose(); 74 | } 75 | 76 | public UI Get(string name) 77 | { 78 | UI child; 79 | if (this.children.TryGetValue(name, out child)) 80 | { 81 | return child; 82 | } 83 | GameObject childGameObject = this.GameObject.transform.Find(name)?.gameObject; 84 | if (childGameObject == null) 85 | { 86 | return null; 87 | } 88 | child = ComponentFactory.Create(childGameObject); 89 | this.Add(child); 90 | return child; 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /Source/Module/UI/UIFactoryAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ETModel 4 | { 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class UIFactoryAttribute: BaseAttribute 7 | { 8 | public string Type { get; } 9 | 10 | public UIFactoryAttribute(string type) 11 | { 12 | this.Type = type; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Source/Module/UI/UIType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ETModel 5 | { 6 | public static class UIType 7 | { 8 | public const string Root = "Root"; 9 | public const string UILoading = "UILoading"; 10 | } 11 | } -------------------------------------------------------------------------------- /Source/Other/AppType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ETModel 5 | { 6 | [Flags] 7 | public enum AppType 8 | { 9 | None = 0, 10 | Manager = 1, 11 | Realm = 1 << 1, 12 | Gate = 1 << 2, 13 | Http = 1 << 3, 14 | DB = 1 << 4, 15 | Location = 1 << 5, 16 | Map = 1 << 6, 17 | 18 | BenchmarkWebsocketServer = 1 << 26, 19 | BenchmarkWebsocketClient = 1 << 27, 20 | Robot = 1 << 28, 21 | Benchmark = 1 << 29, 22 | // 客户端Hotfix层 23 | ClientH = 1 << 30, 24 | // 客户端Model层 25 | ClientM = 1 << 31, 26 | 27 | // 7 28 | AllServer = Manager | Realm | Gate | Http | DB | Location | Map | BenchmarkWebsocketServer 29 | } 30 | 31 | public static class AppTypeHelper 32 | { 33 | public static List GetServerTypes() 34 | { 35 | List appTypes = new List { AppType.Manager, AppType.Realm, AppType.Gate }; 36 | return appTypes; 37 | } 38 | 39 | public static bool Is(this AppType a, AppType b) 40 | { 41 | if ((a & b) != 0) 42 | { 43 | return true; 44 | } 45 | return false; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Source/Other/Define.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public static class Define 4 | { 5 | #if UNITY_EDITOR && !ASYNC 6 | public static bool IsAsync = false; 7 | #else 8 | public static bool IsAsync = true; 9 | #endif 10 | 11 | #if UNITY_EDITOR 12 | public static bool IsEditorMode = true; 13 | #else 14 | public static bool IsEditorMode = false; 15 | #endif 16 | 17 | #if DEVELOPMENT_BUILD 18 | public static bool IsDevelopmentBuild = true; 19 | #else 20 | public static bool IsDevelopmentBuild = false; 21 | #endif 22 | 23 | #if ILRuntime 24 | public static bool IsILRuntime = true; 25 | #else 26 | public static bool IsILRuntime = false; 27 | #endif 28 | } 29 | } -------------------------------------------------------------------------------- /Source/Other/IInstanceMethod.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public abstract class IInstanceMethod 4 | { 5 | public abstract void Run(); 6 | public abstract void Run(object a); 7 | public abstract void Run(object a, object b); 8 | public abstract void Run(object a, object b, object c); 9 | } 10 | 11 | public abstract class IStaticMethod 12 | { 13 | public abstract void Run(); 14 | public abstract void Run(object a); 15 | public abstract void Run(object a, object b); 16 | public abstract void Run(object a, object b, object c); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Source/Other/MotionType.cs: -------------------------------------------------------------------------------- 1 | namespace ETModel 2 | { 3 | public enum MotionType 4 | { 5 | None, 6 | Idle, 7 | Run, 8 | } 9 | } -------------------------------------------------------------------------------- /Source/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ETClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ETClient")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("c72384e6-e8c6-4a4b-a002-7b3364046f85")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/ThirdParty/Lib/UnityEngine.AnimationModule.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Source/ThirdParty/Lib/UnityEngine.AnimationModule.dll -------------------------------------------------------------------------------- /Source/ThirdParty/Lib/UnityEngine.CoreModule.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Source/ThirdParty/Lib/UnityEngine.CoreModule.dll -------------------------------------------------------------------------------- /Source/ThirdParty/Lib/UnityEngine.UI.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Source/ThirdParty/Lib/UnityEngine.UI.dll -------------------------------------------------------------------------------- /Source/ThirdParty/Lib/UnityEngine.UnityWebRequestModule.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Source/ThirdParty/Lib/UnityEngine.UnityWebRequestModule.dll -------------------------------------------------------------------------------- /Source/ThirdParty/Lib/UnityEngine.UnityWebRequestWWWModule.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Source/ThirdParty/Lib/UnityEngine.UnityWebRequestWWWModule.dll -------------------------------------------------------------------------------- /Source/ThirdParty/Lib/UnityEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Source/ThirdParty/Lib/UnityEngine.dll -------------------------------------------------------------------------------- /Source/ThirdParty/Lib/UnityEngine.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UnityEngine 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Source/ThirdParty/LitJson/IJsonWrapper.cs: -------------------------------------------------------------------------------- 1 | #region Header 2 | /** 3 | * IJsonWrapper.cs 4 | * Interface that represents a type capable of handling all kinds of JSON 5 | * data. This is mainly used when mapping objects through JsonMapper, and 6 | * it's implemented by JsonData. 7 | * 8 | * The authors disclaim copyright to this source code. For more details, see 9 | * the COPYING file included with this distribution. 10 | **/ 11 | #endregion 12 | 13 | 14 | using System.Collections; 15 | using System.Collections.Specialized; 16 | 17 | 18 | namespace ETModel.Json 19 | { 20 | public enum JsonType 21 | { 22 | None, 23 | 24 | Object, 25 | Array, 26 | String, 27 | Int, 28 | Long, 29 | Double, 30 | Boolean 31 | } 32 | 33 | public interface IJsonWrapper : IList, IOrderedDictionary 34 | { 35 | bool IsArray { get; } 36 | bool IsBoolean { get; } 37 | bool IsDouble { get; } 38 | bool IsInt { get; } 39 | bool IsLong { get; } 40 | bool IsObject { get; } 41 | bool IsString { get; } 42 | 43 | bool GetBoolean (); 44 | double GetDouble (); 45 | int GetInt (); 46 | JsonType GetJsonType (); 47 | long GetLong (); 48 | string GetString (); 49 | 50 | void SetBoolean (bool val); 51 | void SetDouble (double val); 52 | void SetInt (int val); 53 | void SetJsonType (JsonType type); 54 | void SetLong (long val); 55 | void SetString (string val); 56 | 57 | string ToJson (); 58 | void ToJson (JsonWriter writer); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Source/ThirdParty/LitJson/JsonException.cs: -------------------------------------------------------------------------------- 1 | #region Header 2 | /** 3 | * JsonException.cs 4 | * Base class throwed by LitJSON when a parsing error occurs. 5 | * 6 | * The authors disclaim copyright to this source code. For more details, see 7 | * the COPYING file included with this distribution. 8 | **/ 9 | #endregion 10 | 11 | 12 | using System; 13 | 14 | 15 | namespace ETModel.Json 16 | { 17 | public class JsonException : ApplicationException 18 | { 19 | public JsonException () : base () 20 | { 21 | } 22 | 23 | internal JsonException (ParserToken token) : 24 | base (String.Format ( 25 | "Invalid token '{0}' in input string", token)) 26 | { 27 | } 28 | 29 | internal JsonException (ParserToken token, 30 | Exception inner_exception) : 31 | base (String.Format ( 32 | "Invalid token '{0}' in input string", token), 33 | inner_exception) 34 | { 35 | } 36 | 37 | internal JsonException (int c) : 38 | base (String.Format ( 39 | "Invalid character '{0}' in input string", (char) c)) 40 | { 41 | } 42 | 43 | internal JsonException (int c, Exception inner_exception) : 44 | base (String.Format ( 45 | "Invalid character '{0}' in input string", (char) c), 46 | inner_exception) 47 | { 48 | } 49 | 50 | 51 | public JsonException (string message) : base (message) 52 | { 53 | } 54 | 55 | public JsonException (string message, Exception inner_exception) : 56 | base (message, inner_exception) 57 | { 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Source/ThirdParty/LitJson/JsonWriter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecodeCN/ETClient/8cd326d306baa424260dfd25614005fd18ebc80f/Source/ThirdParty/LitJson/JsonWriter.cs -------------------------------------------------------------------------------- /Source/ThirdParty/LitJson/ParserToken.cs: -------------------------------------------------------------------------------- 1 | #region Header 2 | /** 3 | * ParserToken.cs 4 | * Internal representation of the tokens used by the lexer and the parser. 5 | * 6 | * The authors disclaim copyright to this source code. For more details, see 7 | * the COPYING file included with this distribution. 8 | **/ 9 | #endregion 10 | 11 | 12 | namespace ETModel.Json 13 | { 14 | internal enum ParserToken 15 | { 16 | // Lexer tokens (see section A.1.1. of the manual) 17 | None = System.Char.MaxValue + 1, 18 | Number, 19 | True, 20 | False, 21 | Null, 22 | CharSeq, 23 | // Single char 24 | Char, 25 | 26 | // Parser Rules (see section A.2.1 of the manual) 27 | Text, 28 | Object, 29 | ObjectPrime, 30 | Pair, 31 | PairRest, 32 | Array, 33 | ArrayPrime, 34 | Value, 35 | ValueRest, 36 | String, 37 | 38 | // End of input 39 | End, 40 | 41 | // The empty rule 42 | Epsilon 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/BsonBinaryReaderBookmark.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | /// 19 | /// Represents a bookmark that can be used to return a reader to the current position and state. 20 | /// 21 | public class BsonBinaryReaderBookmark : BsonReaderBookmark 22 | { 23 | // private fields 24 | private BsonBinaryReaderContext _context; 25 | private long _position; 26 | 27 | // constructors 28 | internal BsonBinaryReaderBookmark( 29 | BsonReaderState state, 30 | BsonType currentBsonType, 31 | string currentName, 32 | BsonBinaryReaderContext context, 33 | long position) 34 | : base(state, currentBsonType, currentName) 35 | { 36 | _context = context.Clone(); 37 | _position = position; 38 | } 39 | 40 | // internal properties 41 | internal long Position 42 | { 43 | get { return _position; } 44 | } 45 | 46 | // internal methods 47 | internal BsonBinaryReaderContext CloneContext() 48 | { 49 | return _context.Clone(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/BsonBinaryWriterContext.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | internal class BsonBinaryWriterContext 19 | { 20 | // private fields 21 | private BsonBinaryWriterContext _parentContext; 22 | private ContextType _contextType; 23 | private long _startPosition; 24 | private int _index; // used when contextType is Array 25 | 26 | // constructors 27 | internal BsonBinaryWriterContext( 28 | BsonBinaryWriterContext parentContext, 29 | ContextType contextType, 30 | long startPosition) 31 | { 32 | _parentContext = parentContext; 33 | _contextType = contextType; 34 | _startPosition = startPosition; 35 | } 36 | 37 | // internal properties 38 | internal BsonBinaryWriterContext ParentContext 39 | { 40 | get { return _parentContext; } 41 | } 42 | 43 | internal ContextType ContextType 44 | { 45 | get { return _contextType; } 46 | } 47 | 48 | internal long StartPosition 49 | { 50 | get { return _startPosition; } 51 | } 52 | 53 | internal int Index 54 | { 55 | get { return _index; } 56 | set { _index = value; } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/BsonDocumentReaderBookmark.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | /// 19 | /// Represents a bookmark that can be used to return a reader to the current position and state. 20 | /// 21 | public class BsonDocumentReaderBookmark : BsonReaderBookmark 22 | { 23 | // private fields 24 | private BsonDocumentReaderContext _context; 25 | private BsonValue _currentValue; 26 | 27 | // constructors 28 | internal BsonDocumentReaderBookmark( 29 | BsonReaderState state, 30 | BsonType currentBsonType, 31 | string currentName, 32 | BsonDocumentReaderContext context, 33 | BsonValue currentValue) 34 | : base(state, currentBsonType, currentName) 35 | { 36 | _context = context.Clone(); 37 | _currentValue = currentValue; 38 | } 39 | 40 | // internal properties 41 | internal BsonValue CurrentValue 42 | { 43 | get { return _currentValue; } 44 | } 45 | 46 | // internal methods 47 | internal BsonDocumentReaderContext CloneContext() 48 | { 49 | return _context.Clone(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/BsonReaderState.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | /// 19 | /// Represents the state of a reader. 20 | /// 21 | public enum BsonReaderState 22 | { 23 | /// 24 | /// The initial state. 25 | /// 26 | Initial, 27 | /// 28 | /// The reader is positioned at the type of an element or value. 29 | /// 30 | Type, 31 | /// 32 | /// The reader is positioned at the name of an element. 33 | /// 34 | Name, 35 | /// 36 | /// The reader is positioned at a value. 37 | /// 38 | Value, 39 | /// 40 | /// The reader is positioned at a scope document. 41 | /// 42 | ScopeDocument, 43 | /// 44 | /// The reader is positioned at the end of a document. 45 | /// 46 | EndOfDocument, 47 | /// 48 | /// The reader is positioned at the end of an array. 49 | /// 50 | EndOfArray, 51 | /// 52 | /// The reader has finished reading a document. 53 | /// 54 | Done, 55 | /// 56 | /// The reader is closed. 57 | /// 58 | Closed 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/BsonWriterState.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | /// 19 | /// Represents the state of a BsonWriter. 20 | /// 21 | public enum BsonWriterState 22 | { 23 | /// 24 | /// The initial state. 25 | /// 26 | Initial, 27 | /// 28 | /// The writer is positioned to write a name. 29 | /// 30 | Name, 31 | /// 32 | /// The writer is positioned to write a value. 33 | /// 34 | Value, 35 | /// 36 | /// The writer is positioned to write a scope document (call WriteStartDocument to start writing the scope document). 37 | /// 38 | ScopeDocument, 39 | /// 40 | /// The writer is done. 41 | /// 42 | Done, 43 | /// 44 | /// The writer is closed. 45 | /// 46 | Closed 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/ContextType.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | /// 19 | /// Used by BsonReaders and BsonWriters to represent the current context. 20 | /// 21 | public enum ContextType 22 | { 23 | /// 24 | /// The top level of a BSON document. 25 | /// 26 | TopLevel, 27 | /// 28 | /// A (possibly embedded) BSON document. 29 | /// 30 | Document, 31 | /// 32 | /// A BSON array. 33 | /// 34 | Array, 35 | /// 36 | /// A JavaScriptWithScope BSON value. 37 | /// 38 | JavaScriptWithScope, 39 | /// 40 | /// The scope document of a JavaScriptWithScope BSON value. 41 | /// 42 | ScopeDocument 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/IBsonChunk.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2015 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.IO 19 | { 20 | /// 21 | /// Represents a chunk of bytes. 22 | /// 23 | public interface IBsonChunk : IDisposable 24 | { 25 | /// 26 | /// Gets the bytes. 27 | /// 28 | /// 29 | /// The bytes. 30 | /// 31 | ArraySegment Bytes { get; } 32 | 33 | /// 34 | /// Returns a new reference to the same chunk that can be independently disposed. 35 | /// 36 | /// A new reference to the same chunk. 37 | IBsonChunk Fork(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/IBsonChunkSource.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2015 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.IO 19 | { 20 | /// 21 | /// Represents a source of chunks. 22 | /// 23 | public interface IBsonChunkSource : IDisposable 24 | { 25 | /// 26 | /// Gets the chunk. 27 | /// 28 | /// The chunk source is free to return a larger or smaller chunk than requested. 29 | /// Size of the requested. 30 | /// A chunk. 31 | IBsonChunk GetChunk(int requestedSize); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/IElementNameValidator.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | /// 19 | /// Represents an element name validator. Used by BsonWriters when WriteName is called 20 | /// to determine if the element name is valid. 21 | /// 22 | public interface IElementNameValidator 23 | { 24 | /// 25 | /// Gets the validator to use for child content (a nested document or array). 26 | /// 27 | /// The name of the element. 28 | /// The validator to use for child content. 29 | IElementNameValidator GetValidatorForChildContent(string elementName); 30 | 31 | /// 32 | /// Determines whether the element name is valid. 33 | /// 34 | /// The name of the element. 35 | /// True if the element name is valid. 36 | bool IsValidElementName(string elementName); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/INameDecoder.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2015 MongoDB Inc. 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 | 16 | using System; 17 | using System.IO; 18 | using System.Text; 19 | 20 | namespace MongoDB.Bson.IO 21 | { 22 | /// 23 | /// Represents a name decoder. 24 | /// 25 | public interface INameDecoder 26 | { 27 | /// 28 | /// Decodes the name. 29 | /// 30 | /// The stream. 31 | /// The encoding. 32 | /// 33 | /// The name. 34 | /// 35 | string Decode(BsonStream stream, UTF8Encoding encoding); 36 | 37 | /// 38 | /// Informs the decoder of an already decoded name (so the decoder can change state if necessary). 39 | /// 40 | /// The name. 41 | void Inform(string name); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/JsonOutputMode.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.IO 19 | { 20 | /// 21 | /// Represents the output mode of a JsonWriter. 22 | /// 23 | public enum JsonOutputMode 24 | { 25 | /// 26 | /// Output strict JSON. 27 | /// 28 | Strict, 29 | 30 | /// 31 | /// Use a format that can be pasted in to the MongoDB shell. 32 | /// 33 | Shell, 34 | 35 | /// 36 | /// Use JavaScript data types for some values. 37 | /// 38 | [Obsolete("Use Shell instead.")] 39 | JavaScript = Shell, 40 | 41 | /// 42 | /// Use JavaScript and MongoDB data types for some values. 43 | /// 44 | [Obsolete("Use Shell instead.")] 45 | TenGen = Shell 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/JsonReaderContext.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | internal class JsonReaderContext 19 | { 20 | // private fields 21 | private JsonReaderContext _parentContext; 22 | private ContextType _contextType; 23 | 24 | // constructors 25 | // used by Clone 26 | private JsonReaderContext() 27 | { 28 | } 29 | 30 | internal JsonReaderContext(JsonReaderContext parentContext, ContextType contextType) 31 | { 32 | _parentContext = parentContext; 33 | _contextType = contextType; 34 | } 35 | 36 | // internal properties 37 | internal ContextType ContextType 38 | { 39 | get { return _contextType; } 40 | } 41 | 42 | // public methods 43 | /// 44 | /// Creates a clone of the context. 45 | /// 46 | /// A clone of the context. 47 | public JsonReaderContext Clone() 48 | { 49 | return new JsonReaderContext(_parentContext, _contextType); 50 | } 51 | 52 | public JsonReaderContext PopContext() 53 | { 54 | return _parentContext; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/JsonWriterContext.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.IO 17 | { 18 | internal class JsonWriterContext 19 | { 20 | // private fields 21 | private JsonWriterContext _parentContext; 22 | private ContextType _contextType; 23 | private string _indentation; 24 | private bool _hasElements = false; 25 | 26 | // constructors 27 | internal JsonWriterContext(JsonWriterContext parentContext, ContextType contextType, string indentChars) 28 | { 29 | _parentContext = parentContext; 30 | _contextType = contextType; 31 | _indentation = (parentContext == null) ? indentChars : parentContext.Indentation + indentChars; 32 | } 33 | 34 | // internal properties 35 | internal JsonWriterContext ParentContext 36 | { 37 | get { return _parentContext; } 38 | } 39 | 40 | internal ContextType ContextType 41 | { 42 | get { return _contextType; } 43 | } 44 | 45 | internal string Indentation 46 | { 47 | get { return _indentation; } 48 | } 49 | 50 | internal bool HasElements 51 | { 52 | get { return _hasElements; } 53 | set { _hasElements = value; } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/IO/Utf8Encodings.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System.Text; 17 | 18 | namespace MongoDB.Bson.IO 19 | { 20 | /// 21 | /// Represents a singleton instance of a strict UTF8Encoding. 22 | /// 23 | public static class Utf8Encodings 24 | { 25 | // private static fields 26 | private static readonly UTF8Encoding __lenient = new UTF8Encoding(false, false); 27 | private static readonly UTF8Encoding __strict = new UTF8Encoding(false, true); 28 | 29 | // public static properties 30 | /// 31 | /// Gets the lenient instance. 32 | /// 33 | public static UTF8Encoding Lenient 34 | { 35 | get { return __lenient; } 36 | } 37 | 38 | /// 39 | /// Gets the strict instance. 40 | /// 41 | public static UTF8Encoding Strict 42 | { 43 | get { return __strict; } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/ObjectModel/BsonBinarySubType.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2016 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson 19 | { 20 | /// 21 | /// Represents the binary data subtype of a BsonBinaryData. 22 | /// 23 | #if NET45 24 | [Serializable] 25 | #endif 26 | public enum BsonBinarySubType 27 | { 28 | /// 29 | /// Binary data. 30 | /// 31 | Binary = 0x00, 32 | /// 33 | /// A function. 34 | /// 35 | Function = 0x01, 36 | /// 37 | /// Obsolete binary data subtype (use Binary instead). 38 | /// 39 | [Obsolete("Use Binary instead")] 40 | OldBinary = 0x02, 41 | /// 42 | /// A UUID in a driver dependent legacy byte order. 43 | /// 44 | UuidLegacy = 0x03, 45 | /// 46 | /// A UUID in standard network byte order. 47 | /// 48 | UuidStandard = 0x04, 49 | /// 50 | /// An MD5 hash. 51 | /// 52 | MD5 = 0x05, 53 | /// 54 | /// User defined binary data. 55 | /// 56 | UserDefined = 0x80 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/ObjectModel/BsonSymbolTable.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using System.Collections.Generic; 18 | 19 | namespace MongoDB.Bson 20 | { 21 | /// 22 | /// Represents the symbol table of BsonSymbols. 23 | /// 24 | public static class BsonSymbolTable 25 | { 26 | // private static fields 27 | private static object __staticLock = new object(); 28 | private static Dictionary __symbolTable = new Dictionary(); 29 | 30 | // public static methods 31 | /// 32 | /// Looks up a symbol (and creates a new one if necessary). 33 | /// 34 | /// The name of the symbol. 35 | /// The symbol. 36 | public static BsonSymbol Lookup(string name) 37 | { 38 | if (name == null) 39 | { 40 | throw new ArgumentNullException("name"); 41 | } 42 | lock (__staticLock) 43 | { 44 | BsonSymbol symbol; 45 | if (!__symbolTable.TryGetValue(name, out symbol)) 46 | { 47 | symbol = new BsonSymbol(name); 48 | __symbolTable[name] = symbol; 49 | } 50 | return symbol; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/ObjectModel/GuidRepresentation.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2016 MongoDB Inc. 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 | 16 | using System; 17 | namespace MongoDB.Bson 18 | { 19 | /// 20 | /// Represents the representation to use when converting a Guid to a BSON binary value. 21 | /// 22 | #if NET45 23 | [Serializable] 24 | #endif 25 | public enum GuidRepresentation 26 | { 27 | /// 28 | /// The representation for Guids is unspecified, so conversion between Guids and Bson binary data is not possible. 29 | /// 30 | Unspecified = 0, 31 | /// 32 | /// Use the new standard representation for Guids (binary subtype 4 with bytes in network byte order). 33 | /// 34 | Standard, 35 | /// 36 | /// Use the representation used by older versions of the C# driver (including most community provided C# drivers). 37 | /// 38 | CSharpLegacy, 39 | /// 40 | /// Use the representation used by older versions of the Java driver. 41 | /// 42 | JavaLegacy, 43 | /// 44 | /// Use the representation used by older versions of the Python driver. 45 | /// 46 | PythonLegacy 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/ObjectModel/IConvertibleToBsonDocument.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson 17 | { 18 | /// 19 | /// An interface implemented by objects that convert themselves to a BsonDocument. 20 | /// 21 | public interface IConvertibleToBsonDocument 22 | { 23 | /// 24 | /// Converts this object to a BsonDocument. 25 | /// 26 | /// A BsonDocument. 27 | BsonDocument ToBsonDocument(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/ObjectModel/ICustomBsonTypeMapper.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson 17 | { 18 | /// 19 | /// An interface for custom mappers that map an object to a BsonValue. 20 | /// 21 | public interface ICustomBsonTypeMapper 22 | { 23 | /// 24 | /// Tries to map an object to a BsonValue. 25 | /// 26 | /// An object. 27 | /// The BsonValue. 28 | /// True if the mapping was successfull. 29 | bool TryMapToBsonValue(object value, out BsonValue bsonValue); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/PowerOf2.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2015 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson 19 | { 20 | internal static class PowerOf2 21 | { 22 | public static bool IsPowerOf2(int n) 23 | { 24 | return n == RoundUpToPowerOf2(n); 25 | } 26 | 27 | public static int RoundUpToPowerOf2(int n) 28 | { 29 | if (n < 0 || n > 0x40000000) 30 | { 31 | throw new ArgumentOutOfRangeException("n"); 32 | } 33 | 34 | // see: Hacker's Delight, by Henry S. Warren 35 | n = n - 1; 36 | n = n | (n >> 1); 37 | n = n | (n >> 2); 38 | n = n | (n >> 4); 39 | n = n | (n >> 8); 40 | n = n | (n >> 16); 41 | return n + 1; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/BsonExtraElementsAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Attributes 19 | { 20 | /// 21 | /// Indicates that this property or field will be used to hold any extra elements found during deserialization. 22 | /// 23 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] 24 | [BsonMemberMapAttributeUsage(AllowMultipleMembers = false)] 25 | public class BsonExtraElementsAttribute : Attribute, IBsonMemberMapAttribute 26 | { 27 | // public methods 28 | /// 29 | /// Applies a modification to the member map. 30 | /// 31 | /// The member map. 32 | public void Apply(BsonMemberMap memberMap) 33 | { 34 | memberMap.ClassMap.SetExtraElementsMember(memberMap); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/BsonIgnoreAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Attributes 19 | { 20 | /// 21 | /// Indicates that this field or property should be ignored when this class is serialized. 22 | /// 23 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] 24 | public class BsonIgnoreAttribute : Attribute 25 | { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/BsonMemberMapAttributeUsageAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization 19 | { 20 | /// 21 | /// Indicates the usage restrictions for the attribute. 22 | /// 23 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 24 | public class BsonMemberMapAttributeUsageAttribute : Attribute 25 | { 26 | // private fields 27 | private bool _allowMultipleMembers; 28 | 29 | // constructors 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | public BsonMemberMapAttributeUsageAttribute() 34 | { 35 | _allowMultipleMembers = true; 36 | } 37 | 38 | // public properties 39 | /// 40 | /// Gets or sets a value indicating whether the attribute this attribute applies to is allowed to be applied 41 | /// to more than one member. 42 | /// 43 | public bool AllowMultipleMembers 44 | { 45 | get { return _allowMultipleMembers; } 46 | set { _allowMultipleMembers = value; } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/BsonNoIdAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Attributes 19 | { 20 | /// 21 | /// Specifies that the class's IdMember should be null. 22 | /// 23 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] 24 | public class BsonNoIdAttribute : Attribute, IBsonPostProcessingAttribute 25 | { 26 | // public methods 27 | /// 28 | /// Applies the post processing attribute to the class map. 29 | /// 30 | /// The class map. 31 | public void PostProcess(BsonClassMap classMap) 32 | { 33 | classMap.SetIdMember(null); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/BsonRequiredAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Attributes 19 | { 20 | /// 21 | /// Indicates that a field or property is required. 22 | /// 23 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] 24 | public class BsonRequiredAttribute : Attribute, IBsonMemberMapAttribute 25 | { 26 | // public methods 27 | /// 28 | /// Applies a modification to the member map. 29 | /// 30 | /// The member map. 31 | public void Apply(BsonMemberMap memberMap) 32 | { 33 | memberMap.SetIsRequired(true); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/IBsonClassMapAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization 17 | { 18 | /// 19 | /// Represents an attribute used to modify a class map. 20 | /// 21 | public interface IBsonClassMapAttribute 22 | { 23 | /// 24 | /// Applies the attribute to the class map. 25 | /// 26 | /// The class map. 27 | void Apply(BsonClassMap classMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/IBsonCreatorMapAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization 17 | { 18 | /// 19 | /// Represents an attribute used to modify a creator map. 20 | /// 21 | public interface IBsonCreatorMapAttribute 22 | { 23 | /// 24 | /// Applies the attribute to the creator map. 25 | /// 26 | /// The creator map. 27 | void Apply(BsonCreatorMap creatorMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/IBsonMemberMapAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization 17 | { 18 | /// 19 | /// Represents an attribute used to modify a member map. 20 | /// 21 | public interface IBsonMemberMapAttribute 22 | { 23 | /// 24 | /// Applies the attribute to the member map. 25 | /// 26 | /// The member map. 27 | void Apply(BsonMemberMap memberMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Attributes/IBsonPostProcessingAttribute.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization 17 | { 18 | /// 19 | /// Represents an attribute used to post process a class map. 20 | /// 21 | public interface IBsonPostProcessingAttribute 22 | { 23 | /// 24 | /// Applies the post processing attribute to the class map. 25 | /// 26 | /// The class map. 27 | void PostProcess(BsonClassMap classMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/BsonDeserializationArgs.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using MongoDB.Bson.IO; 18 | 19 | namespace MongoDB.Bson.Serialization 20 | { 21 | /// 22 | /// Represents args common to all serializers. 23 | /// 24 | public struct BsonDeserializationArgs 25 | { 26 | // private fields 27 | private Type _nominalType; 28 | 29 | // constructors 30 | private BsonDeserializationArgs( 31 | Type nominalType) 32 | { 33 | _nominalType = nominalType; 34 | } 35 | 36 | // public properties 37 | /// 38 | /// Gets or sets the nominal type. 39 | /// 40 | /// 41 | /// The nominal type. 42 | /// 43 | public Type NominalType 44 | { 45 | get { return _nominalType; } 46 | set { _nominalType = value; } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/CamelCaseElementNameConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using System.Reflection; 18 | 19 | namespace MongoDB.Bson.Serialization.Conventions 20 | { 21 | /// 22 | /// A convention that sets the element name the same as the member name with the first character lower cased. 23 | /// 24 | public class CamelCaseElementNameConvention : ConventionBase, IMemberMapConvention 25 | { 26 | // public methods 27 | /// 28 | /// Applies a modification to the member map. 29 | /// 30 | /// The member map. 31 | public void Apply(BsonMemberMap memberMap) 32 | { 33 | string name = memberMap.MemberName; 34 | name = GetElementName(name); 35 | memberMap.SetElementName(name); 36 | } 37 | 38 | // private methods 39 | private string GetElementName(string memberName) 40 | { 41 | if (memberName.Length == 0) 42 | { 43 | return ""; 44 | } 45 | else if(memberName.Length == 1) 46 | { 47 | return Char.ToLowerInvariant(memberName[0]).ToString(); 48 | } 49 | else 50 | { 51 | return Char.ToLowerInvariant(memberName[0]) + memberName.Substring(1); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/DelegateClassMapConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Conventions 19 | { 20 | /// 21 | /// A class map convention that wraps a delegate. 22 | /// 23 | public class DelegateClassMapConvention : ConventionBase, IClassMapConvention 24 | { 25 | // private fields 26 | private readonly Action _action; 27 | 28 | // constructors 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | /// The name. 33 | /// The delegate. 34 | public DelegateClassMapConvention(string name, Action action) 35 | : base(name) 36 | { 37 | if (action == null) 38 | { 39 | throw new ArgumentNullException("action"); 40 | } 41 | _action = action; 42 | } 43 | 44 | // public methods 45 | /// 46 | /// Applies a modification to the class map. 47 | /// 48 | /// The class map. 49 | public void Apply(BsonClassMap classMap) 50 | { 51 | _action(classMap); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/DelegateMemberMapConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Conventions 19 | { 20 | /// 21 | /// A member map convention that wraps a delegate. 22 | /// 23 | public class DelegateMemberMapConvention : ConventionBase, IMemberMapConvention 24 | { 25 | // private fields 26 | private readonly Action _action; 27 | 28 | // constructors 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | /// The name. 33 | /// The delegate. 34 | public DelegateMemberMapConvention(string name, Action action) 35 | : base(name) 36 | { 37 | if (action == null) 38 | { 39 | throw new ArgumentNullException("action"); 40 | } 41 | _action = action; 42 | } 43 | 44 | // public methods 45 | /// 46 | /// Applies a modification to the member map. 47 | /// 48 | /// The member map. 49 | public void Apply(BsonMemberMap memberMap) 50 | { 51 | _action(memberMap); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/DelegatePostProcessingConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Conventions 19 | { 20 | /// 21 | /// A post processing convention that wraps a delegate. 22 | /// 23 | public class DelegatePostProcessingConvention : ConventionBase, IPostProcessingConvention 24 | { 25 | // private fields 26 | private readonly Action _action; 27 | 28 | // constructors 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | /// The name. 33 | /// The delegate. 34 | public DelegatePostProcessingConvention(string name, Action action) 35 | : base(name) 36 | { 37 | if (action == null) 38 | { 39 | throw new ArgumentNullException("action"); 40 | } 41 | _action = action; 42 | } 43 | 44 | // public methods 45 | /// 46 | /// Applies a post processing modification to the class map. 47 | /// 48 | /// The class map. 49 | public void PostProcess(BsonClassMap classMap) 50 | { 51 | _action(classMap); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IClassMapConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// Represents a convention that applies to a BsonClassMap. 20 | /// 21 | public interface IClassMapConvention : IConvention 22 | { 23 | /// 24 | /// Applies a modification to the class map. 25 | /// 26 | /// The class map. 27 | void Apply(BsonClassMap classMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// Represents a convention. 20 | /// 21 | public interface IConvention 22 | { 23 | /// 24 | /// Gets the name of the convention. 25 | /// 26 | string Name { get; } 27 | } 28 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IConventionPack.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System.Collections.Generic; 17 | 18 | namespace MongoDB.Bson.Serialization.Conventions 19 | { 20 | /// 21 | /// Represents a grouping of conventions. 22 | /// 23 | public interface IConventionPack 24 | { 25 | /// 26 | /// Gets the conventions. 27 | /// 28 | IEnumerable Conventions { get; } 29 | } 30 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/ICreatorMapConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// Represents a convention that applies to a BsonCreatorMap. 20 | /// 21 | public interface ICreatorMapConvention : IConvention 22 | { 23 | /// 24 | /// Applies a modification to the creator map. 25 | /// 26 | /// The creator map. 27 | void Apply(BsonCreatorMap creatorMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IDiscriminatorConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using MongoDB.Bson.IO; 18 | 19 | namespace MongoDB.Bson.Serialization.Conventions 20 | { 21 | /// 22 | /// Represents a discriminator convention. 23 | /// 24 | public interface IDiscriminatorConvention 25 | { 26 | /// 27 | /// Gets the discriminator element name. 28 | /// 29 | string ElementName { get; } 30 | 31 | /// 32 | /// Gets the actual type of an object by reading the discriminator from a BsonReader. 33 | /// 34 | /// The reader. 35 | /// The nominal type. 36 | /// The actual type. 37 | Type GetActualType(IBsonReader bsonReader, Type nominalType); 38 | 39 | /// 40 | /// Gets the discriminator value for an actual type. 41 | /// 42 | /// The nominal type. 43 | /// The actual type. 44 | /// The discriminator value. 45 | BsonValue GetDiscriminator(Type nominalType, Type actualType); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IMemberMapConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// Represents a convention that applies to a BsonMemberMap. 20 | /// 21 | public interface IMemberMapConvention : IConvention 22 | { 23 | /// 24 | /// Applies a modification to the member map. 25 | /// 26 | /// The member map. 27 | void Apply(BsonMemberMap memberMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IPostProcessingConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// Represents a post processing convention that applies to a BsonClassMap. 20 | /// 21 | public interface IPostProcessingConvention : IConvention 22 | { 23 | /// 24 | /// Applies a post processing modification to the class map. 25 | /// 26 | /// The class map. 27 | void PostProcess(BsonClassMap classMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IgnoreExtraElementsConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// A convention that sets whether to ignore extra elements encountered during deserialization. 20 | /// 21 | public class IgnoreExtraElementsConvention : ConventionBase, IClassMapConvention 22 | { 23 | // private fields 24 | private bool _ignoreExtraElements; 25 | 26 | // constructors 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// Whether to ignore extra elements encountered during deserialization. 31 | public IgnoreExtraElementsConvention(bool ignoreExtraElements) 32 | { 33 | _ignoreExtraElements = ignoreExtraElements; 34 | } 35 | 36 | /// 37 | /// Applies a modification to the class map. 38 | /// 39 | /// The class map. 40 | public void Apply(BsonClassMap classMap) 41 | { 42 | classMap.SetIgnoreExtraElements(_ignoreExtraElements); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IgnoreIfDefaultConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// A convention that sets whether to ignore default values during serialization. 20 | /// 21 | public class IgnoreIfDefaultConvention : ConventionBase, IMemberMapConvention 22 | { 23 | // private fields 24 | private bool _ignoreIfDefault; 25 | 26 | // constructors 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// Whether to ignore default values during serialization. 31 | public IgnoreIfDefaultConvention(bool ignoreIfDefault) 32 | { 33 | _ignoreIfDefault = ignoreIfDefault; 34 | } 35 | 36 | /// 37 | /// Applies a modification to the member map. 38 | /// 39 | /// The member map. 40 | public void Apply(BsonMemberMap memberMap) 41 | { 42 | memberMap.SetIgnoreIfDefault(_ignoreIfDefault); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/IgnoreIfNullConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// A convention that sets whether to ignore nulls during serialization. 20 | /// 21 | public class IgnoreIfNullConvention : ConventionBase, IMemberMapConvention 22 | { 23 | // private fields 24 | private bool _ignoreIfNull; 25 | 26 | // constructors 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// Whether to ignore nulls during serialization. 31 | public IgnoreIfNullConvention(bool ignoreIfNull) 32 | { 33 | _ignoreIfNull = ignoreIfNull; 34 | } 35 | 36 | /// 37 | /// Applies a modification to the member map. 38 | /// 39 | /// The member map. 40 | public void Apply(BsonMemberMap memberMap) 41 | { 42 | memberMap.SetIgnoreIfNull(_ignoreIfNull); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/LookupIdGeneratorConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using System.Reflection; 18 | 19 | namespace MongoDB.Bson.Serialization.Conventions 20 | { 21 | /// 22 | /// A convention that looks up an id generator for the id member. 23 | /// 24 | public class LookupIdGeneratorConvention : ConventionBase, IPostProcessingConvention 25 | { 26 | // public methods 27 | /// 28 | /// Applies a post processing modification to the class map. 29 | /// 30 | /// The class map. 31 | public void PostProcess(BsonClassMap classMap) 32 | { 33 | var idMemberMap = classMap.IdMemberMap; 34 | if (idMemberMap != null) 35 | { 36 | if (idMemberMap.IdGenerator == null) 37 | { 38 | var idGenerator = BsonSerializer.LookupIdGenerator(idMemberMap.MemberType); 39 | if (idGenerator != null) 40 | { 41 | idMemberMap.SetIdGenerator(idGenerator); 42 | } 43 | } 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/MemberDefaultValueConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization.Conventions 19 | { 20 | /// 21 | /// A convention that sets the default value for members of a given type. 22 | /// 23 | public class MemberDefaultValueConvention : ConventionBase, IMemberMapConvention 24 | { 25 | // private fields 26 | private readonly Type _type; 27 | private readonly object _defaultValue; 28 | 29 | // constructors 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | /// The type of the member. 34 | /// The default value for members of this type. 35 | public MemberDefaultValueConvention(Type type, object defaultValue) 36 | { 37 | _type = type; 38 | _defaultValue = defaultValue; 39 | } 40 | 41 | // public methods 42 | /// 43 | /// Applies a modification to the member map. 44 | /// 45 | /// The member map. 46 | public void Apply(BsonMemberMap memberMap) 47 | { 48 | if (memberMap.MemberType == _type) 49 | { 50 | memberMap.SetDefaultValue(_defaultValue); 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/MemberNameElementNameConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using System.Reflection; 18 | 19 | namespace MongoDB.Bson.Serialization.Conventions 20 | { 21 | /// 22 | /// A convention that sets the element name the same as the member name. 23 | /// 24 | public class MemberNameElementNameConvention : ConventionBase, IMemberMapConvention 25 | { 26 | // public methods 27 | /// 28 | /// Applies a modification to the member map. 29 | /// 30 | /// The member map. 31 | public void Apply(BsonMemberMap memberMap) 32 | { 33 | memberMap.SetElementName(memberMap.MemberName); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/NoIdMemberConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Reflection; 20 | 21 | namespace MongoDB.Bson.Serialization.Conventions 22 | { 23 | /// 24 | /// A convention that sets a class's IdMember to null. 25 | /// 26 | public class NoIdMemberConvention : ConventionBase, IPostProcessingConvention 27 | { 28 | // public methods 29 | /// 30 | /// Applies a post processing modification to the class map. 31 | /// 32 | /// The class map. 33 | public void PostProcess(BsonClassMap classMap) 34 | { 35 | classMap.SetIdMember(null); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/ResetClassMapConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// A convention that resets a class map (resetting any changes that earlier conventions may have applied). 20 | /// 21 | public class ResetClassMapConvention : ConventionBase, IClassMapConvention 22 | { 23 | // public methods 24 | /// 25 | /// Applies a modification to the class map. 26 | /// 27 | /// The class map. 28 | public void Apply(BsonClassMap classMap) 29 | { 30 | classMap.Reset(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/ResetMemberMapsConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Conventions 17 | { 18 | /// 19 | /// A convention that resets class members (resetting any changes that earlier conventions may have applied). 20 | /// 21 | public class ResetMemberMapsConvention : ConventionBase, IMemberMapConvention 22 | { 23 | // public methods 24 | /// 25 | /// Applies a modification to the member map. 26 | /// 27 | /// The member map. 28 | public void Apply(BsonMemberMap memberMap) 29 | { 30 | memberMap.Reset(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Conventions/StringObjectIdIdGeneratorConvention.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using MongoDB.Bson.Serialization.IdGenerators; 17 | using MongoDB.Bson.Serialization.Options; 18 | using MongoDB.Bson.Serialization.Serializers; 19 | 20 | namespace MongoDB.Bson.Serialization.Conventions 21 | { 22 | /// 23 | /// A convention that sets the id generator for a string member with a BSON representation of ObjectId. 24 | /// 25 | public class StringObjectIdIdGeneratorConvention : ConventionBase, IPostProcessingConvention 26 | { 27 | // public methods 28 | /// 29 | /// Applies a post processing modification to the class map. 30 | /// 31 | /// The class map. 32 | public void PostProcess(BsonClassMap classMap) 33 | { 34 | var idMemberMap = classMap.IdMemberMap; 35 | if (idMemberMap != null) 36 | { 37 | if (idMemberMap.IdGenerator == null) 38 | { 39 | var stringSerializer = idMemberMap.GetSerializer() as StringSerializer; 40 | if (stringSerializer != null && stringSerializer.Representation == BsonType.ObjectId) 41 | { 42 | idMemberMap.SetIdGenerator(StringObjectIdGenerator.Instance); 43 | } 44 | } 45 | } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/DiscriminatedInterfaceSerializationProvider.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2016 MongoDB Inc. 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 | 16 | using System; 17 | using System.Reflection; 18 | using MongoDB.Bson.Serialization.Serializers; 19 | 20 | namespace MongoDB.Bson.Serialization 21 | { 22 | /// 23 | /// Provides a serializer for interfaces. 24 | /// 25 | public class DiscriminatedInterfaceSerializationProvider : BsonSerializationProviderBase 26 | { 27 | /// 28 | public override IBsonSerializer GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry) 29 | { 30 | if (type == null) 31 | { 32 | throw new ArgumentNullException("type"); 33 | } 34 | var typeInfo = type.GetTypeInfo(); 35 | if (typeInfo.IsGenericType && typeInfo.ContainsGenericParameters) 36 | { 37 | var message = string.Format("Generic type {0} has unassigned type parameters.", BsonUtils.GetFriendlyTypeName(type)); 38 | throw new ArgumentException(message, "type"); 39 | } 40 | 41 | if (typeInfo.IsInterface) 42 | { 43 | var serializerTypeDefinition = typeof(DiscriminatedInterfaceSerializer<>); 44 | return CreateGenericSerializer(serializerTypeDefinition, new[] { type }, serializerRegistry); 45 | } 46 | 47 | return null; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IBsonArraySerializer.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2015 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization 17 | { 18 | /// 19 | /// Contract for serializers to implement if they serialize an array of items. 20 | /// 21 | public interface IBsonArraySerializer : IBsonSerializer 22 | { 23 | /// 24 | /// Tries to get the serialization info for the individual items of the array. 25 | /// 26 | /// The serialization information. 27 | /// 28 | /// true if the serialization info exists; otherwise false. 29 | /// 30 | bool TryGetItemSerializationInfo(out BsonSerializationInfo serializationInfo); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IBsonDictionarySerializer.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using MongoDB.Bson.Serialization.Options; 17 | 18 | namespace MongoDB.Bson.Serialization 19 | { 20 | /// 21 | /// Represents a dictionary serializer that can be used in LINQ queries. 22 | /// 23 | public interface IBsonDictionarySerializer 24 | { 25 | /// 26 | /// Gets the dictionary representation. 27 | /// 28 | /// 29 | /// The dictionary representation. 30 | /// 31 | DictionaryRepresentation DictionaryRepresentation { get; } 32 | 33 | /// 34 | /// Gets the key serializer. 35 | /// 36 | /// 37 | /// The key serializer. 38 | /// 39 | IBsonSerializer KeySerializer { get; } 40 | 41 | /// 42 | /// Gets the value serializer. 43 | /// 44 | /// 45 | /// The value serializer. 46 | /// 47 | IBsonSerializer ValueSerializer { get; } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IBsonDocumentSerializer.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2015 MongoDB Inc. 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 | 16 | using System.Collections.Generic; 17 | namespace MongoDB.Bson.Serialization 18 | { 19 | /// 20 | /// Contract for composite serializers that contain a number of named serializers. 21 | /// 22 | public interface IBsonDocumentSerializer : IBsonSerializer 23 | { 24 | /// 25 | /// Tries to get the serialization info for a member. 26 | /// 27 | /// Name of the member. 28 | /// The serialization information. 29 | /// true if the serialization info exists; otherwise false. 30 | bool TryGetMemberSerializationInfo(string memberName, out BsonSerializationInfo serializationInfo); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IBsonIdProvider.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization 19 | { 20 | /// 21 | /// Contract for serializers that can get and set Id values. 22 | /// 23 | public interface IBsonIdProvider 24 | { 25 | /// 26 | /// Gets the document Id. 27 | /// 28 | /// The document. 29 | /// The Id. 30 | /// The nominal type of the Id. 31 | /// The IdGenerator for the Id type. 32 | /// True if the document has an Id. 33 | bool GetDocumentId(object document, out object id, out Type idNominalType, out IIdGenerator idGenerator); 34 | 35 | /// 36 | /// Sets the document Id. 37 | /// 38 | /// The document. 39 | /// The Id. 40 | void SetDocumentId(object document, object id); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IBsonPolymorphicSerializer.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using MongoDB.Bson.IO; 18 | 19 | namespace MongoDB.Bson.Serialization 20 | { 21 | /// 22 | /// An interface implemented by a polymorphic serializer. 23 | /// 24 | public interface IBsonPolymorphicSerializer 25 | { 26 | /// 27 | /// Gets a value indicating whether this serializer's discriminator is compatible with the object serializer. 28 | /// 29 | /// 30 | /// true if this serializer's discriminator is compatible with the object serializer; otherwise, false. 31 | /// 32 | bool IsDiscriminatorCompatibleWithObjectSerializer { get; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IBsonSerializationProvider.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2015 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization 19 | { 20 | /// 21 | /// An interface implemented by serialization providers. 22 | /// 23 | public interface IBsonSerializationProvider 24 | { 25 | /// 26 | /// Gets a serializer for a type. 27 | /// 28 | /// The type. 29 | /// A serializer. 30 | IBsonSerializer GetSerializer(Type type); 31 | } 32 | 33 | /// 34 | /// An interface implemented by serialization providers that are aware of registries. 35 | /// 36 | /// 37 | /// This interface was added to preserve backward compatability (changing IBsonSerializationProvider would have been a backward breaking change). 38 | /// 39 | public interface IRegistryAwareBsonSerializationProvider : IBsonSerializationProvider 40 | { 41 | /// 42 | /// Gets a serializer for a type. 43 | /// 44 | /// The type. 45 | /// The serializer registry. 46 | /// 47 | /// A serializer. 48 | /// 49 | IBsonSerializer GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IBsonSerializerRegistry.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | 18 | namespace MongoDB.Bson.Serialization 19 | { 20 | /// 21 | /// A serializer registry. 22 | /// 23 | public interface IBsonSerializerRegistry 24 | { 25 | /// 26 | /// Gets the serializer for the specified . 27 | /// 28 | /// The type. 29 | /// The serializer. 30 | IBsonSerializer GetSerializer(Type type); 31 | 32 | /// 33 | /// Gets the serializer for the specified . 34 | /// 35 | /// 36 | /// The serializer. 37 | IBsonSerializer GetSerializer(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IChildSerializerConfigurable.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization 17 | { 18 | // this interface is public so custom serializers can choose to implement it 19 | // but typically you would choose to implement this interface explicitly 20 | // these methods support forwarding attributes to child serializers and wouldn't normally be public 21 | 22 | /// 23 | /// Represents a serializer that has a child serializer that configuration attributes can be forwarded to. 24 | /// 25 | public interface IChildSerializerConfigurable 26 | { 27 | /// 28 | /// Gets the child serializer. 29 | /// 30 | /// 31 | /// The child serializer. 32 | /// 33 | IBsonSerializer ChildSerializer { get; } 34 | 35 | /// 36 | /// Returns a serializer that has been reconfigured with the specified child serializer. 37 | /// 38 | /// The child serializer. 39 | /// The reconfigured serializer. 40 | IBsonSerializer WithChildSerializer(IBsonSerializer childSerializer); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/ICreatorSelector.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System.Collections.Generic; 17 | 18 | namespace MongoDB.Bson.Serialization 19 | { 20 | internal interface ICreatorSelector 21 | { 22 | BsonCreatorMap SelectCreator(BsonClassMap classMap, Dictionary values); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/IIdGenerator.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization 17 | { 18 | /// 19 | /// An interface implemented by Id generators. 20 | /// 21 | public interface IIdGenerator 22 | { 23 | /// 24 | /// Generates an Id for a document. 25 | /// 26 | /// The container of the document (will be a MongoCollection when called from the C# driver). 27 | /// The document. 28 | /// An Id. 29 | object GenerateId(object container, object document); 30 | /// 31 | /// Tests whether an Id is empty. 32 | /// 33 | /// The Id. 34 | /// True if the Id is empty. 35 | bool IsEmpty(object id); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Options/DictionaryRepresentation.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using MongoDB.Bson.Serialization.Attributes; 18 | using MongoDB.Bson.Serialization.Serializers; 19 | 20 | namespace MongoDB.Bson.Serialization.Options 21 | { 22 | /// 23 | /// Represents the representation to use for dictionaries. 24 | /// 25 | public enum DictionaryRepresentation 26 | { 27 | /// 28 | /// Represent the dictionary as a Document. 29 | /// 30 | Document, 31 | /// 32 | /// Represent the dictionary as an array of arrays. 33 | /// 34 | ArrayOfArrays, 35 | /// 36 | /// Represent the dictionary as an array of documents. 37 | /// 38 | ArrayOfDocuments 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Options/TimeSpanUnits.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | namespace MongoDB.Bson.Serialization.Options 17 | { 18 | /// 19 | /// Represents the units a TimeSpan is serialized in. 20 | /// 21 | public enum TimeSpanUnits 22 | { 23 | /// 24 | /// Use ticks as the units. 25 | /// 26 | Ticks = 0, 27 | /// 28 | /// Use days as the units. 29 | /// 30 | Days, 31 | /// 32 | /// Use hours as the units. 33 | /// 34 | Hours, 35 | /// 36 | /// Use minutes as the units. 37 | /// 38 | Minutes, 39 | /// 40 | /// Use seconds as the units. 41 | /// 42 | Seconds, 43 | /// 44 | /// Use milliseconds as the units. 45 | /// 46 | Milliseconds, 47 | /// 48 | /// Use microseconds as the units. 49 | /// 50 | Microseconds, 51 | /// 52 | /// Use nanoseconds as the units. 53 | /// 54 | Nanoseconds 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Serializers/AbstractClassSerializer.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Threading.Tasks; 21 | 22 | namespace MongoDB.Bson.Serialization.Serializers 23 | { 24 | /// 25 | /// Represents a serializer for an abstract class. 26 | /// 27 | /// The type of the class. 28 | public class AbstractClassSerializer : ClassSerializerBase where TClass : class 29 | { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Bson/Serialization/Serializers/StructSerializerBase.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2010-2014 MongoDB Inc. 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 | 16 | using System; 17 | using MongoDB.Bson.IO; 18 | using MongoDB.Bson.Serialization.Conventions; 19 | 20 | namespace MongoDB.Bson.Serialization.Serializers 21 | { 22 | /// 23 | /// Represents an abstract base class for struct serializers. 24 | /// 25 | /// The type of the value. 26 | public abstract class StructSerializerBase : SerializerBase where TValue : struct 27 | { 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ThirdParty/MongoDB/MongoDB.Shared/ApplicationNameHelper.cs: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 MongoDB Inc. 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 | 16 | using System; 17 | using MongoDB.Bson.IO; 18 | 19 | namespace MongoDB.Shared 20 | { 21 | internal static class ApplicationNameHelper 22 | { 23 | public static string EnsureApplicationNameIsValid(string applicationName, string paramName) 24 | { 25 | string message; 26 | if (!IsApplicationNameValid(applicationName, out message)) 27 | { 28 | throw new ArgumentException(message, paramName); 29 | } 30 | 31 | return applicationName; 32 | } 33 | 34 | public static bool IsApplicationNameValid(string applicationName, out string message) 35 | { 36 | if (applicationName != null) 37 | { 38 | var utf8 = Utf8Encodings.Strict.GetBytes(applicationName); 39 | if (utf8.Length > 128) 40 | { 41 | message = "Application name exceeds 128 bytes after encoding to UTF8."; 42 | return false; 43 | } 44 | } 45 | 46 | message = null; 47 | return true; 48 | } 49 | } 50 | } 51 | --------------------------------------------------------------------------------