<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using Anotar.NLog;
using MoreLinq;
using NLog.Fluent;

namespace ActiveStateMachine.Transitions
{
    public sealed class Transition : IObserver<string>
    {
        public string Name { get; }
        public string SourceStateName { get; }
        public string TargetStateName { get; }
        private bool IsCompleted { get; set; }

        /// <summary>
        /// List of checks that need to be done before the transition.
        /// </summary>
        public IEnumerable<TransitionPrecondition> Preconditions { get; }

        /// <summary>
        /// Actions to execute during the transition
        /// </summary>
        public IEnumerable<TransitionAction> TransitionActions { get; }

        public Transition(string name, string sourceStateName, string targetStateName, 
            IEnumerable<TransitionPrecondition> preconditions, IEnumerable<TransitionAction> transitionActions)
        {
            Name = name;
            SourceStateName = sourceStateName;
            TargetStateName = targetStateName;
            Preconditions = preconditions;
            TransitionActions = transitionActions;
        }

        [LogToErrorOnException]
        public void OnNext(string value)
        {
            if (IsCompleted) return;

            if (Preconditions.All(p => p.IsValid))
            {
                TransitionActions.ForEach(t => t.Execute());
            }
        }

        public void OnError(Exception error)
        {
            if (IsCompleted) return;

            Log.Trace()
                .Message($"Handling error in transition {Name}.")
                .Exception(error);

            OnCompleted();
        }
        
        [LogToErrorOnException]
        public void OnCompleted()
        {
            IsCompleted = true;
        }
    }
}<commit_msg>Refactoring Transition into an entity<commit_after>using System.Collections.Generic;

namespace ActiveStateMachine.Transitions
{
    public sealed class Transition
    {
        public string Name { get; }
        public string SourceStateName { get; }
        public string TargetStateName { get; }

        /// <summary>
        /// List of checks that need to be done before the transition.
        /// </summary>
        public IEnumerable<TransitionPrecondition> Preconditions { get; }

        /// <summary>
        /// Actions to execute during the transition
        /// </summary>
        public IEnumerable<TransitionAction> TransitionActions { get; }

        public Transition(string name, string sourceStateName, string targetStateName, 
            IEnumerable<TransitionPrecondition> preconditions, IEnumerable<TransitionAction> transitionActions)
        {
            Name = name;
            SourceStateName = sourceStateName;
            TargetStateName = targetStateName;
            Preconditions = preconditions;
            TransitionActions = transitionActions;
        }
    }
}
{'fraction_non_alphanumeric': 0.07987967914438503, 'fraction_numerical': 0.0, 'mean_word_length': 2.0665983606557377, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 22, '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': '5704189', 'n_tokens_mistral': 718, 'n_tokens_neox': 690, 'n_words': 194}