public void Should_ContainSpecifiedValues_When_CreateProgressDescription() { UpdateDescription ud = new UpdateDescription(); ud.Title = "title"; ProgressDescription pd1 = new ProgressDescription(ud, 0, 1, 50); ProgressDescription pd2 = new ProgressDescription(ud); ProgressDescription pd3 = new ProgressDescription(); Assert.AreSame(pd1.CurrentUpdate, ud); Assert.AreSame(pd2.CurrentUpdate, ud); Assert.IsNull(pd3.CurrentUpdate); Assert.AreEqual(pd1.CurrentIndex, 0); Assert.IsNull(pd2.CurrentIndex); Assert.IsNull(pd3.CurrentIndex); Assert.AreEqual(pd1.Count, 1); Assert.IsNull(pd2.Count); Assert.IsNull(pd3.Count); Assert.IsFalse(pd1.IsIndeterminate); Assert.IsTrue(pd2.IsIndeterminate); Assert.IsTrue(pd3.IsIndeterminate); Assert.IsTrue(pd1.ToString().Contains(ud.Title)); Assert.IsFalse(String.IsNullOrWhiteSpace(pd2.ToString())); Assert.IsFalse(String.IsNullOrWhiteSpace(pd3.ToString())); Assert.AreEqual(pd1.Percent, 50); }
/// <summary> /// Callback for async operations (search, download and install) to update the <see cref="CurrentProgress"/> property. /// </summary> /// <param name="job">The async operation which makes progress.</param> /// <param name="currentUpdate">The current update where the async operation is working on.</param> /// <param name="currentIndex">The index of the current update.</param> /// <param name="count">Total number of updates which the async operation has to proceed.</param> private void ProgressChangedCallback(WuStateAsyncJob job, IUpdate currentUpdate, int currentIndex, int count, int percent) { Debug.Assert(count >= 0 && currentIndex >= 0 && percent >= 0); Debug.Assert(percent <= 100); Debug.Assert(currentIndex < count); Debug.Assert(job != null && currentUpdate != null); try { var progress = new ProgressDescription((currentUpdate != null) ? UpdateHolder.ToUpdateDescription(currentUpdate) : null, currentIndex, count, percent); using (ll.Lock(StateLock)) { if (_currentState == job) { CurrentProgress = progress; Log.Debug("Progress callback received: " + CurrentProgress); } } } catch (Exception e) { Debug.Assert(false, e.Message); // do not hide in test scenarios Log.Error($"Failed to create {nameof(ProgressDescription)}, progress will be ignored.", e); } }
public void Should_ContainSpecifiedValues_When_CreateProgressChangedEventArgs() { WuStateId state = WuStateId.DownloadFailed; ProgressDescription progress = new ProgressDescription(); ProgressChangedEventArgs eventArgs = new ProgressChangedEventArgs(state, progress); Assert.AreEqual(state, eventArgs.StateId); Assert.AreEqual(progress, eventArgs.Progress); }
/// <summary> /// Starts to search for windows updates. /// </summary> /// <param name="timeoutSec">Seconds until the search will be aborted to prevent never ending searches, must be positive.</param> /// <returns>The new state when the method finished.</returns> /// <exception cref="InvalidStateTransitionException" /> /// <exception cref="ArgumentOutOfRangeException" /> /// <exception cref="System.Runtime.InteropServices.COMException" /> public WuStateId BeginSearchUpdates(int timeoutSec = (int)DefaultAsyncOperationTimeout.SearchTimeout) { using (ll.Lock(StateLock)) { ThrowIfInvalidStateTransition(typeof(WuStateSearching)); Log.Debug("Start async search for updates."); EnterState(new WuStateSearching(UpdateSearcher, EndSearchUpdates, TimeoutSearchUpdates, timeoutSec)); } CurrentProgress = new ProgressDescription(); // progress not defineable, searching does not have any progress callbacks return(_currentState.StateId); }
public void Should_NotAllowInvalidCount_When_CreateProgressDescription() { try { ProgressDescription pd = new ProgressDescription(null, 0, -1, 0); Assert.Fail("exception expected"); } catch (IndexOutOfRangeException) { } try { ProgressDescription pd = new ProgressDescription(null, 0, 0, 0); Assert.Fail("exception expected"); } catch (IndexOutOfRangeException) { } }
public void Should_ContainSpecifiedValues_When_CreateStateDescription() { ProgressDescription pd = new ProgressDescription(); string name = "name"; string desc = "desc"; var insts = InstallerStatus.Busy; var en = new WuEnviroment("a", "a", "a", "a", TimeSpan.Zero, 10); StateDescription sd = new StateDescription(WuStateId.Installing, name, desc, insts, en, pd); Assert.AreEqual(name, sd.DisplayName); Assert.AreEqual(desc, sd.Description); Assert.AreEqual(WuStateId.Installing, sd.StateId); Assert.AreEqual(insts, sd.InstallerStatus); Assert.AreSame(pd, sd.Progress); Assert.AreSame(en, sd.Enviroment); }
public void Should_NotAllowInvalidPercentValue_When_CreateProgressDescription() { new ProgressDescription(null, 0, 1, 0); // 0, ok new ProgressDescription(null, 0, 1, 100); // 100, ok try { ProgressDescription pd = new ProgressDescription(null, 0, 1, -1); // -1, not valid Assert.Fail("exception expected"); } catch (IndexOutOfRangeException) { } try { ProgressDescription pd = new ProgressDescription(null, 0, 1, 101); // 101, not valid Assert.Fail("exception expected"); } catch (IndexOutOfRangeException) { } }
public void OnProgressChanged(ProgressDescription progress, WuStateId currentState) { lock (EndpointLock) { if (Endpoint == null) { return; } Log.Debug($"Progress changed callback from {Endpoint.FQDN}. Percent: {progress.Percent} Indeterminate: {progress.IsIndeterminate}."); lock (Endpoint.StateLock) { if (progress.CurrentUpdate != null) { Endpoint.State.Description = progress.CurrentUpdate.Title; if (currentState == WuStateId.Downloading) { Endpoint.State.Description += $" ({BytesToHumanReadableConverter.GetBytesReadable(progress.CurrentUpdate.MaxByteSize)})"; } Endpoint.State.Progress = progress; } } Endpoint.OnPropertyChanged("State"); } }
public bool Equals(DestinyObjectiveDefinition input) { if (input == null) { return(false); } return (( DisplayProperties == input.DisplayProperties || (DisplayProperties != null && DisplayProperties.Equals(input.DisplayProperties)) ) && ( CompletionValue == input.CompletionValue || (CompletionValue.Equals(input.CompletionValue)) ) && ( Scope == input.Scope || (Scope != null && Scope.Equals(input.Scope)) ) && ( LocationHash == input.LocationHash || (LocationHash.Equals(input.LocationHash)) ) && ( AllowNegativeValue == input.AllowNegativeValue || (AllowNegativeValue != null && AllowNegativeValue.Equals(input.AllowNegativeValue)) ) && ( AllowValueChangeWhenCompleted == input.AllowValueChangeWhenCompleted || (AllowValueChangeWhenCompleted != null && AllowValueChangeWhenCompleted.Equals(input.AllowValueChangeWhenCompleted)) ) && ( IsCountingDownward == input.IsCountingDownward || (IsCountingDownward != null && IsCountingDownward.Equals(input.IsCountingDownward)) ) && ( ValueStyle == input.ValueStyle || (ValueStyle != null && ValueStyle.Equals(input.ValueStyle)) ) && ( ProgressDescription == input.ProgressDescription || (ProgressDescription != null && ProgressDescription.Equals(input.ProgressDescription)) ) && ( Perks == input.Perks || (Perks != null && Perks.Equals(input.Perks)) ) && ( Stats == input.Stats || (Stats != null && Stats.Equals(input.Stats)) ) && ( MinimumVisibilityThreshold == input.MinimumVisibilityThreshold || (MinimumVisibilityThreshold.Equals(input.MinimumVisibilityThreshold)) ) && ( AllowOvercompletion == input.AllowOvercompletion || (AllowOvercompletion != null && AllowOvercompletion.Equals(input.AllowOvercompletion)) ) && ( ShowValueOnComplete == input.ShowValueOnComplete || (ShowValueOnComplete != null && ShowValueOnComplete.Equals(input.ShowValueOnComplete)) ) && ( CompletedValueStyle == input.CompletedValueStyle || (CompletedValueStyle != null && CompletedValueStyle.Equals(input.CompletedValueStyle)) ) && ( InProgressValueStyle == input.InProgressValueStyle || (InProgressValueStyle != null && InProgressValueStyle.Equals(input.InProgressValueStyle)) ) && ( Hash == input.Hash || (Hash.Equals(input.Hash)) ) && ( Index == input.Index || (Index.Equals(input.Index)) ) && ( Redacted == input.Redacted || (Redacted != null && Redacted.Equals(input.Redacted)) )); }
public ProgressChangedEventArgs(WuStateId stateId, ProgressDescription progress) { StateId = stateId; Progress = progress; }
/// <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."); } }