DatabaseProxyEngine.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using InABox.Clients;
  2. using InABox.Core;
  3. using InABox.Rpc;
  4. using PRSServices;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace PRSServer;
  11. public abstract class DatabaseProxyEngine<TProperties> : Engine<TProperties>
  12. where TProperties : DatabaseProxyProperties
  13. {
  14. public override void Run()
  15. {
  16. Logger.Send(LogType.Information, "", "Starting..");
  17. if (string.IsNullOrWhiteSpace(Properties.Server))
  18. {
  19. Logger.Send(LogType.Error, "", "Server is blank!");
  20. return;
  21. }
  22. var transport = new RpcClientPipeTransport(DatabaseServerProperties.GetPipeName(Properties.Server, true));
  23. ClientFactory.SetClientType(typeof(RpcClient<>), Platform.LicensingEngine, Version, transport);
  24. CheckConnection();
  25. RunProxy();
  26. }
  27. protected abstract void RunProxy();
  28. private void CheckConnection()
  29. {
  30. // Wait for server connection
  31. while (!Client.Ping())
  32. {
  33. Logger.Send(LogType.Error, "", "Database server unavailable. Trying again in 30 seconds...");
  34. Task.Delay(30_000).Wait();
  35. Logger.Send(LogType.Information, "", "Retrying connection...");
  36. }
  37. ClientFactory.SetBypass();
  38. }
  39. }