CommandLoaderBase.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SuperSocket.Common;
  6. using SuperSocket.SocketBase.Config;
  7. namespace SuperSocket.SocketBase.Command
  8. {
  9. /// <summary>
  10. /// CommandLoader base class
  11. /// </summary>
  12. public abstract class CommandLoaderBase<TCommand> : ICommandLoader<TCommand>
  13. where TCommand : ICommand
  14. {
  15. /// <summary>
  16. /// Initializes the command loader by the root config and appserver instance.
  17. /// </summary>
  18. /// <param name="rootConfig">The root config.</param>
  19. /// <param name="appServer">The app server.</param>
  20. /// <returns></returns>
  21. public abstract bool Initialize(IRootConfig rootConfig, IAppServer appServer);
  22. /// <summary>
  23. /// Tries to load commands.
  24. /// </summary>
  25. /// <param name="commands">The commands.</param>
  26. /// <returns></returns>
  27. public abstract bool TryLoadCommands(out IEnumerable<TCommand> commands);
  28. /// <summary>
  29. /// Called when [updated].
  30. /// </summary>
  31. /// <param name="commands">The commands.</param>
  32. protected void OnUpdated(IEnumerable<CommandUpdateInfo<TCommand>> commands)
  33. {
  34. var handler = Updated;
  35. if (handler != null)
  36. handler(this, new CommandUpdateEventArgs<TCommand>(commands));
  37. }
  38. /// <summary>
  39. /// Occurs when [updated].
  40. /// </summary>
  41. public event EventHandler<CommandUpdateEventArgs<TCommand>> Updated;
  42. /// <summary>
  43. /// Called when [error].
  44. /// </summary>
  45. /// <param name="message">The message.</param>
  46. protected void OnError(string message)
  47. {
  48. OnError(new Exception(message));
  49. }
  50. /// <summary>
  51. /// Called when [error].
  52. /// </summary>
  53. /// <param name="e">The e.</param>
  54. protected void OnError(Exception e)
  55. {
  56. var handler = Error;
  57. if (handler != null)
  58. handler(this, new ErrorEventArgs(e));
  59. }
  60. /// <summary>
  61. /// Occurs when [error].
  62. /// </summary>
  63. public event EventHandler<ErrorEventArgs> Error;
  64. }
  65. }