ShareCollection.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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);
  18. share.ReadAccess = readAccess;
  19. share.WriteAccess = writeAccess;
  20. share.FileSystem = fileSystem;
  21. this.Add(share);
  22. }
  23. public bool Contains(string shareName, StringComparison comparisonType)
  24. {
  25. return (this.IndexOf(shareName, comparisonType) != -1);
  26. }
  27. public int IndexOf(string shareName, StringComparison comparisonType)
  28. {
  29. for (int index = 0; index < this.Count; index++)
  30. {
  31. if (this[index].Name.Equals(shareName, comparisonType))
  32. {
  33. return index;
  34. }
  35. }
  36. return -1;
  37. }
  38. public List<string> ListShares()
  39. {
  40. List<string> result = new List<string>();
  41. foreach (FileSystemShare share in this)
  42. {
  43. result.Add(share.Name);
  44. }
  45. return result;
  46. }
  47. /// <param name="relativePath">e.g. \Shared</param>
  48. public FileSystemShare GetShareFromName(string shareName)
  49. {
  50. int index = IndexOf(shareName, StringComparison.InvariantCultureIgnoreCase);
  51. if (index >= 0)
  52. {
  53. return this[index];
  54. }
  55. else
  56. {
  57. return null;
  58. }
  59. }
  60. }
  61. }