OSHConsole.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* This file is part of OpenSubtitles Handler
  2. A library that handle OpenSubtitles.org XML-RPC methods.
  3. Copyright © Ala Ibrahim Hadid 2013
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using System;
  16. namespace OpenSubtitlesHandler.Console
  17. {
  18. public class OSHConsole
  19. {
  20. /// <summary>
  21. /// Write line to the console and raise the "LineWritten" event
  22. /// </summary>
  23. ///
  24. /// <param name="text">The debug line</param>
  25. /// <param name="code">The status</param>
  26. public static void WriteLine(string text, DebugCode code = DebugCode.None)
  27. {
  28. if (LineWritten != null)
  29. LineWritten(null, new DebugEventArgs(text, code));
  30. }
  31. /// <summary>
  32. /// Update the last written line
  33. /// </summary>
  34. /// <param name="text">The debug line</param>
  35. /// <param name="code">The status</param>
  36. public static void UpdateLine(string text, DebugCode code = DebugCode.None)
  37. {
  38. if (UpdateLastLine != null)
  39. UpdateLastLine(null, new DebugEventArgs(text, code));
  40. }
  41. public static event EventHandler<DebugEventArgs> LineWritten;
  42. public static event EventHandler<DebugEventArgs> UpdateLastLine;
  43. }
  44. public enum DebugCode
  45. {
  46. None,
  47. Good,
  48. Warning,
  49. Error
  50. }
  51. /// <summary>
  52. /// Console Debug Args
  53. /// </summary>
  54. public class DebugEventArgs : EventArgs
  55. {
  56. public DebugCode Code { get; private set; }
  57. public string Text { get; private set; }
  58. /// <summary>
  59. /// Console Debug Args
  60. /// </summary>
  61. /// <param name="text">The debug line</param>
  62. /// <param name="code">The status</param>
  63. public DebugEventArgs(string text, DebugCode code)
  64. {
  65. this.Text = text;
  66. this.Code = code;
  67. }
  68. }
  69. public struct DebugLine
  70. {
  71. public DebugLine(string debugLine, DebugCode status)
  72. {
  73. this.debugLine = debugLine;
  74. this.status = status;
  75. }
  76. string debugLine;
  77. DebugCode status;
  78. public string Text
  79. { get { return debugLine; } set { debugLine = value; } }
  80. public DebugCode Code
  81. { get { return status; } set { status = value; } }
  82. }
  83. }