<commit_before>// Copyright 2009-2011 Taijutsu.
//   
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
// this file except in compliance with the License. You may obtain a copy of the 
// License at 
//  
//      http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software distributed 
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
// specific language governing permissions and limitations under the License.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Transactions;
using Taijutsu.Infrastructure.Internal;

namespace Taijutsu.Infrastructure
{
    public class OperationScope : IDisposable
    {
        private readonly IDataProviderPlanningPolicy dataContextSharing;

        public OperationScope()
            : this(new DataProviderPlanningPolicy())
        {
        }

        protected internal OperationScope(IDataProviderPlanningPolicy dataContextSharing)
        {
            SupervisorContext.RegisterOperationScopeWith(dataContextSharing);
            this.dataContextSharing = dataContextSharing;
        }

        #region IDisposable Members

        public virtual void Dispose()
        {
            dataContextSharing.Dispose();
            SupervisorContext.UnRegisterOperationScope();
        }

        #endregion

        #region Nested type: DataProviderPlanningPolicy

        private sealed class DataProviderPlanningPolicy : IDataProviderPlanningPolicy
        {
            private readonly IList<DataProvider> providers = new List<DataProvider>();
            private readonly IList<ReadOnlyDataProvider> readOnlyProviders = new List<ReadOnlyDataProvider>();

            #region IDataProviderPlanningPolicy Members

            public DataProvider Register(UnitOfWorkConfig config)
            {
                return Internal.Infrastructure.DataProviderFactory(config);
            }

            public ReadOnlyDataProvider Register(UnitOfQueryConfig config)
            {
                return Internal.Infrastructure.ReadOnlyDataProviderFactory(config);
            }

            public void Dispose()
            {
                try
                {
                    Exception lastEx = null;
                    foreach (var dataProvider in providers)
                    {
                        try
                        {
                            dataProvider.Close();
                        }
                        catch (Exception exception)
                        {
                            Trace.TraceError(exception.ToString());
                            lastEx = exception;
                        }
                    }

                    foreach (var readOnlyDataProvider in readOnlyProviders)
                    {
                        try
                        {
                            readOnlyDataProvider.Close();
                        }
                        catch (Exception exception)
                        {
                            Trace.TraceError(exception.ToString());
                            lastEx = exception;
                        }
                    }

                    if (lastEx != null)
                    {
                        throw lastEx;
                    }
                }
                finally
                {
                    providers.Clear();
                    readOnlyProviders.Clear();
                }
            }

            public void Terminate(DataProvider dataProvider)
            {
                providers.Add(dataProvider);
            }

            public void Terminate(ReadOnlyDataProvider readOnlyDataProvider)
            {
                readOnlyProviders.Add(readOnlyDataProvider);
            }

            #endregion
        }

        #endregion
    }

    public class AtomicOperationScope : OperationScope
    {
        private readonly TransactionScope transactionScope;

        public AtomicOperationScope(TransactionScopeOption transactionScopeOption, TimeSpan scopeTimeout)
            : this(new TransactionScope(transactionScopeOption, scopeTimeout), new DataProviderPlanningPolicy())
        {
        }

        public AtomicOperationScope(TransactionScopeOption transactionScopeOption, TransactionOptions transactionOptions,
                                    EnterpriseServicesInteropOption enterpriseServicesInteropOption)
            : this(
                new TransactionScope(transactionScopeOption, transactionOptions, enterpriseServicesInteropOption),
                new DataProviderPlanningPolicy())
        {
        }

        public AtomicOperationScope(TransactionScopeOption transactionScopeOption, TransactionOptions transactionOptions)
            : this(new TransactionScope(transactionScopeOption, transactionOptions), new DataProviderPlanningPolicy())
        {
        }

        public AtomicOperationScope(TransactionScopeOption transactionScopeOption)
            : this(new TransactionScope(transactionScopeOption), new DataProviderPlanningPolicy())
        {
        }

        public AtomicOperationScope()
            : this(new TransactionScope(), new DataProviderPlanningPolicy())
        {
        }

        protected internal AtomicOperationScope(TransactionScope transactionScope,
                                                IDataProviderPlanningPolicy dataContextSharing)
            : base(dataContextSharing)
        {
            this.transactionScope = transactionScope;
        }

        public virtual void Complete()
        {
            transactionScope.Complete();
        }

