<commit_before>﻿using System;
using System.Reactive.Disposables;
using ReactiveUI;

namespace RxMobile
{
    public interface ILifecycleViewModel 
    {
        IReactiveCommand<object> Pausing { get; }
        IReactiveCommand<object> Resuming { get; }
    }

    public interface ILifecycleControllerModel
    {
        IObservable<object> Pausing { get; }
        IObservable<object> Resuming { get; }
    }

    public interface ILifecycleModel : ILifecycleViewModel, ILifecycleControllerModel
    {
    }

    public sealed class LifecycleController : IService
    {
        public static IService Create(ILifecycleControllerModel model, Action onPaused, Action onResumed)
        {
            // FIXME: Preconditions or code contracts
            return new LifecycleController(model, onPaused, onResumed);
        }

        private readonly ILifecycleControllerModel model;
        private readonly Action onPaused;
        private readonly Action onResumed;

        private bool paused = true;
        private IDisposable subscription;

        private LifecycleController(ILifecycleControllerModel model, Action onPaused, Action onResumed)
        {
            this.model = model;
            this.onPaused = onPaused;
            this.onResumed = onResumed;
        }

        public void Start()
        {
            if (subscription != null)
            {
                throw new NotSupportedException("Trying to call start more than once without first calling stop");
            }

            var newSubscription = new CompositeDisposable();

            newSubscription.Add (
                model.Resuming.Subscribe(_ => 
                    {
                        paused = true;
                        onResumed();
                    }));

            newSubscription.Add (
                model.Pausing.Subscribe(_ => 
                    {
                        paused = true;
                        onPaused();
                    }));
                    
            subscription = newSubscription;
        }

        public void Stop()
        {
            if (subscription != null)
            {
                subscription.Dispose();
                subscription = null;
            }
             
            if (!paused)
            {
                onPaused();
            }
        }
    }
}<commit_msg>Fix argument order<commit_after>﻿using System;
using System.Reactive.Disposables;
using ReactiveUI;

namespace RxMobile
{
    public interface ILifecycleViewModel 
    {
        IReactiveCommand<object> Pausing { get; }
        IReactiveCommand<object> Resuming { get; }
    }

    public interface ILifecycleControllerModel
    {
        IObservable<object> Pausing { get; }
        IObservable<object> Resuming { get; }
    }

    public interface ILifecycleModel : ILifecycleViewModel, ILifecycleControllerModel
    {
    }

    public sealed class LifecycleController : IService
    {
        public static IService Create(ILifecycleControllerModel model, Action onResumed, Action onPaused)
        {
            // FIXME: Preconditions or code contracts
            return new LifecycleController(model, onResumed, onPaused);
        }

        private readonly ILifecycleControllerModel model;
        private readonly Action onPaused;
        private readonly Action onResumed;

        private bool paused = true;
        private IDisposable subscription;

        private LifecycleController(ILifecycleControllerModel model, Action onResumed, Action onPaused)
        {
            this.model = model;
            this.onPaused = onPaused;
            this.onResumed = onResumed;
        }

        public void Start()
        {
            if (subscription != null)
            {
                throw new NotSupportedException("Trying to call start more than once without first calling stop");
            }

            var newSubscription = new CompositeDisposable();

            newSubscription.Add (
                model.Resuming.Subscribe(_ => 
                    {
                        paused = false;
                        onResumed();
                    }));

            newSubscription.Add (
                model.Pausing.Subscribe(_ => 
                    {
                        paused = true;
                        onPaused();
                    }));
                    
            subscription = newSubscription;
        }

        public void Stop()
        {
            if (subscription != null)
            {
                subscription.Dispose();
                subscription = null;
            }
             
            if (!paused)
            {
                onPaused();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06624203821656051, 'fraction_numerical': 0.0, 'mean_word_length': 1.4626241505488762, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '6469918', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1095, 'n_words': 270}