Subsystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Text.RegularExpressions;
  2. namespace Renci.SshNet.TestTools.OpenSSH
  3. {
  4. public class Subsystem
  5. {
  6. public Subsystem(string name, string command)
  7. {
  8. Name = name;
  9. Command = command;
  10. }
  11. public string Name { get; }
  12. public string Command { get; set; }
  13. public void WriteTo(TextWriter writer)
  14. {
  15. writer.WriteLine(Name + "=" + Command);
  16. }
  17. public static Subsystem FromConfig(string value)
  18. {
  19. var subSystemValueRegex = new Regex(@"^\s*(?<name>[\S]+)\s+(?<command>.+?){1}\s*$");
  20. var match = subSystemValueRegex.Match(value);
  21. if (match.Success)
  22. {
  23. var nameGroup = match.Groups["name"];
  24. var commandGroup = match.Groups["command"];
  25. var name = nameGroup.Value;
  26. var command = commandGroup.Value;
  27. return new Subsystem(name, command);
  28. }
  29. throw new Exception($"'{value}' not recognized as value for Subsystem.");
  30. }
  31. }
  32. }