2
0

Extensions.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using Renci.SshNet.Common;
  4. using Renci.SshNet.Sftp;
  5. namespace Renci.SshNet.Tests.Common
  6. {
  7. internal static class Extensions
  8. {
  9. public static string AsString(this IList<ExceptionEventArgs> exceptionEvents)
  10. {
  11. if (exceptionEvents.Count == 0)
  12. {
  13. return string.Empty;
  14. }
  15. var reportedExceptions = string.Empty;
  16. foreach (var exceptionEvent in exceptionEvents)
  17. {
  18. reportedExceptions += exceptionEvent.Exception.ToString();
  19. }
  20. return reportedExceptions;
  21. }
  22. public static byte[] Copy(this byte[] buffer)
  23. {
  24. var copy = new byte[buffer.Length];
  25. Buffer.BlockCopy(buffer, 0, copy, 0, buffer.Length);
  26. return copy;
  27. }
  28. /// <summary>
  29. /// Creates a deep clone of the current instance.
  30. /// </summary>
  31. /// <returns>
  32. /// A deep clone of the current instance.
  33. /// </returns>
  34. internal static SftpFileAttributes Clone(this SftpFileAttributes value)
  35. {
  36. Dictionary<string, string> clonedExtensions;
  37. if (value.Extensions != null)
  38. {
  39. clonedExtensions = new Dictionary<string, string>(value.Extensions.Count);
  40. foreach (var entry in value.Extensions)
  41. {
  42. clonedExtensions.Add(entry.Key, entry.Value);
  43. }
  44. }
  45. else
  46. {
  47. clonedExtensions = null;
  48. }
  49. return new SftpFileAttributes(value.LastAccessTimeUtc,
  50. value.LastWriteTimeUtc,
  51. value.Size,
  52. value.UserId,
  53. value.GroupId,
  54. value.Permissions,
  55. clonedExtensions);
  56. }
  57. }
  58. }