示例#1
0
        /// <summary>
        /// Throws <see cref="ApplicationException"/> if <see cref="Change.Path"/> and / or <see cref="Change.OldPath"/>
        /// properties have incorrect values.
        ///
        /// The performance of this check is same as <see cref="Directory.Exists"/>
        /// </summary>
        /// <exception cref="ApplicationException"></exception>
        public void ThrowIfIncorrectPath(Change change)
        {
            if (change.FileSystemWatcher == null)
            {
                return;
            }

            lock (_sync)
            {
                if (!_initialWatchPaths.TryGetValue(change.FileSystemWatcher, out var expectedPath))
                {
                    return;
                }

                string actualPath = WatcherPathInspector.GetActualPath(change.FileSystemWatcher);

                if (PathString.Comparer.Equals(expectedPath, actualPath))
                {
                    return;
                }

                throw new ApplicationException(new StringBuilder()
                                               .AppendLine("Observed directory was moved. Initial path:")
                                               .AppendLine(expectedPath)
                                               .AppendLine()
                                               .AppendLine("Current path:")
                                               .AppendLine(actualPath)
                                               .ToString());
            }
        }
示例#2
0
        private void saveInitialWatchLocation(FileSystemWatcher watcher)
        {
            string initialPath = WatcherPathInspector.GetActualPath(watcher);

            if (String.IsNullOrEmpty(initialPath))
            {
                throw new ApplicationException("Failed to retrieve actual watcher path");
            }

            _initialWatchPaths[watcher] = initialPath;
        }
示例#3
0
        /// <summary>
        /// Returns false if <see cref="Change.Path"/> and / or <see cref="Change.OldPath"/>
        /// properties have incorrect values.
        ///
        /// The performance of this check is same as <see cref="Directory.Exists"/>
        /// </summary>
        public bool IsPathCorrect(WatchTarget target)
        {
            lock (_sync)
            {
                if (!_watchers.TryGetValue(target, out var watcher))
                {
                    return(true);
                }

                string expectedPath = _initialWatchPaths[watcher];
                string actualPath   = WatcherPathInspector.GetActualPath(watcher);

                return(PathString.Comparer.Equals(expectedPath, actualPath));
            }
        }