<commit_before>﻿#region Usings

using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using ReactiveUI;

#endregion

namespace UI.WPF.Modules.Installation.ViewModels.Installation
{
    public class InstallationItemParent : InstallationItem
    {
        public InstallationItemParent(string title, IEnumerable<InstallationItem> children)
        {
            Title = title;
            Children = children.ToList();

            Children.Select(x => x.ProgressObservable).CombineLatest().Select(list => list.Average()).BindTo(this, x => x.Progress);
            Children.Select(x => x.IndeterminateObservable).CombineLatest().Select(list => list.All(b => b)).BindTo(this, x => x.Indeterminate);
            Children.Select(x => x.ResultObservable).CombineLatest().Select(ResultSelector).BindTo(this, x => x.Result);

            OperationMessage = null;
        }

        public IEnumerable<InstallationItem> Children { get; private set; }

        private static InstallationResult ResultSelector(IList<InstallationResult> children)
        {
            if (children.Any(x => x == InstallationResult.Failed))
            {
                return InstallationResult.Failed;
            }

            if (children.All(x => x == InstallationResult.Successful))
            {
                return InstallationResult.Successful;
            }

            if (children.Any(x => x == InstallationResult.Canceled))
            {
                return InstallationResult.Canceled;
            }

            return InstallationResult.Pending;
        }

        #region Overrides of InstallationItem

        public override async Task Install()
        {
            using (CancellationTokenSource = new CancellationTokenSource())
            {
                CancellationTokenSource.Token.Register(() =>
                {
                    foreach (var installationItem in Children)
                    {
                        if (installationItem.CancellationTokenSource != null && !installationItem.CancellationTokenSource.IsCancellationRequested)
                        {
                            installationItem.CancellationTokenSource.Cancel();
                        }<commit_msg>Improved code layout a bit<commit_after>﻿#region Usings

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using ReactiveUI;

#endregion

namespace UI.WPF.Modules.Installation.ViewModels.Installation
{
    public class InstallationItemParent : InstallationItem
    {
        public InstallationItemParent(string title, IEnumerable<InstallationItem> children)
        {
            Title = title;
            Children = children.ToList();

            Children.Select(x => x.ProgressObservable).CombineLatest().Select(list => list.Average()).BindTo(this, x => x.Progress);
            Children.Select(x => x.IndeterminateObservable).CombineLatest().Select(list => list.All(b => b)).BindTo(this, x => x.Indeterminate);
            Children.Select(x => x.ResultObservable).CombineLatest().Select(ResultSelector).BindTo(this, x => x.Result);

            OperationMessage = null;
        }

        public IEnumerable<InstallationItem> Children { get; private set; }

        private static InstallationResult ResultSelector(IList<InstallationResult> children)
        {
            if (children.Any(x => x == InstallationResult.Failed))
            {
                return InstallationResult.Failed;
            }

            if (children.All(x => x == InstallationResult.Successful))
            {
                return InstallationResult.Successful;
            }

            if (children.Any(x => x == InstallationResult.Canceled))
            {
                return InstallationResult.Canceled;
            }

            return InstallationResult.Pending;
        }

        #region Overrides of InstallationItem

        public override async Task Install()
        {
            using (CancellationTokenSource = new CancellationTokenSource())
            {
                CancellationTokenSource.Token.Register(() =>
                {
                    foreach (var installationItem in Children)
                    {
                        if (installationItem.CancellationTokenSource == null || installationItem.CancellationTokenSource.IsCancellationRequested)
                        {
                            continue;
                        }

                        try
                        {
                            installationItem.CancellationTokenSource.Cancel();
                        }
                        catch (ObjectDisposedException)
                        {
                            // I can't think of a better way to do this, sorry...
                        }
{'fraction_non_alphanumeric': 0.08866189989785496, 'fraction_numerical': 0.0, 'mean_word_length': 1.888495575221239, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1094265', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1159, 'n_words': 225}