protected override void EnterStateInternal(WuProcessState oldState) { OnTimeoutSignal.Reset(); }
internal InvalidStateTransitionException(WuProcessState from, WuProcessState to) : this(from, to, innerException : null) { }
internal InvalidStateTransitionException(WuProcessState from, WuProcessState to, string message) : this(from, to, message, null) { }
internal InvalidStateTransitionException(WuProcessState from, WuProcessState to, string message, Exception innerException) : base(message, innerException) { From = from; To = to; }
internal InvalidStateTransitionException(WuProcessState from, WuProcessState to, Exception innerException) : base($"Not allowed: Transition from '{from.DisplayName}' to '{to.DisplayName}'.", innerException) { From = from; To = to; }
/// <summary> /// Leaves and disposes the current state and enters a new state. /// </summary> /// <param name="next">The new state to change to.</param> private void EnterState(WuProcessState next) { if (next == null) { throw new ArgumentNullException(nameof(next)); } using (ll.Lock(StateChangingLock)) { if (_currentState != null) { ThrowIfInvalidStateTransition(next.GetType()); } Log.Info($"Changing state from '{_currentState?.DisplayName}' to '{next.DisplayName}'."); WuProcessState oldState = _currentState; try { next.EnterState(oldState); } catch (Exception e) { Log.Error($"Failed to enter state '{next?.DisplayName}' properly.", e); Debug.Assert(_currentState != next, "Should not switch to the next state when an error occured."); throw; } _currentState = next; CurrentProgress = null; try { oldState?.LeaveState(); } catch (Exception e) { Debug.Assert(true, $"Failed to leave state '{oldState?.DisplayName}' properly: {e.Message}."); // do not hide this exception in test scenarios Log.Error($"Failed to leave state '{oldState?.DisplayName}' properly.", e); } finally { (oldState as IDisposable)?.Dispose(); } OnStateChanged?.Invoke(this, new StateChangedEventArgs((oldState != null) ? oldState.StateId : WuStateId.Ready, next.StateId)); if (OnAsyncOperationCompleted != null && oldState is WuStateAsyncJob) { if (oldState is WuStateSearching) { OnAsyncOperationCompleted(this, new AsyncOperationCompletedEventArgs(AsyncOperation.Searching, next.StateId)); } else if (oldState is WuStateDownloading) { OnAsyncOperationCompleted(this, new AsyncOperationCompletedEventArgs(AsyncOperation.Downloading, next.StateId)); } else if (oldState is WuStateInstalling) { OnAsyncOperationCompleted(this, new AsyncOperationCompletedEventArgs(AsyncOperation.Installing, next.StateId)); } else { throw new NotImplementedException($"For {oldState.GetType()} are no {nameof(OnAsyncOperationCompleted)} event args implemented."); } } Debug.Assert(_currentState == next, "State was not changed."); Debug.Assert(CurrentProgress == null, "Should reset progress when state changes."); } }
internal PreConditionNotFulfilledException(WuProcessState from, WuProcessState to, string message) : base(from, to, message) { }
public override void EnterState(WuProcessState oldState) { throw new NotImplementedException(); }