ServerInfoSetting.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using Vinno.FIS.Sonopost.Common;
  3. namespace Vinno.FIS.Sonopost.Settings.Config
  4. {
  5. internal class ServerInfoSetting
  6. {
  7. private string _displayName;
  8. /// <summary>
  9. /// Gets or sets the host.
  10. /// </summary>
  11. public string Host { get; set; }
  12. /// <summary>
  13. /// Gets or sets the server port.
  14. /// </summary>
  15. public int Port { get; set; }
  16. /// <summary>
  17. /// Gets the value to indicate whether the server is FIS default server or custom server.
  18. /// </summary>
  19. public bool IsDefault { get; }
  20. /// <summary>
  21. /// Gets the value to indicate DisplayName,if is default,the displayName is Flyinsono Server else is host:port
  22. /// </summary>
  23. public string DisplayName => _displayName;
  24. public ServerInfoSetting(string host, int port, bool isDefault = false, string displayName = "")
  25. {
  26. Host = host;
  27. Port = port;
  28. IsDefault = isDefault;
  29. if (string.IsNullOrEmpty(displayName))
  30. {
  31. if (isDefault)
  32. {
  33. if (string.Equals($"{host}:{port}", SonopostConstants.OldChinaServer, StringComparison.OrdinalIgnoreCase) || string.Equals($"{host}:{port}", SonopostConstants.NewChinaServer, StringComparison.OrdinalIgnoreCase))
  34. {
  35. _displayName = SonopostConstants.ChinaServerName;
  36. }
  37. else if (string.Equals($"{host}:{port}", SonopostConstants.OldGermanyServer, StringComparison.OrdinalIgnoreCase) || string.Equals($"{host}:{port}", SonopostConstants.NewGermanyServer, StringComparison.OrdinalIgnoreCase))
  38. {
  39. _displayName = SonopostConstants.GermanyServerName;
  40. }
  41. else if (string.Equals($"{host}:{port}", SonopostConstants.OldHongkongServer, StringComparison.OrdinalIgnoreCase) || string.Equals($"{host}:{port}", SonopostConstants.NewHongkongServer, StringComparison.OrdinalIgnoreCase))
  42. {
  43. _displayName = SonopostConstants.HongkongServerName;
  44. }
  45. else
  46. {
  47. _displayName = $"{host}:{port}";
  48. }
  49. }
  50. else
  51. {
  52. _displayName = $"{host}:{port}";
  53. }
  54. }
  55. else
  56. {
  57. _displayName = displayName;
  58. }
  59. }
  60. public override string ToString()
  61. {
  62. return $"{Host}:{Port}";
  63. }
  64. }
  65. }