PascalCoinServer.dpr 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. program PascalCoinServer;
  2. {$APPTYPE CONSOLE}
  3. uses
  4. SysUtils,
  5. SyncObjs,
  6. UAES in 'Units\Utils\UAES.pas',
  7. UJSONFunctions in 'Units\Utils\UJSONFunctions.pas',
  8. UCrypto in 'Units\PascalCoin\UCrypto.pas',
  9. UAccounts in 'Units\PascalCoin\UAccounts.pas',
  10. UConst in 'Units\PascalCoin\UConst.pas',
  11. UThread in 'Units\PascalCoin\UThread.pas',
  12. ULog in 'Units\PascalCoin\ULog.pas',
  13. UServerApp in 'Units\PascalCoin\UServerApp.pas';
  14. type
  15. TOutputLogger = class
  16. protected
  17. FLock : TCriticalSection;
  18. procedure ServerAppLog(LogType: TPascalCoinServerLogType;
  19. Msg: String; Level: Integer);
  20. public
  21. constructor Create;
  22. destructor Destroy; override;
  23. end;
  24. constructor TOutputLogger.Create;
  25. begin
  26. inherited Create;
  27. FLock := TCriticalSection.Create;
  28. end;
  29. destructor TOutputLogger.Destroy;
  30. begin
  31. FreeAndNil(FLock);
  32. inherited Destroy;
  33. end;
  34. procedure TOutputLogger.ServerAppLog(LogType: TPascalCoinServerLogType;
  35. Msg: String; Level: Integer);
  36. var
  37. M : String;
  38. begin
  39. FLock.Acquire;
  40. try
  41. M := FormatDateTime('hhnnss.zzz', Now) + ' ' + Msg;
  42. Writeln(M);
  43. finally
  44. FLock.Release;
  45. end;
  46. end;
  47. var
  48. OutputLogger : TOutputLogger = nil;
  49. begin
  50. try
  51. OutputLogger := TOutputLogger.Create;
  52. try
  53. ServerApp := TPascalCoinServerApp.Create;
  54. try
  55. ServerApp.OnLog := OutputLogger.ServerAppLog;
  56. ServerApp.Init;
  57. ServerApp.Run;
  58. ServerApp.Stop;
  59. finally
  60. FreeAndNil(ServerApp);
  61. end;
  62. finally
  63. FreeAndNil(OutputLogger);
  64. end;
  65. except
  66. on E: Exception do
  67. Writeln('Fatal error:', E.ClassName, ': ', E.Message);
  68. end;
  69. end.