< Summary

Information
Class: MyNet.UI.ViewModels.Shell.Taskbar.BusyTaskbarCoordinator
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Shell/Taskbar/BusyTaskbarCoordinator.cs
Tag: 323_28699572109
Line coverage
95%
Covered lines: 38
Uncovered lines: 2
Coverable lines: 40
Total lines: 103
Line coverage: 95%
Branch coverage
71%
Covered branches: 20
Total branches: 28
Branch coverage: 71.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%44100%
Dispose()100%11100%
OnApplicationBusyPropertyChanged(...)66.66%7675%
SyncFromApplicationBusy()75%44100%
UpdateProgressionSubscription(...)83.33%66100%
UnsubscribeProgression()100%22100%
OnProgressionBusyPropertyChanged(...)66.66%6685.71%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Shell/Taskbar/BusyTaskbarCoordinator.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="BusyTaskbarCoordinator.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.ComponentModel;
 9using MyNet.UI.Loading;
 10using MyNet.UI.Loading.Models;
 11
 12namespace MyNet.UI.ViewModels.Shell.Taskbar;
 13
 14/// <summary>
 15/// Synchronizes application <see cref="IBusyService"/> state with <see cref="ITaskbarProgressSource"/>.
 16/// </summary>
 17public sealed class BusyTaskbarCoordinator : IDisposable
 18{
 19    private readonly IBusyService _applicationBusy;
 20    private readonly ITaskbarProgressSource _taskbarProgress;
 21    private ProgressionBusy? _subscribedProgression;
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="BusyTaskbarCoordinator"/> class.
 25    /// </summary>
 26    public BusyTaskbarCoordinator(IBusyService applicationBusy, ITaskbarProgressSource taskbarProgress)
 27    {
 1228        _applicationBusy = applicationBusy ?? throw new ArgumentNullException(nameof(applicationBusy));
 1229        _taskbarProgress = taskbarProgress ?? throw new ArgumentNullException(nameof(taskbarProgress));
 30
 1231        _applicationBusy.PropertyChanged += OnApplicationBusyPropertyChanged;
 1232        SyncFromApplicationBusy();
 1233    }
 34
 35    /// <inheritdoc />
 36    public void Dispose()
 37    {
 1238        _applicationBusy.PropertyChanged -= OnApplicationBusyPropertyChanged;
 1239        UnsubscribeProgression();
 1240    }
 41
 42    private void OnApplicationBusyPropertyChanged(object? sender, PropertyChangedEventArgs e)
 43    {
 3644        if (e.PropertyName is not (nameof(IBusyService.IsBusy) or nameof(IBusyService.CurrentBusy)))
 045            return;
 46
 3647        SyncFromApplicationBusy();
 3648    }
 49
 50    private void SyncFromApplicationBusy()
 51    {
 4852        var progressionBusy = _applicationBusy.GetCurrent<ProgressionBusy>();
 4853        UpdateProgressionSubscription(progressionBusy);
 54
 4855        var progressState = _applicationBusy.IsBusy
 4856            ? TaskbarProgressState.Indeterminate
 4857            : _taskbarProgress.ProgressState == TaskbarProgressState.Error
 4858                ? TaskbarProgressState.Error
 4859                : TaskbarProgressState.None;
 60
 4861        _taskbarProgress.SetProgress(progressState);
 4862    }
 63
 64    private void UpdateProgressionSubscription(ProgressionBusy? progressionBusy)
 65    {
 4866        if (ReferenceEquals(_subscribedProgression, progressionBusy))
 3667            return;
 68
 1269        UnsubscribeProgression();
 70
 1271        _subscribedProgression = progressionBusy;
 72
 1273        if (_subscribedProgression is not null && _applicationBusy.IsBusy)
 674            _subscribedProgression.PropertyChanged += OnProgressionBusyPropertyChanged;
 1275    }
 76
 77    private void UnsubscribeProgression()
 78    {
 2479        if (_subscribedProgression is null)
 1880            return;
 81
 682        _subscribedProgression.PropertyChanged -= OnProgressionBusyPropertyChanged;
 683        _subscribedProgression = null;
 684    }
 85
 86    private void OnProgressionBusyPropertyChanged(object? sender, PropertyChangedEventArgs e)
 87    {
 988        if (sender is not ProgressionBusy progressionBusy)
 089            return;
 90
 991        switch (e.PropertyName)
 92        {
 93            case nameof(ProgressionBusy.Value):
 694                _taskbarProgress.SetProgress(TaskbarProgressState.Normal, progressionBusy.Value);
 695                break;
 96
 97            case nameof(ProgressionBusy.IsCancelling):
 398                _taskbarProgress.SetProgress(TaskbarProgressState.Paused, progressionBusy.Value);
 99                break;
 100        }
 3101    }
 102}
 103