SMBShareCollection.cs 1.9 KB

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