/// <summary> /// Gets a replacement for the InternalWatcher /// </summary> /// <returns>A new IWatcher of the same type as the InternalWatcher</returns> private IWatcher GetReplacementWatcher() { IWatcher newInternalWatcher = null; // Swallowing any exceptions that might occure when trying to get a clone of the current watcher CancellationToken cToken = _refreshTokenSource.Token; Policy.Handle <Exception>() .RetryForever((Exception ex, Int32 con) => Thread.Sleep(RefreshAttempInterval)) .Execute(() => { // If the refreshment is cancelled, place a fake as the new watcher and return. if (cToken.IsCancellationRequested) { newInternalWatcher = new FakeWatcher(); return; //Exits polly's 'Execute' method. } newInternalWatcher = (IWatcher)InternalWatcher.Clone(); // setting EnableRaisingEvents to true is where exceptions may raise so // I'm giving this clone a "test drive" before returning it to the Refresh method newInternalWatcher.EnableRaisingEvents = true; newInternalWatcher.EnableRaisingEvents = false; }); return(newInternalWatcher); }
public override Object Clone() { IWatcher clonedInternalWatcher = (IWatcher)InternalWatcher.Clone(); return(new RefreshableWatcher(clonedInternalWatcher) { RefreshAttempInterval = RefreshAttempInterval }); }
public override object Clone() { var clonedInternalWatcher = (IFileSystemWatcher)InternalWatcher.Clone(); return(new FileSystemRefreshableWatcher(clonedInternalWatcher) { RefreshAttempInterval = this.RefreshAttempInterval }); }
private void Dispose(Boolean disposing) { UnsubscribeFromInternalWatcherEvents(); if (disposing) { InternalWatcher.Dispose(); } }
public override object Clone() { IFileSystemWatcher clonedEncapsWatcher = InternalWatcher.Clone() as IFileSystemWatcher; FileSystemAutoRefreshingWatcher clonedAutoRefreshingWatcher = new FileSystemAutoRefreshingWatcher(clonedEncapsWatcher); // Add current refresher's policies to the cloned one clonedAutoRefreshingWatcher.ClearPolicies(); foreach (var policy in _errorHandlingPolicies) { clonedAutoRefreshingWatcher.AddPolicy(policy); } return(clonedAutoRefreshingWatcher); }
/// <summary> /// Refreshes the internal FileSystemWatcher /// </summary> /// <param name="returnWhenRefreshed">In case another thread is alreayd refreshing, determines wether the thread should return before the refreshing thread finishes or not.</param> private void Refresh(Boolean returnWhenRefreshed) { // Making sure another thread isn't already refreshing: if (!Monitor.TryEnter(_refreshLock)) { // if another thread IS already refreshing - wait for it to finish then return if (returnWhenRefreshed) { WaitForRefresh(); } return; } IsRefreshing = true; // 1. unsubscribe from old watcher's events. UnsubscribeFromInternalWatcherEvents(); // 2a. Keeping the current internal "EnableRaisingEvents" value Boolean currentEnableRaisingEvents = InternalWatcher.EnableRaisingEvents; // 2b. Turning off EnableRaisingEvents to avoid "locking" the watched folder InternalWatcher.EnableRaisingEvents = false; // 3. Get a new watcher IWatcher newInternalWatcher = GetReplacementWatcher(); newInternalWatcher.EnableRaisingEvents = currentEnableRaisingEvents; // 4. Disposing of the old watcher InternalWatcher.Dispose(); // 5. Place new watcher in the Internal watcher property // This also registers to the watcher's events InternalWatcher = newInternalWatcher; // Change state back to "not refreshing" IsRefreshing = false; // Notify any waiting threads that the refresh is done foreach (ManualResetEventSlim waitingThreadEvent in _waitingThreadsEvents.Values) { waitingThreadEvent.Set(); } _waitingThreadsEvents.Clear(); Monitor.Exit(_refreshLock); // Notify listeners about the refresh. Refreshed?.Invoke(this, new EventArgs()); }
public override Object Clone() { IWatcher clonedEncapsWatcher = InternalWatcher.Clone() as IWatcher; AutoRefreshingWatcher clonedAutoRefreshingWatcher = new AutoRefreshingWatcher(clonedEncapsWatcher); // Add current refresher's policies to the cloned one clonedAutoRefreshingWatcher.ClearPolicies(); foreach (WatcherErrorHandlingPolicy policy in _errorHandlingPolicies) { clonedAutoRefreshingWatcher.AddPolicy(policy); } return(clonedAutoRefreshingWatcher); }
public override object Clone() { var clonedPoller = (IFileSystemPoller)_poller.Clone(); var clonedEncapsWatcher = (IFileSystemWatcher)InternalWatcher.Clone(); var clonedOverseer = new FileSystemOverseer(clonedPoller, clonedEncapsWatcher) { PollerReportsDelay = this.PollerReportsDelay }; clonedOverseer.ClearPolicies(); foreach (var policy in ErrorHandlingPolicies) { clonedOverseer.AddPolicy(policy); } return(clonedOverseer); }
public override Object Clone() { IPoller clonedPoller = (IPoller)_poller.Clone(); IWatcher clonedEncapsWatcher = (IWatcher)InternalWatcher.Clone(); OverseerWatcher clonedOverseerWatcher = new OverseerWatcher(clonedPoller, clonedEncapsWatcher) { PollerReportsDelay = PollerReportsDelay }; clonedOverseerWatcher.ClearPolicies(); foreach (WatcherErrorHandlingPolicy policy in ErrorHandlingPolicies) { clonedOverseerWatcher.AddPolicy(policy); } return(clonedOverseerWatcher); }
public virtual WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, Int32 timeout) { return(InternalWatcher.WaitForChanged(changeType, timeout)); }
public virtual WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType) { return(InternalWatcher.WaitForChanged(changeType)); }
public WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) { return(InternalWatcher.WaitForChanged(changeType, timeout)); }