Guest User

Untitled

a guest
Jan 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public static List<object> ExecutePolicy()
  2. {
  3. Policy policy = new Policy();
  4.  
  5. List<object> rules = GetRules();
  6.  
  7. object[] rulesObjs = rules.ToArray();
  8.  
  9. // Call this method with array of object, but in batches.
  10. policy.Execute(rulesObjs);
  11.  
  12. return rulesObjs.ToList();
  13. }
  14.  
  15. private static List<object> GetRules()
  16. {
  17. // get the rules via some process
  18. return new List<object>();
  19. }
  20. }
  21.  
  22. public sealed class Policy
  23. {
  24. public void Execute(params object[] rules)
  25. {
  26. // Process rules...
  27. }
  28. }
  29.  
  30. List<object> rules = GetRules();
  31. int batchSize = 500;
  32. int currentBatch = 0;
  33.  
  34. while (currentBatch * batchSize < rules.Count)
  35. {
  36. object[] nextBatch = rules.Skip(currentBatch * batchSize)
  37. .Take(batchSize).ToArray();
  38. //use batch
  39. currentBatch++;
  40. }
  41.  
  42. public void Execute(int startIndex, /*optional*/ int endIndex, params object[] rules)
  43. {
  44. // Process rules...
  45. }
  46.  
  47. int total = 10000;
  48. int chunkSize = 500;
  49. for (int i = 0; i < total; i += chunkSize )
  50. {
  51. var chunk = rulesObjs.Skip(i).Take(chunkSize).ToArray();
  52.  
  53. policy.Execute(chunk);
  54. }
Add Comment
Please, Sign In to add comment