Complete sources for a monero webminer.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.2 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. // The MIT License (MIT)
  2. // Copyright (c) 2018-2019 - the webminerpool developer
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. // this software and associated documentation files (the "Software"), to deal in
  5. // the Software without restriction, including without limitation the rights to
  6. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  7. // the Software, and to permit persons to whom the Software is furnished to do so,
  8. // subject to the following conditions:
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  13. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  14. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  15. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. using System;
  18. using System.IO;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. namespace Server
  22. {
  23. public static class CConsole
  24. {
  25. // Info, Alert, Warning
  26. private static readonly object locker = new object();
  27. private static readonly bool enabled = true;
  28. static CConsole()
  29. {
  30. try
  31. {
  32. Console.BackgroundColor = ConsoleColor.White;
  33. Console.ForegroundColor = ConsoleColor.Black;
  34. Console.ResetColor();
  35. }
  36. catch
  37. {
  38. // ArgumentException, SecurityException, IOException.
  39. enabled = false;
  40. }
  41. }
  42. private static void ColorConsole(Action consoleAction, ConsoleColor foreground)
  43. {
  44. if (enabled)
  45. {
  46. lock (locker)
  47. {
  48. Console.ForegroundColor = foreground;
  49. consoleAction();
  50. Console.ResetColor();
  51. }
  52. }
  53. else
  54. {
  55. consoleAction();
  56. }
  57. }
  58. private static void ColorConsole(Action consoleAction, ConsoleColor foreground, ConsoleColor background)
  59. {
  60. if (enabled)
  61. {
  62. lock (locker)
  63. {
  64. Console.ForegroundColor = foreground;
  65. Console.BackgroundColor = background;
  66. consoleAction();
  67. Console.ResetColor();
  68. }
  69. }
  70. else
  71. {
  72. consoleAction();
  73. }
  74. }
  75. public static void ColorInfo(Action consoleAction)
  76. {
  77. ColorConsole(consoleAction, ConsoleColor.Cyan);
  78. }
  79. public static void ColorWarning(Action consoleAction)
  80. {
  81. ColorConsole(consoleAction, ConsoleColor.Yellow);
  82. }
  83. public static void ColorAlert(Action consoleAction)
  84. {
  85. ColorConsole(consoleAction, ConsoleColor.Red);
  86. }
  87. }
  88. }