/// <summary> /// Constructs the window resource service. /// </summary> /// <param name="physicalBasePath">The physical base path of th application.</param> /// <param name="resourceSubFolder">The subfolder in which the application paths live.</param> /// <param name="assemblyRootPaths">The root paths.</param> /// <param name="pathInterpreters">The <see cref="IEnumerable{T}"/>s.</param> /// <param name="cachingService">The <see cref="ICachingService"/>.</param> public WindowsApplicationResourceService(string physicalBasePath, string resourceSubFolder, IEnumerable<string> assemblyRootPaths, IEnumerable<ResourcePathInterpreter> pathInterpreters, ICachingService cachingService) { // validate arguments if (string.IsNullOrEmpty(physicalBasePath)) throw new ArgumentNullException("physicalBasePath"); if (assemblyRootPaths == null) throw new ArgumentNullException("assemblyRootPaths"); if (pathInterpreters == null) throw new ArgumentNullException("pathInterpreters"); if (cachingService == null) throw new ArgumentNullException("cachingService"); // get the directory info var physicalBaseDirectory = new DirectoryInfo(physicalBasePath); if (!physicalBaseDirectory.Exists) throw new InvalidOperationException(string.Format("Physical path '{0}' does not exist", physicalBasePath)); // set the values this.physicalBasePath = physicalBaseDirectory.FullName; this.pathInterpreters = pathInterpreters; foreach (var rootPath in assemblyRootPaths.Select(rootPath => rootPath.Trim(new[] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}))) { // make sure the path is only added once if (rootPaths.Contains(rootPath)) throw new InvalidOperationException(string.Format("The root path '{0}' is already added", rootPath)); // make sure the directoy exists var rootPathDirectory = Path.Combine(physicalBasePath, Path.Combine(rootPath, resourceSubFolder)); if (!Directory.Exists(rootPathDirectory)) throw new InvalidOperationException(string.Format("Resource path '{0}' does not exist", rootPathDirectory)); // add the root path rootPaths.Add(rootPathDirectory); rootPathsReverse.Insert(0, rootPathDirectory); } // add file system watchers foreach (var watcher in rootPaths.Select(rootPath => new FileSystemWatcher(rootPath) { EnableRaisingEvents = true, IncludeSubdirectories = true })) { watcher.Changed += (sender, e) => { // clear the cache when this object is not yet disposed if (IsNotDisposed) cachingService.ClearAll(); }; watchers.Add(watcher); } }