private void StartWatchers(CancellationToken cancellationToken) { // This is all synchronous, so it's safe to execute inside the lock lock (this.apiClientsLock) { cancellationToken.ThrowIfCancellationRequested(); if (apiClient == null) { throw new InvalidOperationException("ApiClient must not be null"); } if (this.connectionsWatcher != null) { this.connectionsWatcher.Dispose(); } this.connectionsWatcher = this.connectionsWatcherFactory.CreateConnectionsWatcher(apiClient); this.connectionsWatcher.TotalConnectionStatsChanged += (o, e) => this.OnTotalConnectionStatsChanged(e.TotalConnectionStats); this.connectionsWatcher.Start(); if (this.eventWatcher != null) { this.eventWatcher.Dispose(); } this.eventWatcher = this.eventWatcherFactory.CreateEventWatcher(apiClient); this.eventWatcher.SyncStateChanged += (o, e) => this.OnFolderSyncStateChanged(e); this.eventWatcher.ItemStarted += (o, e) => this.ItemStarted(e.Folder, e.Item); this.eventWatcher.ItemFinished += (o, e) => this.ItemFinished(e.Folder, e.Item); this.eventWatcher.DeviceConnected += (o, e) => this.OnDeviceConnected(e); this.eventWatcher.DeviceDisconnected += (o, e) => this.OnDeviceDisconnected(e); this.eventWatcher.Start(); } }
public SyncThingManager( ISyncThingProcessRunner processRunner, ISyncThingApiClientFactory apiClientFactory, ISyncThingEventWatcherFactory eventWatcherFactory, ISyncThingConnectionsWatcherFactory connectionsWatcherFactory, IFreePortFinder freePortFinder) { this.StartedTime = DateTime.MinValue; this.LastConnectivityEventTime = DateTime.MinValue; this.eventDispatcher = new SynchronizedEventDispatcher(this); this.processRunner = processRunner; this.apiClientFactory = apiClientFactory; this.freePortFinder = freePortFinder; this.apiClient = new SynchronizedTransientWrapper <ISyncThingApiClient>(this.apiClientsLock); this.eventWatcher = eventWatcherFactory.CreateEventWatcher(this.apiClient); this.eventWatcher.DeviceConnected += (o, e) => this.OnDeviceConnected(e); this.eventWatcher.DeviceDisconnected += (o, e) => this.OnDeviceDisconnected(e); this.eventWatcher.ConfigSaved += (o, e) => this.ReloadConfigDataAsync(); this.eventWatcher.EventsSkipped += (o, e) => this.ReloadConfigDataAsync(); this.connectionsWatcher = connectionsWatcherFactory.CreateConnectionsWatcher(this.apiClient); this.connectionsWatcher.TotalConnectionStatsChanged += (o, e) => this.OnTotalConnectionStatsChanged(e.TotalConnectionStats); this._folders = new SyncThingFolderManager(this.apiClient, this.eventWatcher, TimeSpan.FromMinutes(10)); this._transferHistory = new SyncThingTransferHistory(this.eventWatcher, this._folders); this.processRunner.ProcessStopped += (o, e) => this.ProcessStopped(e.ExitStatus); this.processRunner.MessageLogged += (o, e) => this.OnMessageLogged(e.LogMessage); this.processRunner.ProcessRestarted += (o, e) => this.ProcessRestarted(); this.processRunner.Starting += (o, e) => this.ProcessStarting(); }
private void StopApiClients() { lock (this.apiClientsLock) { if (this.apiAbortCts != null) { this.apiAbortCts.Cancel(); } this.apiClient = null; if (this.connectionsWatcher != null) { this.connectionsWatcher.Dispose(); } this.connectionsWatcher = null; if (this.eventWatcher != null) { this.eventWatcher.Dispose(); } this.eventWatcher = null; } }
public SyncThingManager( ISyncThingProcessRunner processRunner, ISyncThingApiClientFactory apiClientFactory, ISyncThingEventWatcherFactory eventWatcherFactory, ISyncThingConnectionsWatcherFactory connectionsWatcherFactory, IFreePortFinder freePortFinder) { this.StartedTime = DateTime.MinValue; this.LastConnectivityEventTime = DateTime.MinValue; this.eventDispatcher = new SynchronizedEventDispatcher(this); this.processRunner = processRunner; this.apiClientFactory = apiClientFactory; this.freePortFinder = freePortFinder; this.apiClient = new SynchronizedTransientWrapper<ISyncThingApiClient>(this.apiClientsLock); this.eventWatcher = eventWatcherFactory.CreateEventWatcher(this.apiClient); this.eventWatcher.DeviceConnected += (o, e) => this.OnDeviceConnected(e); this.eventWatcher.DeviceDisconnected += (o, e) => this.OnDeviceDisconnected(e); this.eventWatcher.ConfigSaved += (o, e) => this.ReloadConfigDataAsync(); this.eventWatcher.EventsSkipped += (o, e) => this.ReloadConfigDataAsync(); this.connectionsWatcher = connectionsWatcherFactory.CreateConnectionsWatcher(this.apiClient); this.connectionsWatcher.TotalConnectionStatsChanged += (o, e) => this.OnTotalConnectionStatsChanged(e.TotalConnectionStats); this._folders = new SyncThingFolderManager(this.apiClient, this.eventWatcher, TimeSpan.FromMinutes(10)); this._transferHistory = new SyncThingTransferHistory(this.eventWatcher, this._folders); this.processRunner.ProcessStopped += (o, e) => this.ProcessStopped(e.ExitStatus); this.processRunner.MessageLogged += (o, e) => this.OnMessageLogged(e.LogMessage); this.processRunner.ProcessRestarted += (o, e) => this.ProcessRestarted(); this.processRunner.Starting += (o, e) => this.ProcessStarting(); }