ContentLocator.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.IO;
  3. namespace CassiniDev
  4. {
  5. /// <summary>
  6. /// Walks up from the current execution directory looking for directoryName.
  7. /// This means that we can spin up a server on an arbitrary directory that is a child
  8. /// of any of the current directory's ancestors
  9. /// </summary>
  10. public class ContentLocator : IContentLocator
  11. {
  12. private readonly string _directoryName;
  13. public ContentLocator(string directoryName)
  14. {
  15. _directoryName = directoryName;
  16. }
  17. #region IContentLocator Members
  18. public string LocateContent()
  19. {
  20. var path = Environment.CurrentDirectory;
  21. while (!Directory.Exists(Path.Combine(path + "", _directoryName)))
  22. {
  23. path = Path.GetDirectoryName(path);
  24. }
  25. if (Directory.Exists(Path.Combine(path + "", _directoryName)))
  26. {
  27. path = Path.Combine(path + "", _directoryName);
  28. }
  29. else
  30. {
  31. throw new Exception("could not find content");
  32. }
  33. return path;
  34. }
  35. #endregion
  36. }
  37. }