コード例 #1
0
        private void WriteChange(FileSystemEventArgs objIn, NotifyFilters filters)
        {
            if (objIn != null)
            {
                if (IsInvalidFile(objIn.FullPath))
                {
                    return;
                }

                // If we are gathering extended details LastAccess times aren't meaningful since we
                // will trigger them Instead we note they are gathered and clean up in StopRun
                if (!options.FileNamesOnly && filters.HasFlag(NotifyFilters.LastAccess))
                {
                    filesAccessed.TryAdd(objIn.FullPath, objIn);
                }
                else
                {
                    // We skip gathering extended information when The File was Deleted We are set
                    // to gather names only
                    var fso     = (objIn.ChangeType == WatcherChangeTypes.Deleted || options.FileNamesOnly) ? null : fsc.FilePathToFileSystemObject(objIn.FullPath);
                    var ToWrite = new FileMonitorObject(objIn.FullPath)
                    {
                        ResultType       = RESULT_TYPE.FILEMONITOR,
                        ChangeType       = ChangeTypeStringToChangeType(objIn.ChangeType.ToString()),
                        Name             = objIn.Name,
                        Timestamp        = DateTime.Now.ToString("O", CultureInfo.InvariantCulture),
                        FileSystemObject = fso,
                        NotifyFilters    = filters
                    };

                    changeHandler(ToWrite);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// By default existing files and directories will be added. You can change this behaviour by overriding this method.
        /// This depends on the use of <see cref="NotifyFilters"/> though.
        ///
        /// If you need, you can recognize the manual files added as they'll be of type <see cref="ManualFileSystemEventArgs"/>.
        /// </summary>
        protected virtual void AddManualFileSystemEventArgs(DirectoryInfo path, string filter, bool includeSubDirectories, NotifyFilters notifyFilters, Action <ManualFileSystemEventArgs> adder)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (adder == null)
            {
                throw new ArgumentNullException(nameof(adder));
            }

            foreach (
                FileSystemInfo info in
                path.EnumerateFileSystemInfos(filter,
                                              includeSubDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
            {
                bool isDirectory          = info.Attributes.HasFlag(FileAttributes.Directory);
                bool monitorDirectoryName = notifyFilters.HasFlag(NotifyFilters.DirectoryName);

                if (isDirectory)
                {
                    if (!monitorDirectoryName)
                    {
                        continue;
                    }
                }
                else
                {
                    bool monitorFileName = notifyFilters.HasFlag(NotifyFilters.FileName);

                    if (!monitorFileName)
                    {
                        continue;
                    }
                }

                adder(new ManualFileSystemEventArgs(
                          WatcherChangeTypes.Created,
                          Path.GetDirectoryName(info.FullName) ?? info.FullName,
                          info.Name));
            }
        }
コード例 #3
0
            private void AddCasesForSingleFilter([NotNull] TestCasesBuilder builder)
            {
                int bitmask = 1;

                NotifyFilters filters = GetUnionForFilters();

                while (filters != 0)
                {
                    var currentFilter = (NotifyFilters)bitmask;

                    if (filters.HasFlag(currentFilter))
                    {
                        builder.Add(currentFilter, GetExpectedTextForFilters(currentFilter));
                        filters &= ~currentFilter;
                    }

                    bitmask = bitmask << 1;
                }
            }