DatabaseProxyEngine.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. protected IRpcClientTransport ServerTransport { get; set; }
  15. public override void Run()
  16. {
  17. Logger.Send(LogType.Information, "", "Starting..");
  18. if (string.IsNullOrWhiteSpace(Properties.Server))
  19. {
  20. Logger.Send(LogType.Error, "", "Server is blank!");
  21. return;
  22. }
  23. ServerTransport = new RpcClientPipeTransport(DatabaseServerProperties.GetProxyName(Properties.Server));
  24. CheckConnection();
  25. RunProxy();
  26. }
  27. protected abstract void RunProxy();
  28. private void CheckConnection()
  29. {
  30. // Wait for server connection
  31. ServerTransport.Connect();
  32. while (!ServerTransport.IsConnected())
  33. {
  34. Logger.Send(LogType.Error, "", "Database server unavailable. Trying again in 30 seconds...");
  35. Task.Delay(30_000).Wait();
  36. Logger.Send(LogType.Information, "", "Retrying connection...");
  37. }
  38. }
  39. }