ServerProperties.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using InABox.Core;
  4. using PRSClasses;
  5. namespace PRSServer
  6. {
  7. public abstract class ServerProperties : BaseObject
  8. {
  9. [TextBoxEditor]
  10. [Caption("Service Account Username")]
  11. [EditorSequence("Advanced",999)]
  12. public string Username { get; set; }
  13. public ServerProperties()
  14. {
  15. Name = CoreUtils.Neatify(Type().ToString());
  16. }
  17. [TextBoxEditor]
  18. [EditorSequence(-1)]
  19. public string Name { get; set; }
  20. public abstract ServerType Type();
  21. public List<string> CommandLineOptions(params string[] extras)
  22. {
  23. var options = new List<string>();
  24. var props = CoreUtils.PropertyList(
  25. GetType(),
  26. x => x.GetEditor() != null
  27. && (x.DeclaringType == typeof(ServerProperties) || x.DeclaringType.IsSubclassOf(typeof(ServerProperties))
  28. )
  29. ).OrderBy(x => x.GetSequence());
  30. foreach (var prop in props)
  31. options.Add(
  32. string.Format(
  33. "/{0}={1}{2}{1}",
  34. prop.Name,
  35. prop.PropertyType == typeof(string) ? "\"" : "",
  36. prop.GetValue(this)
  37. )
  38. );
  39. foreach (var extra in extras)
  40. options.Add(extra);
  41. return options;
  42. }
  43. }
  44. }