Utils.cs 731 B

12345678910111213141516171819202122232425
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace PRS.Shared.Database_Update_Scripts.Utils;
  8. internal static class Utils
  9. {
  10. public static void ProcessInChunks<T>(IList<T> items, Action<IList<T>> processChunk, int stepBy, Action<double> reportPercentage)
  11. {
  12. for(int i = 0; i < items.Count; i += 1000)
  13. {
  14. reportPercentage((double)i / (double)items.Count * 100.0);
  15. var mpStages = new List<T>(1000);
  16. for(int j = i; j < Math.Min(i + 1000, items.Count); j++)
  17. {
  18. mpStages.Add(items[j]);
  19. }
  20. processChunk(mpStages);
  21. }
  22. }
  23. }