-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d20494b
commit be08db1
Showing
31 changed files
with
187 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using GameFrameX.Setting; | ||
using GameFrameX.Utility.Setting; | ||
|
||
namespace GameFrameX.Apps; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,113 @@ | ||
using GameFrameX.Log; | ||
using GameFrameX.Utility.Log; | ||
|
||
namespace GameFrameX.Apps | ||
namespace GameFrameX.Apps; | ||
|
||
public class DictionaryRepresentationConvention : ConventionBase, IMemberMapConvention | ||
{ | ||
public class DictionaryRepresentationConvention : ConventionBase, IMemberMapConvention | ||
{ | ||
private readonly DictionaryRepresentation _dictionaryRepresentation; | ||
private readonly DictionaryRepresentation _dictionaryRepresentation; | ||
|
||
public DictionaryRepresentationConvention(DictionaryRepresentation dictionaryRepresentation = DictionaryRepresentation.ArrayOfDocuments) | ||
{ | ||
_dictionaryRepresentation = dictionaryRepresentation; | ||
} | ||
public DictionaryRepresentationConvention(DictionaryRepresentation dictionaryRepresentation = DictionaryRepresentation.ArrayOfDocuments) | ||
{ | ||
_dictionaryRepresentation = dictionaryRepresentation; | ||
} | ||
|
||
public void Apply(BsonMemberMap memberMap) | ||
public void Apply(BsonMemberMap memberMap) | ||
{ | ||
var serializer = memberMap.GetSerializer(); | ||
if (serializer is IDictionaryRepresentationConfigurable dictionaryRepresentationConfigurable) | ||
{ | ||
var serializer = memberMap.GetSerializer(); | ||
if (serializer is IDictionaryRepresentationConfigurable dictionaryRepresentationConfigurable) | ||
{ | ||
var reconfiguredSerializer = dictionaryRepresentationConfigurable.WithDictionaryRepresentation(_dictionaryRepresentation); | ||
memberMap.SetSerializer(reconfiguredSerializer); | ||
} | ||
var reconfiguredSerializer = dictionaryRepresentationConfigurable.WithDictionaryRepresentation(_dictionaryRepresentation); | ||
memberMap.SetSerializer(reconfiguredSerializer); | ||
} | ||
} | ||
} | ||
|
||
public class EmptyContainerSerializeMethodConvention : ConventionBase, IMemberMapConvention | ||
public class EmptyContainerSerializeMethodConvention : ConventionBase, IMemberMapConvention | ||
{ | ||
public void Apply(BsonMemberMap memberMap) | ||
{ | ||
public void Apply(BsonMemberMap memberMap) | ||
if (memberMap.MemberType.IsGenericType) | ||
{ | ||
if (memberMap.MemberType.IsGenericType) | ||
var genType = memberMap.MemberType.GetGenericTypeDefinition(); | ||
if (genType == typeof(List<>)) | ||
{ | ||
var genType = memberMap.MemberType.GetGenericTypeDefinition(); | ||
if (genType == typeof(List<>)) | ||
memberMap.SetShouldSerializeMethod(o => | ||
{ | ||
memberMap.SetShouldSerializeMethod(o => | ||
var value = memberMap.Getter(o); | ||
if (value is IList list) | ||
{ | ||
var value = memberMap.Getter(o); | ||
if (value is IList list) | ||
{ | ||
return list != null && list.Count > 0; | ||
} | ||
return list != null && list.Count > 0; | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
else if (genType == typeof(ConcurrentDictionary<,>) || genType == typeof(Dictionary<,>)) | ||
else if (genType == typeof(ConcurrentDictionary<,>) || genType == typeof(Dictionary<,>)) | ||
{ | ||
memberMap.SetShouldSerializeMethod(o => | ||
{ | ||
memberMap.SetShouldSerializeMethod(o => | ||
if (o != null) | ||
{ | ||
if (o != null) | ||
var value = memberMap.Getter(o); | ||
if (value != null) | ||
{ | ||
var value = memberMap.Getter(o); | ||
if (value != null) | ||
var countProperty = value.GetType().GetProperty("Count"); | ||
if (countProperty != null) | ||
{ | ||
PropertyInfo countProperty = value.GetType().GetProperty("Count"); | ||
if (countProperty != null) | ||
{ | ||
int count = (int)countProperty.GetValue(value, null); | ||
return count > 0; | ||
} | ||
var count = (int)countProperty.GetValue(value, null); | ||
return count > 0; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
return true; | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static class BsonClassMapHelper | ||
public static class BsonClassMapHelper | ||
{ | ||
public static void SetConvention() | ||
{ | ||
public static void SetConvention() | ||
{ | ||
ConventionRegistry.Register(nameof(DictionaryRepresentationConvention), | ||
new ConventionPack { new DictionaryRepresentationConvention(DictionaryRepresentation.ArrayOfDocuments) }, _ => true); | ||
ConventionRegistry.Register(nameof(DictionaryRepresentationConvention), | ||
new ConventionPack { new DictionaryRepresentationConvention(), }, _ => true); | ||
|
||
ConventionRegistry.Register(nameof(EmptyContainerSerializeMethodConvention), | ||
new ConventionPack { new EmptyContainerSerializeMethodConvention() }, _ => true); | ||
} | ||
ConventionRegistry.Register(nameof(EmptyContainerSerializeMethodConvention), | ||
new ConventionPack { new EmptyContainerSerializeMethodConvention(), }, _ => true); | ||
} | ||
|
||
/// <summary> | ||
/// 提前注册,简化多态类型处理 | ||
/// </summary> | ||
/// <param name="assembly"></param> | ||
public static void RegisterAllClass(System.Reflection.Assembly assembly) | ||
/// <summary> | ||
/// 提前注册,简化多态类型处理 | ||
/// </summary> | ||
/// <param name="assembly"></param> | ||
public static void RegisterAllClass(Assembly assembly) | ||
{ | ||
var types = assembly.GetTypes(); | ||
foreach (var t in types) | ||
{ | ||
var types = assembly.GetTypes(); | ||
foreach (var t in types) | ||
try | ||
{ | ||
try | ||
if (!BsonClassMap.IsClassMapRegistered(t)) | ||
{ | ||
if (!BsonClassMap.IsClassMapRegistered(t)) | ||
{ | ||
RegisterClass(t); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
LogHelper.Error(e); | ||
RegisterClass(t); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
LogHelper.Error(e); | ||
} | ||
} | ||
} | ||
|
||
public static void RegisterClass(Type t) | ||
{ | ||
var bsonClassMap = new BsonClassMap(t); | ||
bsonClassMap.AutoMap(); | ||
bsonClassMap.SetIgnoreExtraElements(true); | ||
bsonClassMap.SetIgnoreExtraElementsIsInherited(true); | ||
BsonClassMap.RegisterClassMap(bsonClassMap); | ||
} | ||
public static void RegisterClass(Type t) | ||
{ | ||
var bsonClassMap = new BsonClassMap(t); | ||
bsonClassMap.AutoMap(); | ||
bsonClassMap.SetIgnoreExtraElements(true); | ||
bsonClassMap.SetIgnoreExtraElementsIsInherited(true); | ||
BsonClassMap.RegisterClassMap(bsonClassMap); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
| ||
|
||
using GameFrameX.DataBase.Abstractions; | ||
using GameFrameX.Utility.Extensions; | ||
|
||
namespace GameFrameX.Apps; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
using GameFrameX.Core.Abstractions.Events; | ||
|
||
namespace GameFrameX.Apps.Common.Event | ||
namespace GameFrameX.Apps.Common.Event; | ||
|
||
/// <summary> | ||
/// 表示事件的特性。 | ||
/// </summary> | ||
public sealed class EventAttribute : EventInfoAttribute | ||
{ | ||
/// <summary> | ||
/// 表示事件的特性。 | ||
/// 使用指定的事件ID初始化 <see cref="EventAttribute" /> 类的新实例。 | ||
/// </summary> | ||
public sealed class EventAttribute : EventInfoAttribute | ||
/// <param name="eventId">事件ID。</param> | ||
public EventAttribute(EventId eventId) : base((int)eventId) | ||
{ | ||
/// <summary> | ||
/// 使用指定的事件ID初始化 <see cref="EventAttribute"/> 类的新实例。 | ||
/// </summary> | ||
/// <param name="eventId">事件ID。</param> | ||
public EventAttribute(EventId eventId) : base((int)eventId) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,53 @@ | ||
namespace GameFrameX.Apps.Common.Event | ||
namespace GameFrameX.Apps.Common.Event; | ||
|
||
public enum EventId | ||
{ | ||
public enum EventId | ||
{ | ||
#region role event | ||
|
||
/// <summary> | ||
/// 玩家事件 | ||
/// </summary> | ||
SessionRemove = 1000, | ||
|
||
/// <summary> | ||
/// 玩家等级提升 | ||
/// </summary> | ||
RoleLevelUp = 1001, | ||
|
||
/// <summary> | ||
/// 玩家vip改变 | ||
/// </summary> | ||
RoleVipChange, | ||
|
||
/// <summary> | ||
/// 玩家上线 | ||
/// </summary> | ||
OnRoleOnline, | ||
|
||
/// <summary> | ||
/// 玩家下线 | ||
/// </summary> | ||
OnRoleOffline, | ||
|
||
/// <summary> | ||
/// 解锁用 | ||
/// </summary> | ||
GotNewPet, | ||
|
||
#endregion | ||
|
||
/// <summary> | ||
/// 玩家事件分割点 | ||
/// </summary> | ||
RoleSeparator = 8000, | ||
|
||
#region server event | ||
|
||
//服务器事件 | ||
/// <summary> | ||
/// 世界等级改变 | ||
/// </summary> | ||
WorldLevelChange, | ||
|
||
#endregion | ||
} | ||
#region role event | ||
|
||
/// <summary> | ||
/// 玩家事件 | ||
/// </summary> | ||
SessionRemove = 1000, | ||
|
||
/// <summary> | ||
/// 玩家等级提升 | ||
/// </summary> | ||
RoleLevelUp = 1001, | ||
|
||
/// <summary> | ||
/// 玩家vip改变 | ||
/// </summary> | ||
RoleVipChange, | ||
|
||
/// <summary> | ||
/// 玩家上线 | ||
/// </summary> | ||
OnRoleOnline, | ||
|
||
/// <summary> | ||
/// 玩家下线 | ||
/// </summary> | ||
OnRoleOffline, | ||
|
||
/// <summary> | ||
/// 解锁用 | ||
/// </summary> | ||
GotNewPet, | ||
|
||
#endregion | ||
|
||
/// <summary> | ||
/// 玩家事件分割点 | ||
/// </summary> | ||
RoleSeparator = 8000, | ||
|
||
#region server event | ||
|
||
//服务器事件 | ||
/// <summary> | ||
/// 世界等级改变 | ||
/// </summary> | ||
WorldLevelChange, | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.