ShareCollection.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.Server
  12. {
  13. public class ShareCollection : List<FileSystemShare>
  14. {
  15. public void Add(string shareName, List<string> readAccess, List<string> writeAccess, IFileSystem fileSystem)
  16. {
  17. FileSystemShare share = new FileSystemShare(shareName, fileSystem);
  18. share.ReadAccess = readAccess;
  19. share.WriteAccess = writeAccess;
  20. this.Add(share);
  21. }
  22. public bool Contains(string shareName, StringComparison comparisonType)
  23. {
  24. return (this.IndexOf(shareName, comparisonType) != -1);
  25. }
  26. public int IndexOf(string shareName, StringComparison comparisonType)
  27. {
  28. for (int index = 0; index < this.Count; index++)
  29. {
  30. if (this[index].Name.Equals(shareName, comparisonType))
  31. {
  32. return index;
  33. }
  34. }
  35. return -1;
  36. }
  37. public List<string> ListShares()
  38. {
  39. List<string> result = new List<string>();
  40. foreach (FileSystemShare share in this)
  41. {
  42. result.Add(share.Name);
  43. }
  44. return result;
  45. }
  46. /// <param name="relativePath">e.g. \Shared</param>
  47. public FileSystemShare GetShareFromName(string shareName)
  48. {
  49. int index = IndexOf(shareName, StringComparison.InvariantCultureIgnoreCase);
  50. if (index >= 0)
  51. {
  52. return this[index];
  53. }
  54. else
  55. {
  56. return null;
  57. }
  58. }
  59. }
  60. }