2
0

SftpNameResponseBuilder.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using Renci.SshNet.Sftp;
  4. using Renci.SshNet.Sftp.Responses;
  5. namespace Renci.SshNet.Tests.Classes.Sftp
  6. {
  7. internal class SftpNameResponseBuilder
  8. {
  9. private uint _responseId;
  10. private uint _protocolVersion;
  11. private Encoding _encoding;
  12. private readonly List<KeyValuePair<string, SftpFileAttributes>> _files;
  13. public SftpNameResponseBuilder()
  14. {
  15. _files = new List<KeyValuePair<string, SftpFileAttributes>>();
  16. }
  17. public SftpNameResponseBuilder WithProtocolVersion(uint protocolVersion)
  18. {
  19. _protocolVersion = protocolVersion;
  20. return this;
  21. }
  22. public SftpNameResponseBuilder WithResponseId(uint responseId)
  23. {
  24. _responseId = responseId;
  25. return this;
  26. }
  27. public SftpNameResponseBuilder WithFiles(params KeyValuePair<string, SftpFileAttributes>[] files)
  28. {
  29. for (var i = 0; i < files.Length; i++)
  30. {
  31. _files.Add(files[i]);
  32. }
  33. return this;
  34. }
  35. public SftpNameResponseBuilder WithFile(string filename, SftpFileAttributes attributes)
  36. {
  37. _files.Add(new KeyValuePair<string, SftpFileAttributes>(filename, attributes));
  38. return this;
  39. }
  40. public SftpNameResponseBuilder WithEncoding(Encoding encoding)
  41. {
  42. _encoding = encoding;
  43. return this;
  44. }
  45. public SftpNameResponse Build()
  46. {
  47. var sftpNameResponse = new SftpNameResponse(_protocolVersion, _encoding)
  48. {
  49. ResponseId = _responseId,
  50. Files = _files.ToArray()
  51. };
  52. return sftpNameResponse;
  53. }
  54. }
  55. }