Example #1
0
        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();
            }
        }
Example #2
0
        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();
        }
        public SyncThingFolderManager(
            SynchronizedTransientWrapper<ISyncThingApiClient> apiClient,
            ISyncThingEventWatcher eventWatcher,
            TimeSpan ignoresFetchTimeout)
        {
            this.eventDispatcher = new SynchronizedEventDispatcher(this);
            this.apiClient = apiClient;
            this.ignoresFetchTimeout = ignoresFetchTimeout;

            this.eventWatcher = eventWatcher;
            this.eventWatcher.SyncStateChanged += (o, e) => this.FolderSyncStateChanged(e);
            this.eventWatcher.ItemStarted += (o, e) => this.ItemStarted(e.Folder, e.Item);
            this.eventWatcher.ItemFinished += (o, e) => this.ItemFinished(e.Folder, e.Item);
        }
        public SyncThingFolderManager(
            SynchronizedTransientWrapper <ISyncThingApiClient> apiClient,
            ISyncThingEventWatcher eventWatcher,
            TimeSpan ignoresFetchTimeout)
        {
            this.eventDispatcher     = new SynchronizedEventDispatcher(this);
            this.apiClient           = apiClient;
            this.ignoresFetchTimeout = ignoresFetchTimeout;

            this.eventWatcher = eventWatcher;
            this.eventWatcher.SyncStateChanged += (o, e) => this.FolderSyncStateChanged(e);
            this.eventWatcher.ItemStarted      += (o, e) => this.ItemStarted(e.Folder, e.Item);
            this.eventWatcher.ItemFinished     += (o, e) => this.ItemFinished(e.Folder, e.Item);
        }
Example #5
0
        public SyncThingTransferHistory(ISyncThingEventWatcher eventWatcher, ISyncThingFolderManager folderManager)
        {
            this.eventDispatcher = new SynchronizedEventDispatcher(this);

            this.eventWatcher  = eventWatcher;
            this.folderManager = folderManager;

            this.eventWatcher.ItemStarted  += this.ItemStarted;
            this.eventWatcher.ItemFinished += this.ItemFinished;
            this.eventWatcher.ItemDownloadProgressChanged += this.ItemDownloadProgressChanged;

            // We can't use the EventWatcher to watch for folder sync state change events: events could be skipped.
            // The folder manager knows how to listen to skipped event notifications, and refresh the folder states appropriately
            this.folderManager.SyncStateChanged += this.SyncStateChanged;
        }
Example #6
0
        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();
        }