Beispiel #1
0
        private void SetState(SyncthingState state)
        {
            SyncthingState oldState;
            bool           abortApi = false;

            lock (this.stateLock)
            {
                logger.Debug("Request to set state: {0} -> {1}", this._state, state);
                if (state == this._state)
                {
                    return;
                }

                oldState = this._state;
                // We really need a proper state machine here....
                // There's a race if Syncthing can't start because the database is locked by another process on the same port
                // In this case, we see the process as having failed, but the event watcher chimes in a split-second later with the 'Started' event.
                // This runs the risk of transitioning us from Stopped -> Starting -> Stopped -> Running, which is bad news for everyone
                // So, get around this by enforcing strict state transitions.
                if (this._state == SyncthingState.Stopped && state == SyncthingState.Running)
                {
                    return;
                }

                // Not entirely sure where this condition comes from...
                if (this._state == SyncthingState.Stopped && state == SyncthingState.Stopping)
                {
                    return;
                }

                if (this._state == SyncthingState.Running ||
                    (this._state == SyncthingState.Starting && state == SyncthingState.Stopped))
                {
                    abortApi = true;
                }

                logger.Debug("Setting state: {0} -> {1}", this._state, state);
                this._state = state;
            }

            this.eventDispatcher.Raise(this.StateChanged, new SyncthingStateChangedEventArgs(oldState, state));

            if (abortApi)
            {
                logger.Debug("Aborting API clients");
                // StopApiClients acquires the correct locks, and aborts the CTS
                this.StopApiClients();
            }
        }
Beispiel #2
0
        public ShellViewModel(
            IWindowManager windowManager,
            ISyncthingManager syncthingManager,
            IApplicationState application,
            IConfigurationProvider configurationProvider,
            ConsoleViewModel console,
            ViewerViewModel viewer,
            BarAlertsViewModel barAlerts,
            Func <SettingsViewModel> settingsViewModelFactory,
            Func <AboutViewModel> aboutViewModelFactory,
            Func <ConflictResolutionViewModel> confictResolutionViewModelFactory,
            IProcessStartProvider processStartProvider,
            IDonationManager donationManager)
        {
            this.windowManager         = windowManager;
            this.syncthingManager      = syncthingManager;
            this.application           = application;
            this.configurationProvider = configurationProvider;
            this.Console   = console;
            this.Viewer    = viewer;
            this.BarAlerts = barAlerts;
            this.settingsViewModelFactory          = settingsViewModelFactory;
            this.aboutViewModelFactory             = aboutViewModelFactory;
            this.confictResolutionViewModelFactory = confictResolutionViewModelFactory;
            this.processStartProvider = processStartProvider;
            this.DonationManager      = donationManager;

            var configuration = this.configurationProvider.Load();

            this.Console.ConductWith(this);
            this.Viewer.ConductWith(this);
            this.BarAlerts.ConductWith(this);

            this.syncthingManager.StateChanged           += (o, e) => this.SyncthingState = e.NewState;
            this.syncthingManager.ProcessExitedWithError += (o, e) => this.ShowExitedWithError();

            this.ConsoleHeight = configuration.SyncthingConsoleHeight;
            this.Bind(s => s.ConsoleHeight, (o, e) => this.configurationProvider.AtomicLoadAndSave(c => c.SyncthingConsoleHeight = e.NewValue));

            this.ShowConsole = configuration.SyncthingConsoleHeight > 0;
            this.Bind(s => s.ShowConsole, (o, e) =>
            {
                this.ConsoleHeight = e.NewValue ? Configuration.DefaultSyncthingConsoleHeight : 0.0;
            });

            this.Placement = configuration.WindowPlacement;
            this.Bind(s => s.Placement, (o, e) => this.configurationProvider.AtomicLoadAndSave(c => c.WindowPlacement = e.NewValue));
        }
