DesktopConsole.cs 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using InABox.Core;
  2. using InABox.Logging;
  3. using InABox.Wpf.Console;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Console = InABox.Wpf.Console.Console;
  9. namespace PRSDesktop;
  10. public class DesktopConsole : Console
  11. {
  12. private EventLogger? logger;
  13. public DesktopConsole(string description): base(description)
  14. {
  15. }
  16. protected override void OnLoaded()
  17. {
  18. base.OnLoaded();
  19. ConsoleControl.Enabled = true;
  20. logger = new EventLogger(OnLog);
  21. MainLogger.AddLogger(logger);
  22. }
  23. private void OnLog(string message)
  24. {
  25. Dispatcher.BeginInvoke(() =>
  26. {
  27. ConsoleControl.LoadLogEntry(message);
  28. });
  29. }
  30. protected override void OnClosing()
  31. {
  32. base.OnClosing();
  33. if(logger is not null)
  34. {
  35. MainLogger.RemoveLogger(logger);
  36. }
  37. }
  38. protected override string GetLogDirectory()
  39. {
  40. return CoreUtils.GetPath();
  41. }
  42. }