AMActorLocationHandler.cs 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 ETTask 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. try
  25. {
  26. await this.Run(e, msg);
  27. }
  28. catch (Exception exception)
  29. {
  30. Log.Error(exception);
  31. }
  32. }
  33. public Type GetMessageType()
  34. {
  35. return typeof (Message);
  36. }
  37. }
  38. }