Guest User

Untitled

a guest
Feb 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. class Callee
  2. {
  3. public void RegularCall(int command, parameters)
  4. {
  5. switch (command)
  6. {
  7. case 1: // Comand #1
  8. // Check if the permissions allow this command to be called.
  9. // Check if it should be outsourced to the ThreadPool and
  10. // call it accordingly. +Other Checks.
  11. // Finally execute command #1.
  12. break;
  13. case 2: // Comand #2
  14. // Check if the permissions allow that command to be called.
  15. // Check if it should be outsourced to the ThreadPool and
  16. // call it accordingly. +Other Checks.
  17. // Finally execute command #2.
  18. break;
  19. // Many more cases with various combinations of permissions and
  20. // Other flags.
  21. }
  22. }
  23. }
  24.  
  25. static Dictionary<int, Callee> callees = new Dictionary<int, Callee>();
  26.  
  27. static void CallMethod(int elementId, int commandId, parameters)
  28. {
  29. callees[elementId].RegularCall(commandId, parameters);
  30. }
  31.  
  32. class Callee
  33. {
  34. [Command(1)]
  35. [Permissions(0b00111000)]
  36. [UseThreadPool]
  37. public void SpeakingNameForCommand1(parameters)
  38. {
  39. // Code for command #1.
  40. }
  41.  
  42. [Command(2)]
  43. [Permissions(0b00101011)]
  44. public void SpeakingNameForCommand2(parameters)
  45. {
  46. // Code for command #2.
  47. }
  48.  
  49. // Again, many more commands.
  50. }
  51.  
  52. static Dictionary<int, CommandInfo> commands = new Dictionary<int, CommandInfo>();
  53.  
  54. static void CallMethod(int elementId, int commandId)
  55. {
  56. CommandInfo ci = commands[commandId];
  57.  
  58. if (ci.Permissions != EVERYTHING_OK)
  59. throw ...;
  60.  
  61. if (ci.UseThreadPool)
  62. ThreadPool.Queue...(delegate { ci.MethodInfover.Invoke(callees[elementId], params); });
  63. else
  64. ci.MethodInfo.Invoke(callees[elementId], params);
  65. }
Add Comment
Please, Sign In to add comment