public void Should_ContainSpecifiedValues_When_CreateStateTransition() { Type s1 = typeof(WuStateReady); Type s2 = typeof(WuStateRebootRequired); StateTransition.TransitionCondition condition = (x) => { return(ConditionEvalResult.ValidStateChange); }; StateTransition t1 = new StateTransition(s1, s2, condition); Assert.AreEqual(s1, t1.FromState); Assert.AreEqual(s2, t1.ToState); Assert.AreSame(condition, t1.Condition); }
public void Should_BeEqual_When_CompareTransitionsWithSameFromToTypes() { StateTransition.TransitionCondition condition = (x) => { return(ConditionEvalResult.ValidStateChange); }; StateTransition t1 = new StateTransition(typeof(WuStateReady), typeof(WuStateRebootRequired)); StateTransition t2 = new StateTransition(typeof(WuStateReady), typeof(WuStateRebootRequired), condition); StateTransition t3 = new StateTransition(typeof(WuStateRebootRequired), typeof(WuStateReady)); StateTransition t4 = new StateTransition(typeof(WuStateRebootRequired), typeof(WuStateReady), condition); Assert.AreEqual(t1, t2); Assert.AreEqual(t3, t4); Assert.AreNotEqual(t1, t3); Assert.AreNotEqual(t2, t4); }
/// <summary> /// Setups a list of all valid state transistions. /// </summary> private StateTransitionCollection SetupStateTransitions() { StateTransition.TransitionCondition downloadingPreCon = (c) => { using (ll.Lock(UpdateHolderLock)) { var applUpdates = UpdateHolder.GetSelectedUpdates((u) => u.EulaAccepted); if (applUpdates.Any()) { if (applUpdates.All(u => u.IsDownloaded || u.IsInstalled)) { return(new ConditionEvalResult(true, "All selected updates are already downloaded.")); // or installed } if (SystemInfo.GetFreeSpace() < (decimal)1.5 * applUpdates.Where(u => !u.IsDownloaded && !u.IsInstalled).Sum(u => (u.RecommendedHardDiskSpace > 0) ? u.RecommendedHardDiskSpace : u.MaxDownloadSize)) { return(new ConditionEvalResult(false, "Not enough free space on system drive.")); } return(ConditionEvalResult.ValidStateChange); } return(new ConditionEvalResult(false, "Please search for updates first, select some updates and accept the eulas.")); } }; StateTransition.TransitionCondition installingPreCon = (c) => { using (ll.Lock(UpdateHolderLock)) { if (UpdateInstaller.IsBusy) { return(new ConditionEvalResult(false, "The update installer is currently busy, an other update session installs or uninstalls updates.")); } if (UpdateInstaller.RebootRequiredBeforeInstallation) { return(new ConditionEvalResult(false, "A reboot is required before updates can be installed.")); } var applUpdates = UpdateHolder.GetSelectedUpdates((u) => u.EulaAccepted); if (applUpdates.Any()) { if (applUpdates.All(u => u.IsInstalled)) { return(new ConditionEvalResult(true, "All selected updates are already downloaded.")); // or installed } return(ConditionEvalResult.ValidStateChange); } return(new ConditionEvalResult(false, "Please search for updates first, select some updates and accept the eulas.")); } }; var stateTransitions = new StateTransitionCollection(); // fromState -goes-> toState stateTransitions.Add <WuStateReady, WuStateSearching>(); stateTransitions.Add <WuStateReady, WuStateRestartSentToOS>(); stateTransitions.Add <WuStateSearching, WuStateSearchCompleted>(); stateTransitions.Add <WuStateSearching, WuStateSearchFailed>(); stateTransitions.Add <WuStateSearchCompleted, WuStateSearching>(); stateTransitions.Add <WuStateSearchCompleted, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateSearchCompleted, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateSearchFailed, WuStateSearching>(); stateTransitions.Add <WuStateSearchFailed, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateSearchFailed, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateDownloading, WuStateDownloadFailed>(); stateTransitions.Add <WuStateDownloading, WuStateDownloadCompleted>(); stateTransitions.Add <WuStateDownloading, WuStateDownloadPartiallyFailed>(); stateTransitions.Add <WuStateDownloadFailed, WuStateSearching>(); stateTransitions.Add <WuStateDownloadFailed, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateDownloadFailed, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateDownloadCompleted, WuStateSearching>(); stateTransitions.Add <WuStateDownloadCompleted, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateDownloadCompleted, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateDownloadPartiallyFailed, WuStateSearching>(); stateTransitions.Add <WuStateDownloadPartiallyFailed, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateDownloadPartiallyFailed, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateInstalling, WuStateInstallCompleted>(); stateTransitions.Add <WuStateInstalling, WuStateInstallFailed>(); stateTransitions.Add <WuStateInstalling, WuStateInstallPartiallyFailed>(); stateTransitions.Add <WuStateInstalling, WuStateRebootRequired>(); stateTransitions.Add <WuStateInstalling, WuStateUserInputRequired>(); stateTransitions.Add <WuStateInstallCompleted, WuStateSearching>(); stateTransitions.Add <WuStateInstallCompleted, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateInstallCompleted, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateInstallFailed, WuStateSearching>(); stateTransitions.Add <WuStateInstallFailed, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateInstallFailed, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateInstallPartiallyFailed, WuStateSearching>(); stateTransitions.Add <WuStateInstallPartiallyFailed, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateInstallPartiallyFailed, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateInstallPartiallyFailed, WuStateRestartSentToOS>(); stateTransitions.Add <WuStateUserInputRequired, WuStateSearching>(); stateTransitions.Add <WuStateUserInputRequired, WuStateDownloading>(downloadingPreCon); stateTransitions.Add <WuStateUserInputRequired, WuStateInstalling>(installingPreCon); stateTransitions.Add <WuStateRebootRequired, WuStateRestartSentToOS>(); return(stateTransitions); }
public void Add <T1, T2>(StateTransition.TransitionCondition condition) => Add(new StateTransition(typeof(T1), typeof(T2), condition));