DBSaveBatchRequestHandler.cs 954 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using Model;
  3. namespace Hotfix
  4. {
  5. [MessageHandler(AppType.DB)]
  6. public class DBSaveBatchRequestHandler : AMRpcHandler<DBSaveBatchRequest, DBSaveBatchResponse>
  7. {
  8. protected override async void Run(Session session, DBSaveBatchRequest message, Action<DBSaveBatchResponse> reply)
  9. {
  10. DBSaveBatchResponse response = new DBSaveBatchResponse();
  11. try
  12. {
  13. DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
  14. if (string.IsNullOrEmpty(message.CollectionName))
  15. {
  16. message.CollectionName = message.Disposers[0].GetType().Name;
  17. }
  18. if (message.NeedCache)
  19. {
  20. foreach (Disposer disposer in message.Disposers)
  21. {
  22. dbCacheComponent.AddToCache(disposer, message.CollectionName);
  23. }
  24. }
  25. await dbCacheComponent.AddBatch(message.Disposers, message.CollectionName);
  26. reply(response);
  27. }
  28. catch (Exception e)
  29. {
  30. ReplyError(response, e, reply);
  31. }
  32. }
  33. }
  34. }