Example #1
0
 protected override void OnParentUpdated(object sender, DirectoryItemUpdatedEventArgs e)
 {
     // If the parent path changes (i.e folder rename?),
     // or its existence changes, it effects us so we need to notify subscribers we have been affected!
     if ((e.OldItem.Path != e.NewItem.Path))
     {
         var oldItem = new FileDirectoryItem(this.FileInfo, e.OldItem as IFolderDirectoryItem, false);
         OnRaiseItemUpdated(oldItem);
     }
 }
Example #2
0
        protected virtual void OnRaiseItemUpdated(DirectoryItemUpdatedEventArgs args)
        {
            // Only raise the event if the old or new item (i.e file or folder could have been renamed)
            // matches a pattern.
            var newItemMatches = GetMatchingFilters(args.NewItem.Path).ToArray();
            var oldItemMatches = GetMatchingFilters(args.OldItem.Path).ToArray();
            var unionMatches   = newItemMatches.Union(oldItemMatches).ToArray();

            if (unionMatches.Length > 0)
            {
                var watcherArgs = new DirectoryWatcherFilterMatchedEventArgs <DirectoryItemUpdatedEventArgs>(args, unionMatches);
                EventHandler <DirectoryWatcherFilterMatchedEventArgs <DirectoryItemUpdatedEventArgs> > handler = ItemUpdated;
                handler?.Invoke(this, watcherArgs);
            }
            ;
        }
Example #3
0
        // public event EventHandler<DirectoryItemDeletedEventArgs> ItemDeleted;

        #endregion

        protected void OnRaiseItemUpdated(IDirectoryItem oldItem)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler <DirectoryItemUpdatedEventArgs> handler = Updated;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                var args = new DirectoryItemUpdatedEventArgs(oldItem, this);

                // Use the () operator to raise the event.
                handler(this, args);
            }
        }
Example #4
0
 /// <summary>
 /// Handles an item being updated.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Item_Updated(object sender, DirectoryItemUpdatedEventArgs e)
 {
     // either file change, or folder rename.
     // no need to register / unregister.
     OnRaiseItemUpdated(e);
 }
Example #5
0
 protected abstract void OnParentUpdated(object sender, DirectoryItemUpdatedEventArgs e);