Example #1
0
        public SyncthingManager(
            ISyncthingProcessRunner processRunner,
            ISyncthingApiClientFactory apiClientFactory,
            ISyncthingEventWatcherFactory eventWatcherFactory,
            ISyncthingConnectionsWatcherFactory connectionsWatcherFactory,
            IFreePortFinder freePortFinder)
        {
            this.StartedTime = DateTime.MinValue;
            this.LastConnectivityEventTime = DateTime.MinValue;

            this.ApiKey = this.GenerateApiKey();

            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.LastConnectivityEventTime = DateTime.UtcNow;
            this.eventWatcher.DeviceDisconnected += (o, e) => this.LastConnectivityEventTime = DateTime.UtcNow;
            this.eventWatcher.ConfigSaved        += (o, e) => this.ReloadConfigDataAsync();
            this.eventWatcher.EventsSkipped      += (o, e) => this.ReloadConfigDataAsync();
            this.eventWatcher.DeviceRejected     += (o, e) => this.OnDeviceRejected(e.DeviceId, e.Address);
            this.eventWatcher.FolderRejected     += (o, e) => this.OnFolderRejected(e.DeviceId, e.FolderId);

            this.connectionsWatcher = connectionsWatcherFactory.CreateConnectionsWatcher(this.apiClient);
            this.connectionsWatcher.TotalConnectionStatsChanged += (o, e) => this.OnTotalConnectionStatsChanged(e.TotalConnectionStats);

            this._folders         = new SyncthingFolderManager(this.apiClient, this.eventWatcher);
            this._devices         = new SyncthingDeviceManager(this.apiClient, this.eventWatcher, this.Capabilities);
            this._transferHistory = new SyncthingTransferHistory(this.eventWatcher, this._folders);
            this._debugFacilities = new SyncthingDebugFacilitiesManager(this.apiClient, this.Capabilities);

            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();
        }
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.LastConnectivityEventTime = DateTime.UtcNow;
            this.eventWatcher.DeviceDisconnected += (o, e) => this.LastConnectivityEventTime = DateTime.UtcNow;
            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._devices = new SyncthingDeviceManager(this.apiClient, this.eventWatcher, this.Capabilities);
            this._transferHistory = new SyncthingTransferHistory(this.eventWatcher, this._folders);
            this._debugFacilities = new SyncthingDebugFacilitiesManager(this.apiClient, this.Capabilities);

            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();
        }