DBSaveBatchRequestHandler.cs 932 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. [MessageHandler(AppType.DB)]
  6. public class DBSaveBatchRequestHandler : AMRpcHandler<DBSaveBatchRequest, DBSaveBatchResponse>
  7. {
  8. protected override void Run(Session session, DBSaveBatchRequest message, Action<DBSaveBatchResponse> reply)
  9. {
  10. RunAsync(session, message, reply).Coroutine();
  11. }
  12. protected async ETVoid RunAsync(Session session, DBSaveBatchRequest message, Action<DBSaveBatchResponse> reply)
  13. {
  14. DBSaveBatchResponse response = new DBSaveBatchResponse();
  15. try
  16. {
  17. DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
  18. if (string.IsNullOrEmpty(message.CollectionName))
  19. {
  20. message.CollectionName = message.Components[0].GetType().Name;
  21. }
  22. await dbComponent.AddBatch(message.Components, message.CollectionName);
  23. reply(response);
  24. }
  25. catch (Exception e)
  26. {
  27. ReplyError(response, e, reply);
  28. }
  29. }
  30. }
  31. }