Example #1
0
            public Context(FileChangeWatcher fileChangeWatcher, string directoryFilePath)
            {
                _fileChangeWatcher     = fileChangeWatcher;
                _noOpFileWatchingToken = new FileWatchingToken();

                if (directoryFilePath != null)
                {
                    if (!directoryFilePath.EndsWith("\\"))
                    {
                        directoryFilePath = directoryFilePath + "\\";
                    }

                    _directoryFilePathOpt = directoryFilePath;

                    _fileChangeWatcher.EnqueueWork(
                        service => { ErrorHandler.ThrowOnFailure(service.AdviseDirChange(_directoryFilePathOpt, fWatchSubDir: 1, this, out _directoryWatchCookie)); });
                }
            }
Example #2
0
            public void StopWatchingFile(IFileWatchingToken token)
            {
                var typedToken = token as FileWatchingToken;

                Contract.ThrowIfNull(typedToken, "The token passed did not originate from this service.");

                if (typedToken == _noOpFileWatchingToken)
                {
                    // This file never required a direct file watch, our main subscription covered it.
                    return;
                }

                lock (_gate)
                {
                    Contract.ThrowIfFalse(_activeFileWatchingTokens.Remove(typedToken), "This token was no longer being watched.");
                }

                _fileChangeWatcher.EnqueueWork(service => UnsubscribeFileChangeEventsAsync(service, typedToken));
            }
Example #3
0
            public Context(FileChangeWatcher fileChangeWatcher, string?directoryFilePath)
            {
                _fileChangeWatcher     = fileChangeWatcher;
                _noOpFileWatchingToken = new FileWatchingToken();

                if (directoryFilePath != null)
                {
                    if (!directoryFilePath.EndsWith("\\"))
                    {
                        directoryFilePath += "\\";
                    }

                    _directoryFilePath = directoryFilePath;

                    _fileChangeWatcher.EnqueueWork(
                        async service =>
                    {
                        _directoryWatchCookie = await service.AdviseDirChangeAsync(_directoryFilePath, watchSubdirectories: true, this).ConfigureAwait(false);
                    });
                }
            }