AMActorLocationHandler.cs 950 B

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