Beispiel #3
0
        public ShellViewModel(
            IWindowManager windowManager,
            ISyncthingManager syncthingManager,
            IApplicationState application,
            IConfigurationProvider configurationProvider,
            ConsoleViewModel console,
            ViewerViewModel viewer,
            BarAlertsViewModel barAlerts,
            Func<SettingsViewModel> settingsViewModelFactory,
            Func<AboutViewModel> aboutViewModelFactory,
            Func<ConflictResolutionViewModel> confictResolutionViewModelFactory,
            IProcessStartProvider processStartProvider)
        {
            this.windowManager = windowManager;
            this.syncthingManager = syncthingManager;
            this.application = application;
            this.configurationProvider = configurationProvider;
            this.Console = console;
            this.Viewer = viewer;
            this.BarAlerts = barAlerts;
            this.settingsViewModelFactory = settingsViewModelFactory;
            this.aboutViewModelFactory = aboutViewModelFactory;
            this.confictResolutionViewModelFactory = confictResolutionViewModelFactory;
            this.processStartProvider = processStartProvider;

            var configuration = this.configurationProvider.Load();

            this.Console.ConductWith(this);
            this.Viewer.ConductWith(this);
            this.BarAlerts.ConductWith(this);

            this.syncthingManager.StateChanged += (o, e) => this.SyncthingState = e.NewState;
            this.syncthingManager.ProcessExitedWithError += (o, e) => this.ShowExitedWithError();

            this.ConsoleHeight = configuration.SyncthingConsoleHeight;
            this.Bind(s => s.ConsoleHeight, (o, e) => this.configurationProvider.AtomicLoadAndSave(c => c.SyncthingConsoleHeight = e.NewValue));

            this.ShowConsole = configuration.SyncthingConsoleHeight > 0;
            this.Bind(s => s.ShowConsole, (o, e) =>
            {
                this.ConsoleHeight = e.NewValue ? Configuration.DefaultSyncthingConsoleHeight : 0.0;
            });

            this.Placement = configuration.WindowPlacement;
            this.Bind(s => s.Placement, (o, e) => this.configurationProvider.AtomicLoadAndSave(c => c.WindowPlacement = e.NewValue));
        }
Beispiel #4
0
        private void SetState(SyncthingState state)
        {
            SyncthingState oldState;
            bool abortApi = false;
            lock (this.stateLock)
            {
                logger.Debug("Request to set state: {0} -> {1}", this._state, state);
                if (state == this._state)
                    return;

                oldState = this._state;
                // We really need a proper state machine here....
                // There's a race if Syncthing can't start because the database is locked by another process on the same port
                // In this case, we see the process as having failed, but the event watcher chimes in a split-second later with the 'Started' event.
                // This runs the risk of transitioning us from Stopped -> Starting -> Stopped -> Running, which is bad news for everyone
                // So, get around this by enforcing strict state transitions.
                if (this._state == SyncthingState.Stopped && state == SyncthingState.Running)
                    return;

                // Not entirely sure where this condition comes from...
                if (this._state == SyncthingState.Stopped && state == SyncthingState.Stopping)
                    return;

                if (this._state == SyncthingState.Running ||
                    (this._state == SyncthingState.Starting && state == SyncthingState.Stopped))
                    abortApi = true;

                logger.Debug("Setting state: {0} -> {1}", this._state, state);
                this._state = state;
            }

            if (abortApi)
            {
                logger.Debug("Aborting API clients");
                // StopApiClients acquires the correct locks, and aborts the CTS
                this.StopApiClients();
            }

            this.eventDispatcher.Raise(this.StateChanged, new SyncthingStateChangedEventArgs(oldState, state));
        }
 public SyncthingStateChangedEventArgs(SyncthingState oldState, SyncthingState newState)
 {
     this.OldState = oldState;
     this.NewState = newState;
 }
 public SyncthingStateChangedEventArgs(SyncthingState oldState, SyncthingState newState)
 {
     this.OldState = oldState;
     this.NewState = newState;
 }