DesktopConsole.cs 1.0 KB

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