Skip to content

Commit

Permalink
[修改]1. 修改程序集的引用。从改版本开始为手动升级模式
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Jan 15, 2025
1 parent d20494b commit be08db1
Show file tree
Hide file tree
Showing 31 changed files with 187 additions and 194 deletions.
2 changes: 2 additions & 0 deletions GameFrameX.Apps/Account/Login/Entity/LoginState.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using GameFrameX.DataBase.Mongo;

namespace GameFrameX.Apps.Account.Login.Entity;

public class LoginState : CacheState
Expand Down
2 changes: 1 addition & 1 deletion GameFrameX.Apps/ActorType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GameFrameX.Setting;
using GameFrameX.Utility.Setting;

namespace GameFrameX.Apps;

Expand Down
153 changes: 76 additions & 77 deletions GameFrameX.Apps/BsonClassMapHelper.cs
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);
}
}
}
4 changes: 1 addition & 3 deletions GameFrameX.Apps/CacheStateTypeManager.cs
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;

Expand Down
19 changes: 9 additions & 10 deletions GameFrameX.Apps/Common/Event/EventAttribute.cs
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)
{
}
}
}
103 changes: 51 additions & 52 deletions GameFrameX.Apps/Common/Event/EventId.cs
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
}
1 change: 0 additions & 1 deletion GameFrameX.Apps/Common/Session/Session.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using GameFrameX.NetWork.Abstractions;
using GameFrameX.NetWork.Messages;
using GameFrameX.Setting;

namespace GameFrameX.Apps.Common.Session;

Expand Down
2 changes: 1 addition & 1 deletion GameFrameX.Apps/Common/Session/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using GameFrameX.Apps.Common.Event;
using GameFrameX.NetWork.Abstractions;
using GameFrameX.Setting;
using GameFrameX.Utility.Setting;

namespace GameFrameX.Apps.Common.Session;

Expand Down
4 changes: 2 additions & 2 deletions GameFrameX.Apps/GameFrameX.Apps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GameFrameX.Core" Version="1.2.0-beta16" />
<PackageReference Include="GameFrameX.Monitor" Version="1.2.0-beta16" />
<PackageReference Include="GameFrameX.Core" Version="1.2.0-beta18" />
<PackageReference Include="GameFrameX.Monitor" Version="1.2.0-beta18" />
</ItemGroup>
</Project>
5 changes: 0 additions & 5 deletions GameFrameX.Apps/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
global using MongoDB.Bson.Serialization.Attributes;
global using GameFrameX.Core;
global using GameFrameX.Core.Utility;
global using GameFrameX.Core.Components;
global using GameFrameX.Core.Events;
global using GameFrameX.Core.Hotfix.Agent;
global using GameFrameX.Core.Hotfix;
global using GameFrameX.Core.Actors;
global using GameFrameX.Core.Timer;
global using GameFrameX.Core.Abstractions.Attribute;
global using GameFrameX.Proto.Proto;
global using GameFrameX.DataBase;
global using GameFrameX.DataBase.Mongo;
global using GameFrameX.DataBase.Abstractions;
global using GameFrameX.Extension;
global using GameFrameX.Apps.Common.Event;
global using GameFrameX.Utility;
global using System.Collections;
global using System.Collections.Concurrent;
Expand Down
Loading

0 comments on commit be08db1

Please sign in to comment.