        public override void Dispose()
        {
            try
            {
                base.Dispose();
            }
            finally
            {
                transactionScope.Dispose();    
            }
        }
    }
}<commit_msg>Renaming for AtomicOperationScope.<commit_after>// Copyright 2009-2011 Taijutsu.
//   
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
// this file except in compliance with the License. You may obtain a copy of the 
// License at 
//  
//      http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software distributed 
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
// specific language governing permissions and limitations under the License.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Transactions;
using Taijutsu.Infrastructure.Internal;

namespace Taijutsu.Infrastructure
{
    public class OperationScope : IDisposable
    {
        private readonly IDataProviderPlanningPolicy dataContextSharing;

        public OperationScope()
            : this(new DataProviderPlanningPolicy())
        {
        }

        protected internal OperationScope(IDataProviderPlanningPolicy dataContextSharing)
        {
            SupervisorContext.RegisterOperationScopeWith(dataContextSharing);
            this.dataContextSharing = dataContextSharing;
        }

        #region IDisposable Members

        public virtual void Dispose()
        {
            dataContextSharing.Dispose();
            SupervisorContext.UnRegisterOperationScope();
        }

        #endregion

        #region Nested type: DataProviderPlanningPolicy

        private sealed class DataProviderPlanningPolicy : IDataProviderPlanningPolicy
        {
            private readonly IList<DataProvider> providers = new List<DataProvider>();
            private readonly IList<ReadOnlyDataProvider> readOnlyProviders = new List<ReadOnlyDataProvider>();

            #region IDataProviderPlanningPolicy Members

            public DataProvider Register(UnitOfWorkConfig config)
            {
                return Internal.Infrastructure.DataProviderFactory(config);
            }

            public ReadOnlyDataProvider Register(UnitOfQueryConfig config)
            {
                return Internal.Infrastructure.ReadOnlyDataProviderFactory(config);
            }

            public void Dispose()
            {
                try
                {
                    Exception lastEx = null;
                    foreach (var dataProvider in providers)
                    {
                        try
                        {
                            dataProvider.Close();
                        }
                        catch (Exception exception)
                        {
                            Trace.TraceError(exception.ToString());
                            lastEx = exception;
                        }
                    }

                    foreach (var readOnlyDataProvider in readOnlyProviders)
                    {
                        try
                        {
                            readOnlyDataProvider.Close();
                        }
                        catch (Exception exception)
                        {
                            Trace.TraceError(exception.ToString());
                            lastEx = exception;
                        }
                    }

                    if (lastEx != null)
                    {
                        throw lastEx;
                    }
                }
                finally
                {
                    providers.Clear();
                    readOnlyProviders.Clear();
                }
            }

            public void Terminate(DataProvider dataProvider)
            {
                providers.Add(dataProvider);
            }

            public void Terminate(ReadOnlyDataProvider readOnlyDataProvider)
            {
                readOnlyProviders.Add(readOnlyDataProvider);
            }

            #endregion
        }

        #endregion
    }


    public class DistributedOperationScope : OperationScope
    {
        private readonly TransactionScope transactionScope;

        public DistributedOperationScope(TransactionScopeOption transactionScopeOption, TimeSpan scopeTimeout)
            : this(new TransactionScope(transactionScopeOption, scopeTimeout), new DataProviderPlanningPolicy())
        {
        }

        public DistributedOperationScope(TransactionScopeOption transactionScopeOption, TransactionOptions transactionOptions,
                                    EnterpriseServicesInteropOption enterpriseServicesInteropOption)
            : this(
                new TransactionScope(transactionScopeOption, transactionOptions, enterpriseServicesInteropOption),
                new DataProviderPlanningPolicy())
        {
        }

        public DistributedOperationScope(TransactionScopeOption transactionScopeOption, TransactionOptions transactionOptions)
            : this(new TransactionScope(transactionScopeOption, transactionOptions), new DataProviderPlanningPolicy())
        {
        }

        public DistributedOperationScope(TransactionScopeOption transactionScopeOption)
            : this(new TransactionScope(transactionScopeOption), new DataProviderPlanningPolicy())
        {
        }

        public DistributedOperationScope()
            : this(new TransactionScope(), new DataProviderPlanningPolicy())
        {
        }

        protected internal DistributedOperationScope(TransactionScope transactionScope,
                                                IDataProviderPlanningPolicy dataContextSharing)
            : base(dataContextSharing)
        {
            this.transactionScope = transactionScope;
        }

        public virtual void Complete()
        {
            transactionScope.Complete();
        }

        public override void Dispose()
        {
            try
            {
                base.Dispose();
            }
            finally
            {
                transactionScope.Dispose();    
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.05642296571664601, 'fraction_numerical': 0.001982651796778191, 'mean_word_length': 1.5828888414764242, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7242595', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2404, 'n_words': 580}