/// <summary> /// Initializes a new instance of the <see cref="Syncless.Monitor.DTO.FileSystemEvent" /> class for non-rename event, given the specified path, the event change type and the file system change type. /// </summary> /// <param name="path">A <see cref="string" /> specifying the affected path.</param> /// <param name="eventType">A <see cref="Syncless.Monitor.DTO.EventChangeType" /> enum specifying the event change type.</param> /// <param name="fileSystemType">A <see cref="Syncless.Monitor.DTO.FileSystemType" /> enum specifying the file system change type.</param> public FileSystemEvent(string path, EventChangeType eventType, FileSystemType fileSystemType) { this._path = path; this._oldPath = null; this._watchPath = null; this._eventType = eventType; this._fileSystemType = fileSystemType; }
private void UnsubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType) { if (value == null) { return; } lock (_lockObject) { ConditionalWeakTable <object, IWeakEventListener> eventsTable; List <IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; break; case EventChangeType.Collection: eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } IWeakEventListener oldSubscription; if (eventsTable.TryGetValue(value, out oldSubscription)) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); eventsTable.Remove(value); } if (value is ICollection) { List <WeakReference> collectionItems; if (_collectionItems.TryGetValue(value, out collectionItems)) { collectionItems.Clear(); _collectionItems.Remove(value); } } } }
/// <summary> /// Initializes a new instance of the <see cref="Syncless.Monitor.DTO.FolderChangeEvent" /> class for rename event only, given the specified old directory path and new directory path. /// </summary> /// <param name="oldPath">A <see cref="System.IO.DirectoryInfo" /> class specifying the old path.</param> /// <param name="newPath">A <see cref="System.IO.DirectoryInfo" /> class specifying the new path.</param> public FolderChangeEvent(DirectoryInfo oldPath, DirectoryInfo newPath) { this._oldPath = oldPath; this._newPath = newPath; this._event = EventChangeType.RENAMED; }
/// <summary> /// Initializes a new instance of the <see cref="Syncless.Monitor.DTO.FolderChangeEvent" /> class for non-rename event, given the specified directory path and the event change type. /// </summary> /// <param name="oldPath">A <see cref="System.IO.DirectoryInfo" /> class specifying the affected path.</param> /// <param name="e">A <see cref="Syncless.Monitor.DTO.EventChangeType" /> enum specifying the event change type.</param> public FolderChangeEvent(DirectoryInfo oldPath, EventChangeType e) { this._oldPath = oldPath; this._newPath = null; this._event = e; }
private void UnsubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType, ICollection parentCollection) { if (value == null) { return; } lock (_lockObject) { ConditionalWeakTable<object, IWeakEventListener> eventsTable; List<IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; if (parentCollection != null) { List<WeakReference> collectionItems; if (_collectionItems.TryGetValue(parentCollection, out collectionItems)) { // TODO: Consider less costly way to determine this for (var i = 0; i < collectionItems.Count; i++) { if (ReferenceEquals(collectionItems[i].Target, value)) { collectionItems.RemoveAt(i--); break; } } } } break; case EventChangeType.Collection: eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } IWeakEventListener oldSubscription; if (eventsTable != null && eventsTable.TryGetValue(value, out oldSubscription)) { if (oldSubscription != null) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); } eventsTable.Remove(value); } if (value is ICollection) { List<WeakReference> collectionItems; if (_collectionItems.TryGetValue(value, out collectionItems)) { foreach (var item in collectionItems) { if (item.IsAlive) { var actualItem = item.Target; UnsubscribeNotifyChangedEvents(actualItem, parentCollection); } } collectionItems.Clear(); _collectionItems.Remove(value); } } } }
private void SubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType, ICollection parentCollection) { if (value == null) { return; } lock (_lockObject) { ConditionalWeakTable<object, IWeakEventListener> eventsTable; List<IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: if (_weakPropertyChangedListenersTable == null) { _weakPropertyChangedListenersTable = new ConditionalWeakTable<object, IWeakEventListener>(); } if (_weakPropertyChangedListeners == null) { _weakPropertyChangedListeners = new List<IWeakEventListener>(); } eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; break; case EventChangeType.Collection: if (_weakCollectionChangedListenersTable == null) { _weakCollectionChangedListenersTable = new ConditionalWeakTable<object, IWeakEventListener>(); } if (_weakCollectionChangedListeners == null) { _weakCollectionChangedListeners = new List<IWeakEventListener>(); } if (_collectionItems == null) { _collectionItems = new ConditionalWeakTable<object, List<WeakReference>>(); } eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } IWeakEventListener oldSubscription; if (eventsTable != null && eventsTable.TryGetValue(value, out oldSubscription)) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); eventsTable.Remove(value); } IWeakEventListener weakListener; switch (eventChangeType) { case EventChangeType.Property: if (parentCollection != null) { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectCollectionItemPropertyChanged, false); if (weakListener == null) { Log.Debug("Failed to use weak events to subscribe to 'value.PropertyChanged', going to subscribe without weak events"); ((INotifyPropertyChanged) value).PropertyChanged += OnObjectCollectionItemPropertyChanged; } var collectionItems = _collectionItems.GetOrCreateValue(parentCollection); collectionItems.Add(weakListener != null ? weakListener.SourceWeakReference : new WeakReference(value)); } else { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectPropertyChanged, false); if (weakListener == null) { Log.Debug("Failed to use weak events to subscribe to 'value.PropertyChanged', going to subscribe without weak events"); ((INotifyPropertyChanged)value).PropertyChanged += OnObjectPropertyChanged; } } break; case EventChangeType.Collection: weakListener = this.SubscribeToWeakCollectionChangedEvent(value, OnObjectCollectionChanged, false); if (weakListener == null) { Log.Debug("Failed to use weak events to subscribe to 'value.CollectionChanged', going to subscribe without weak events"); ((INotifyCollectionChanged)value).CollectionChanged += OnObjectCollectionChanged; } break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } if (eventsTable != null) { eventsTable.Add(value, weakListener); } if (eventsList != null) { eventsList.Add(weakListener); } } }
private void UnsubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType) { if (value == null) { return; } ConditionalWeakTable<object, IWeakEventListener> eventsTable; List<IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; break; case EventChangeType.Collection: eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } lock (_lockObject) { IWeakEventListener oldSubscription; if (eventsTable.TryGetValue(value, out oldSubscription)) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); eventsTable.Remove(value); } } }
private void SubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType, bool isCollectionItem) { if (value == null) { return; } ConditionalWeakTable<object, IWeakEventListener> eventsTable; List<IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: if (_weakPropertyChangedListenersTable == null) { _weakPropertyChangedListenersTable = new ConditionalWeakTable<object, IWeakEventListener>(); } if (_weakPropertyChangedListeners == null) { _weakPropertyChangedListeners = new List<IWeakEventListener>(); } eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; break; case EventChangeType.Collection: if (_weakCollectionChangedListenersTable == null) { _weakCollectionChangedListenersTable = new ConditionalWeakTable<object, IWeakEventListener>(); } if (_weakCollectionChangedListeners == null) { _weakCollectionChangedListeners = new List<IWeakEventListener>(); } eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } lock (_lockObject) { IWeakEventListener oldSubscription; if (eventsTable.TryGetValue(value, out oldSubscription)) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); eventsTable.Remove(value); } IWeakEventListener weakListener; switch (eventChangeType) { case EventChangeType.Property: if (isCollectionItem) { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectCollectionItemPropertyChanged); } else { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectPropertyChanged); } break; case EventChangeType.Collection: weakListener = this.SubscribeToWeakCollectionChangedEvent(value, OnObjectCollectionChanged); break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } eventsTable.Add(value, weakListener); eventsList.Add(weakListener); } }
private void SubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType, bool isCollectionItem) { if (value == null) { return; } lock (_lockObject) { ConditionalWeakTable <object, IWeakEventListener> eventsTable; List <IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: if (_weakPropertyChangedListenersTable == null) { _weakPropertyChangedListenersTable = new ConditionalWeakTable <object, IWeakEventListener>(); } if (_weakPropertyChangedListeners == null) { _weakPropertyChangedListeners = new List <IWeakEventListener>(); } eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; break; case EventChangeType.Collection: if (_weakCollectionChangedListenersTable == null) { _weakCollectionChangedListenersTable = new ConditionalWeakTable <object, IWeakEventListener>(); } if (_weakCollectionChangedListeners == null) { _weakCollectionChangedListeners = new List <IWeakEventListener>(); } if (_collectionItems == null) { _collectionItems = new ConditionalWeakTable <object, List <WeakReference> >(); } eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } IWeakEventListener oldSubscription; if (eventsTable.TryGetValue(value, out oldSubscription)) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); eventsTable.Remove(value); } IWeakEventListener weakListener; switch (eventChangeType) { case EventChangeType.Property: if (isCollectionItem) { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectCollectionItemPropertyChanged); } else { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectPropertyChanged); } break; case EventChangeType.Collection: weakListener = this.SubscribeToWeakCollectionChangedEvent(value, OnObjectCollectionChanged); var collection = value as ICollection; if (collection != null) { var collectionItems = new List <WeakReference>(); foreach (var item in collection) { collectionItems.Add(new WeakReference(item)); } _collectionItems.Add(value, collectionItems); } break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } eventsTable.Add(value, weakListener); eventsList.Add(weakListener); } }
private void UnsubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType, ICollection parentCollection) { if (value == null) { return; } lock (_lockObject) { ConditionalWeakTable <object, IWeakEventListener> eventsTable; List <IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; if (parentCollection != null) { List <WeakReference> collectionItems; if (_collectionItems.TryGetValue(parentCollection, out collectionItems)) { // TODO: Consider less costly way to determine this for (var i = 0; i < collectionItems.Count; i++) { if (ReferenceEquals(collectionItems[i].Target, value)) { collectionItems.RemoveAt(i--); break; } } } } break; case EventChangeType.Collection: eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } IWeakEventListener oldSubscription; if (eventsTable != null && eventsTable.TryGetValue(value, out oldSubscription)) { if (oldSubscription != null) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); } eventsTable.Remove(value); } if (value is ICollection) { List <WeakReference> collectionItems; if (_collectionItems.TryGetValue(value, out collectionItems)) { foreach (var item in collectionItems) { if (item.IsAlive) { var actualItem = item.Target; UnsubscribeNotifyChangedEvents(actualItem, parentCollection); } } collectionItems.Clear(); _collectionItems.Remove(value); } } } }
private void SubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType, ICollection parentCollection) { if (value == null) { return; } lock (_lockObject) { ConditionalWeakTable <object, IWeakEventListener> eventsTable; List <IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: if (_weakPropertyChangedListenersTable == null) { _weakPropertyChangedListenersTable = new ConditionalWeakTable <object, IWeakEventListener>(); } if (_weakPropertyChangedListeners == null) { _weakPropertyChangedListeners = new List <IWeakEventListener>(); } eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; break; case EventChangeType.Collection: if (_weakCollectionChangedListenersTable == null) { _weakCollectionChangedListenersTable = new ConditionalWeakTable <object, IWeakEventListener>(); } if (_weakCollectionChangedListeners == null) { _weakCollectionChangedListeners = new List <IWeakEventListener>(); } if (_collectionItems == null) { _collectionItems = new ConditionalWeakTable <object, List <WeakReference> >(); } eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } IWeakEventListener oldSubscription; if (eventsTable != null && eventsTable.TryGetValue(value, out oldSubscription)) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); eventsTable.Remove(value); } IWeakEventListener weakListener; switch (eventChangeType) { case EventChangeType.Property: if (parentCollection != null) { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectCollectionItemPropertyChanged, false); if (weakListener == null) { Log.Debug("Failed to use weak events to subscribe to 'value.PropertyChanged', going to subscribe without weak events"); ((INotifyPropertyChanged)value).PropertyChanged += OnObjectCollectionItemPropertyChanged; } var collectionItems = _collectionItems.GetOrCreateValue(parentCollection); collectionItems.Add(weakListener != null ? weakListener.SourceWeakReference : new WeakReference(value)); } else { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectPropertyChanged, false); if (weakListener == null) { Log.Debug("Failed to use weak events to subscribe to 'value.PropertyChanged', going to subscribe without weak events"); ((INotifyPropertyChanged)value).PropertyChanged += OnObjectPropertyChanged; } } break; case EventChangeType.Collection: weakListener = this.SubscribeToWeakCollectionChangedEvent(value, OnObjectCollectionChanged, false); if (weakListener == null) { Log.Debug("Failed to use weak events to subscribe to 'value.CollectionChanged', going to subscribe without weak events"); ((INotifyCollectionChanged)value).CollectionChanged += OnObjectCollectionChanged; } break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } if (eventsTable != null) { eventsTable.Add(value, weakListener); } if (eventsList != null) { eventsList.Add(weakListener); } } }
private void SubscribeNotifyChangedEvent(object value, EventChangeType eventChangeType, bool isCollectionItem) { if (value == null) { return; } ConditionalWeakTable <object, IWeakEventListener> eventsTable; List <IWeakEventListener> eventsList; switch (eventChangeType) { case EventChangeType.Property: eventsTable = _weakPropertyChangedListenersTable; eventsList = _weakPropertyChangedListeners; break; case EventChangeType.Collection: eventsTable = _weakCollectionChangedListenersTable; eventsList = _weakCollectionChangedListeners; break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } lock (_lockObject) { IWeakEventListener oldSubscription; if (eventsTable.TryGetValue(value, out oldSubscription)) { oldSubscription.Detach(); eventsList.Remove(oldSubscription); eventsTable.Remove(value); } IWeakEventListener weakListener; switch (eventChangeType) { case EventChangeType.Property: if (isCollectionItem) { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectCollectionItemPropertyChanged); } else { weakListener = this.SubscribeToWeakPropertyChangedEvent(value, OnObjectPropertyChanged); } break; case EventChangeType.Collection: weakListener = this.SubscribeToWeakCollectionChangedEvent(value, OnObjectCollectionChanged); break; default: throw new ArgumentOutOfRangeException("eventChangeType"); } eventsTable.Add(value, weakListener); eventsList.Add(weakListener); } }
/// <summary> /// Initializes a new instance of the <see cref="Syncless.Monitor.DTO.FileChangeEvent" /> class for rename event only, given the specified old file path and new file path. /// </summary> /// <param name="oldPath">A <see cref="System.IO.FileInfo" /> class specifying the old path.</param> /// <param name="newPath">A <see cref="System.IO.FileInfo" /> class specifying the new path.</param> public FileChangeEvent(FileInfo oldPath, FileInfo newPath) { this._oldPath = oldPath; this._newPath = newPath; this._event = EventChangeType.RENAMED; }
/// <summary> /// Initializes a new instance of the <see cref="Syncless.Monitor.DTO.FileChangeEvent" /> class for non-rename event, given the specified file path and the event change type. /// </summary> /// <param name="oldPath">A <see cref="System.IO.FileInfo" /> class specifying the affected path.</param> /// <param name="e">A <see cref="Syncless.Monitor.DTO.EventChangeType" /> enum specifying the event change type.</param> public FileChangeEvent(FileInfo oldPath, EventChangeType e) { this._oldPath = oldPath; this._newPath = null; this._event = e; }
/// <summary> /// Initializes a new instance of the <see cref="Syncless.Monitor.DTO.FileSystemEvent" /> class for delete event with unknown file system type only, given the affected path and the path being monitored. /// </summary> /// <param name="path">A <see cref="string" /> specifying the affected path.</param> /// <param name="watchPath">A <see cref="string" /> specifying the path being monitored.</param> public FileSystemEvent(string path, string watchPath) { this._path = path; this._oldPath = null; this._watchPath = watchPath; this._eventType = EventChangeType.DELETED; this._fileSystemType = FileSystemType.UNKNOWN; }
/// <summary> /// Initializes a new instance of the <see cref="Syncless.Monitor.DTO.FileSystemEvent" /> class for rename event only, given the old path, the new path and the file system change type. /// </summary> /// <param name="oldPath">A <see cref="string" /> class specifying the old path.</param> /// <param name="newPath">A <see cref="string" /> class specifying the new path.</param> /// <param name="fileSystemType">A <see cref="Syncless.Monitor.DTO.FileSystemType" /> enum specifying the file system change type.</param> public FileSystemEvent(string oldPath, string newPath, FileSystemType fileSystemType) { this._oldPath = oldPath; this._path = newPath; this._watchPath = null; this._eventType = EventChangeType.RENAMED; this._fileSystemType = fileSystemType; }