LocalContentLocator.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.IO;
  3. namespace CassiniDev
  4. {
  5. /// <summary>
  6. /// Locates content local to the project, e.g. copy always or deployment item/directory
  7. ///
  8. /// Depending on the runner in question, the content directory may be in any one over several relative locations.
  9. /// Let's just start backing out of the current directory looking for it...
  10. ///
  11. /// For MSTest we added a deployment directory so can find somewhere in the hierarchy /web
  12. /// For NUnit the content will be in /deploy/web right here in /bin/xxx
  13. /// </summary>
  14. public class LocalContentLocator : IContentLocator
  15. {
  16. #region IContentLocator Members
  17. public string LocateContent()
  18. {
  19. var path = Environment.CurrentDirectory;
  20. while (!Directory.Exists(Path.Combine(path + "", "web")) &&
  21. !Directory.Exists(Path.Combine(path + "", @"deploy\web")))
  22. {
  23. path = Path.GetDirectoryName(path);
  24. }
  25. if (Directory.Exists(Path.Combine(path + "", "web")))
  26. {
  27. path = Path.Combine(path + "", "web");
  28. }
  29. else if (Directory.Exists(Path.Combine(path + "", @"deploy\web")))
  30. {
  31. path = Path.Combine(path + "", @"deploy\web");
  32. }
  33. else
  34. {
  35. throw new Exception("could not find content");
  36. }
  37. return path;
  38. }
  39. #endregion
  40. }
  41. }