private string FormatEvent(ShellObjectChangeTypes changeType, ShellObjectNotificationEventArgs args) { ShellObjectChangedEventArgs changeArgs; ShellObjectRenamedEventArgs renameArgs; SystemImageUpdatedEventArgs imageArgs; string msg; if ((renameArgs = args as ShellObjectRenamedEventArgs) != null) { msg = string.Format("{0}: {1} ==> {2}", changeType, renameArgs.Path, System.IO.Path.GetFileName(renameArgs.NewPath)); } else if ((changeArgs = args as ShellObjectChangedEventArgs) != null) { msg = string.Format("{0}: {1}", changeType, changeArgs.Path); } else if ((imageArgs = args as SystemImageUpdatedEventArgs) != null) { msg = string.Format("{0}: ImageUpdated ==> {1}", changeType, imageArgs.ImageIndex); } else { msg = args.ChangeType.ToString(); } return msg; }
/// <summary> /// Processes all change notifications sent by the Windows Shell. /// </summary> /// <param name="e">The windows message representing the notification event</param> protected virtual void ProcessChangeNotificationEvent(WindowMessageEventArgs e) { if (!Running) { return; } if (e == null) { throw new ArgumentNullException(nameof(e)); } ChangeNotifyLock notifyLock = new ChangeNotifyLock(e.Message); ShellObjectNotificationEventArgs args = null; switch (notifyLock.ChangeType) { case ShellObjectChangeTypes.DirectoryRename: case ShellObjectChangeTypes.ItemRename: args = new ShellObjectRenamedEventArgs(notifyLock); break; case ShellObjectChangeTypes.SystemImageUpdate: args = new SystemImageUpdatedEventArgs(notifyLock); break; default: args = new ShellObjectChangedEventArgs(notifyLock); break; } _manager.Invoke(this, notifyLock.ChangeType, args); }
void AllEventsHandler(object sender, ShellObjectNotificationEventArgs e) { eventStack.Children.Add( new Label() { Content = FormatEvent(e.ChangeType, e) }); }