<commit_before>using System;
using System.Collections.Generic;
using System.Linq;

namespace Lix.Commons.Repositories.InMemory
{
    /// <summary>
    /// Represents an in memory unit of work.
    /// </summary>
    public class InMemoryUnitOfWork : IUnitOfWork
    {
        public InMemoryUnitOfWork(InMemoryDataStore dataStore)
        {
            this.DataStore = dataStore;
            this.CurrentTransactionDataStore = new InMemoryDataStore();
        }

        public InMemoryDataStore DataStore
        {
            get;
            private set;
        }

        public InMemoryDataStore CurrentTransactionDataStore
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets a value indicating whether unit of work is active.
        /// </summary>
        /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
        public bool IsActive
        {
            get;
            private set;
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
        }

        /// <summary>
        /// Begins a new unit of work.
        /// </summary>
        public void Begin()
        {
            // TODO: Check whether a unit of work already exists for this DataStore
            ///throw new InvalidOperationException("A unit of work has already begun for this session.");

            this.CurrentTransactionDataStore = new InMemoryDataStore();
            this.CurrentTransactionDataStore.Merge(this.DataStore);
            this.IsActive = true;
        }

        /// <summary>
        /// Commits the unit of work.
        /// </summary>
        public void Commit()
        {
            this.Commit(false);
        }

        /// <summary>
        /// Commits the unit of work.
        /// </summary>
        public void Commit(bool begin)
        {
            if (!this.IsActive)
            {
                throw new InvalidOperationException("Unable to commit when not active.");
            }

            // Commit transactionaldatastore to InMemoryDataStore
            this.DataStore.Merge(this.CurrentTransactionDataStore);

            if (begin)
            {
                this.Begin();
            }
            else
            {
                this.CurrentTransactionDataStore.Clear();
                this.IsActive = false;
            }
        }

        /// <summary>
        /// Rollbacks the unit of work.
        /// </summary>
        public void Rollback()
        {
            if (!this.IsActive)
            {
                throw new InvalidOperationException("Unable to rollback when not active.");
            }
            else
            {
                this.CurrentTransactionDataStore.Clear();
                this.IsActive = false;
            }
        }
    }
}<commit_msg>Moved IsActive = false statement in Commit(bool)<commit_after>using System;
using System.Collections.Generic;
using System.Linq;

namespace Lix.Commons.Repositories.InMemory
{
    /// <summary>
    /// Represents an in memory unit of work.
    /// </summary>
    public class InMemoryUnitOfWork : IUnitOfWork
    {
        public InMemoryUnitOfWork(InMemoryDataStore dataStore)
        {
            this.DataStore = dataStore;
            this.CurrentTransactionDataStore = new InMemoryDataStore();
        }

        public InMemoryDataStore DataStore
        {
            get;
            private set;
        }

        public InMemoryDataStore CurrentTransactionDataStore
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets a value indicating whether unit of work is active.
        /// </summary>
        /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
        public bool IsActive
        {
            get;
            private set;
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
        }

        /// <summary>
        /// Begins a new unit of work.
        /// </summary>
        public void Begin()
        {
            // TODO: Check whether a unit of work already exists for this DataStore
            //if (this.IsActive)
            //{
            //    throw new InvalidOperationException("A unit of work has already begun for this session.");
            //}

            this.CurrentTransactionDataStore = new InMemoryDataStore();
            this.CurrentTransactionDataStore.Merge(this.DataStore);
            this.IsActive = true;
        }

        /// <summary>
        /// Commits the unit of work.
        /// </summary>
        public void Commit()
        {
            this.Commit(false);
        }

        /// <summary>
        /// Commits the unit of work.
        /// </summary>
        public void Commit(bool begin)
        {
            if (!this.IsActive)
            {
                throw new InvalidOperationException("Unable to commit when not active.");
            }

            // Commit transactionaldatastore to InMemoryDataStore
            this.DataStore.Merge(this.CurrentTransactionDataStore);

            this.IsActive = false;

            if (begin)
            {
                this.Begin();
            }
            else
            {
                this.CurrentTransactionDataStore.Clear();
            }
        }

        /// <summary>
        /// Rollbacks the unit of work.
        /// </summary>
        public void Rollback()
        {
            if (!this.IsActive)
            {
                throw new InvalidOperationException("Unable to rollback when not active.");
            }
            else
            {
                this.CurrentTransactionDataStore.Clear();
                this.IsActive = false;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09493041749502983, 'fraction_numerical': 0.0, 'mean_word_length': 1.339922480620155, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '5626891', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1438, 'n_words': 391}