AMActorLocationHandler.cs 924 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. namespace ETModel
  3. {
  4. public abstract class AMActorLocationHandler<E, Message>: IMActorHandler where E: Entity where Message : class, IActorLocationMessage
  5. {
  6. protected abstract void Run(E entity, Message message);
  7. public async ETTask Handle(Session session, Entity entity, object actorMessage)
  8. {
  9. Message msg = actorMessage as Message;
  10. if (msg == null)
  11. {
  12. Log.Error($"消息类型转换错误: {actorMessage.GetType().FullName} to {typeof (Message).Name}");
  13. return;
  14. }
  15. E e = entity as E;
  16. if (e == null)
  17. {
  18. Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}");
  19. return;
  20. }
  21. ActorResponse actorResponse = new ActorResponse();
  22. actorResponse.RpcId = msg.RpcId;
  23. session.Reply(actorResponse);
  24. this.Run(e, msg);
  25. await ETTask.CompletedTask;
  26. }
  27. public Type GetMessageType()
  28. {
  29. return typeof (Message);
  30. }
  31. }
  32. }