Ejemplo n.º 1
0
 private void RebuildFileList(FileSystemEventArgs e)
 {
   if (e is RenamedEventArgs)
   {
     int i = _fileList.IndexOf(((RenamedEventArgs)e).OldName);
     _fileList[i] = e.Name;
   }
   else
   {
     switch (e.ChangeType)
     {
       case WatcherChangeTypes.Changed:
         // Need to send event
         int i = _fileList.IndexOf(e.Name);
         _fileList[i] = e.Name;
         break;
       case WatcherChangeTypes.Created:
         _fileList.Add(e.Name);
         break;
       case WatcherChangeTypes.Deleted:
         if (_fileList.Contains(e.Name))
         {
           _fileList.Remove(e.Name);
         }
         break;
       default:
         break;
     }
   }
 }
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;
                }
            }
        }