DBSaveBatchRequestHandler.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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).NoAwait();
  11. }
  12. protected async ETVoid RunAsync(Session session, DBSaveBatchRequest message, Action<DBSaveBatchResponse> reply)
  13. {
  14. DBSaveBatchResponse response = new DBSaveBatchResponse();
  15. try
  16. {
  17. DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
  18. if (string.IsNullOrEmpty(message.CollectionName))
  19. {
  20. message.CollectionName = message.Components[0].GetType().Name;
  21. }
  22. if (message.NeedCache)
  23. {
  24. foreach (ComponentWithId component in message.Components)
  25. {
  26. dbCacheComponent.AddToCache(component, message.CollectionName);
  27. }
  28. }
  29. await dbCacheComponent.AddBatch(message.Components, message.CollectionName);
  30. reply(response);
  31. }
  32. catch (Exception e)
  33. {
  34. ReplyError(response, e, reply);
  35. }
  36. }
  37. }
  38. }