Ejemplo n.º 1
0
    // ************************************************************************
    // Public Methods
    // ************************************************************************
    #region Public Methods

    public WatchedRecursiveFileList(DirectoryInfo directory, string fileFilter = "*.3ds")
    {
      if (!directory.Exists)
        directory.Create();

      _fileList = new ConcurrentObservableCollection<string>();
      _fileFilter = fileFilter;
      _watchedDirectoryLocation = directory.FullName;

      _watcher = new FileSystemWatcher(_watchedDirectoryLocation, _fileFilter);
      _watcher.IncludeSubdirectories = true;
      _watcher.Filter = _fileFilter;
      _watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;

      _watcher.Changed += new FileSystemEventHandler(watcher_Changed);
      _watcher.Created += new FileSystemEventHandler(watcher_Changed);
      _watcher.Deleted += new FileSystemEventHandler(watcher_Changed);
      _watcher.Renamed += new RenamedEventHandler(watcher_Renamed);

      _watcher.EnableRaisingEvents = true;

      _fileList.Clear();
      _fileList.Add("");
      BuildFileList(null, "");
    }
Ejemplo n.º 2
0
        private static void ChildToAggregateMapUnmap <T>(this ConcurrentObservableCollection <T> source, ConcurrentObservableCollection <T> dest, MapUnmap mapUnmap)
        {
            NotifyCollectionChangedEventHandler collectionChangedHander = (s, e) =>
            {
                foreach (var item in e?.OldItems?.OfType <T>() ?? Enumerable.Empty <T>())
                {
                    dest.Remove(item);
                }
                foreach (var item in e?.NewItems?.OfType <T>() ?? Enumerable.Empty <T>())
                {
                    dest.Add(item);
                }
            };

            using (var freezeToken = source.FreezeUpdates())
            {
                if (mapUnmap == MapUnmap.Map)
                {
                    dest.AddRange(source);
                    source.CollectionChanged += collectionChangedHander;
                }
                else if (mapUnmap == MapUnmap.Unmap)
                {
                    dest.RemoveRange(source);
                    source.CollectionChanged -= collectionChangedHander;
                }
            }
        }
Ejemplo n.º 3
0
        public static void MapChildListToAggregate <T, K>(this ConcurrentObservableCollection <T> source, ConcurrentObservableCollection <K> dest, Func <T, ConcurrentObservableCollection <K> > selectChildList)
        {
            NotifyCollectionChangedEventHandler collectionChangedHander = (s, e) =>
            {
                foreach (var item in e?.OldItems?.OfType <T>() ?? Enumerable.Empty <T>())
                {
                    selectChildList(item).UnmapChildToAggregate(dest);
                }
                foreach (var item in e?.NewItems?.OfType <T>() ?? Enumerable.Empty <T>())
                {
                    selectChildList(item).MapChildToAggregate(dest);
                }
            };

            using (var freezeToken = source.FreezeUpdates())
            {
                source.CollectionChanged += collectionChangedHander;
                foreach (var item in source)
                {
                    selectChildList(item).MapChildToAggregate(dest);
                }
            }
        }
Ejemplo n.º 4
0
 public static void UnmapChildToAggregate <T>(this ConcurrentObservableCollection <T> source, ConcurrentObservableCollection <T> dest)
 {
     source.ChildToAggregateMapUnmap(dest, MapUnmap.Unmap);
 }