public void ComplexTest() { var wtc = new WatchTestClass(2, 0); var watcher = new PathWatcher<WatchTestClass, int>(wtc, w => w.Child.Child.Value); Assert.AreEqual(0, watcher.Value); wtc.Update(42); Assert.AreEqual(42, watcher.Value); int i = 0; int rnd = int.MinValue; int changeCount = 10; int eventCount = 0; watcher.ValueChanged += (sender, args) => { eventCount++; Assert.AreEqual(watcher.Value, rnd); }; for (i = 0; i < changeCount; i++) { rnd = Util.Rnd.Next(); wtc.Update(rnd); Assert.AreEqual(rnd, watcher.Value); } Assert.AreEqual(eventCount, changeCount); WatchTestClass.Check(); }
public void ComplexTest() { var wtc = new WatchTestClass(2, 0); var watcher = new PathWatcher <WatchTestClass, int>(wtc, w => w.Child.Child.Value); Assert.AreEqual(0, watcher.Value); wtc.Update(42); Assert.AreEqual(42, watcher.Value); int i = 0; int rnd = int.MinValue; int changeCount = 10; int eventCount = 0; watcher.ValueChanged += (sender, args) => { eventCount++; Assert.AreEqual(watcher.Value, rnd); }; for (i = 0; i < changeCount; i++) { rnd = Util.Rnd.Next(); wtc.Update(rnd); Assert.AreEqual(rnd, watcher.Value); } Assert.AreEqual(eventCount, changeCount); WatchTestClass.Check(); }
private void TestBase <TChangeType, THandler>( Action <MockWatchableFileSystem> prepareSystem, Action <MockWatchableFileSystem> mockAction, ExceptedChange <TChangeType>[] expectedChanges, Func <PathWatcher, ExceptedChange <TChangeType>, Action, THandler> getHandlerFunc, Action <PathWatcher, string, THandler> watchAction, Action <PathWatcher, string, THandler> unwatchAction) { var mockSystem = new MockWatchableFileSystem(); var watcher = new PathWatcher(mockSystem, mockSystem.WatcherProvider) { Logger = new ConsoleLogger() }; Console.WriteLine("--- First pass ---"); TestPass(); Console.WriteLine("--- Second pass ---"); TestPass(); void TestPass() { prepareSystem?.Invoke(mockSystem); var handled = new bool[expectedChanges.Length]; (string, THandler)[] handlers = expectedChanges.Select((x, i) => (x.WatchedPath, getHandlerFunc(watcher, x, () => handled[i] = true))).ToArray();
public void Watch(string path) { var pathWatcher = new PathWatcher(path, _eventsProcessor.Add); _watchers.Add(path, pathWatcher); pathWatcher.Enable(); _pathPoller.TryStart(); _eventReactor.React(EngineEvent.PathWatchingStarted, path); }
public RawContentLibrary(IGraphicsDeviceService graphicsDeviceService, ILogger logger, string rawRootPath, string cacheRootPath) : base(graphicsDeviceService, logger, Path.Combine(cacheRootPath, "bin")) { Directory.CreateDirectory(cacheRootPath); RawRootPath = rawRootPath; _pathWatcher = new PathWatcher(); // Song files are not valid if we are not using full paths _pipelineManager = new PipelineManager(Path.GetFullPath(RawRootPath), Path.GetFullPath(RootPath), Path.GetFullPath(Path.Combine(cacheRootPath, "obj"))) { CompressContent = true, Profile = GraphicsProfile.HiDef, Platform = TargetPlatform.Windows }; FxCompilerPath = ResolveFxCompilerPath(); }
public SharedWatcher(string uniquePath, PathWatcher pathWatcher) { UniquePath = uniquePath; PathWatcher = pathWatcher; string folderPath = FileSystem.GetFolderPath(uniquePath); if (folderPath == null) { throw new InvalidOperationException(); } FolderPath = FileSystem.UniqueFolder(folderPath); _parentWatcher = PathWatcher.GetSharedWatcher(FolderPath); TryGetInternalWatcher(); StartWatchFolder(); StartWatchParentFolder(); }