<commit_before>﻿using Lime.Protocol.Resources;
using Lime.Protocol.Util;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

#if !MONO
using System.Threading.Tasks.Dataflow;
#endif

namespace Lime.Protocol.Network
{
    /// <summary>
    /// Base class for the protocol
    /// communication channels
    /// </summary>
    public abstract class ChannelBase : IChannel, IDisposable
    {
        #region Fields
        
		private readonly TimeSpan _sendTimeout;
		private readonly bool _fillEnvelopeRecipients;
		private readonly bool _autoReplyPings;

#if MONO
		private readonly IAsyncQueue<Message> _messageBuffer;
		private readonly IAsyncQueue<Command> _commandBuffer;
		private readonly IAsyncQueue<Notification> _notificationBuffer;
		private readonly IAsyncQueue<Session> _sessionBuffer;
#else
		private readonly System.Threading.Tasks.Dataflow.BufferBlock<Message> _messageBuffer;
		private readonly System.Threading.Tasks.Dataflow.BufferBlock<Command> _commandBuffer;
		private readonly System.Threading.Tasks.Dataflow.BufferBlock<Notification> _notificationBuffer;
		private readonly System.Threading.Tasks.Dataflow.BufferBlock<Session> _sessionBuffer;
#endif

        private Task _consumeTransportTask;

        protected readonly CancellationTokenSource _channelCancellationTokenSource;                
        private bool _isDisposing;

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new instance of ChannelBase
        /// </summary>
        /// <param name="transport"></param>
        /// <param name="sendTimeout"></param>
        /// <param name="buffersLimit"></param>
        /// <param name="fillEnvelopeRecipients">Indicates if the from and to properties of sent and received envelopes should be filled with the session information if not defined.</param>
        /// <param name="autoReplyPings">Indicates if the channel should reply automatically to ping request commands. In this case, the ping command are not returned by the ReceiveCommandAsync method.</param>
        public ChannelBase(ITransport transport, TimeSpan sendTimeout, int buffersLimit, bool fillEnvelopeRecipients, bool autoReplyPings)
        {
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            this.Transport = transport;
            this.Transport.Closing += Transport_Closing;

            _sendTimeout = sendTimeout;<commit_msg>Remove of unnecessary full class name<commit_after>﻿using Lime.Protocol.Resources;
using Lime.Protocol.Util;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

#if !MONO
using System.Threading.Tasks.Dataflow;
#endif

namespace Lime.Protocol.Network
{
    /// <summary>
    /// Base class for the protocol
    /// communication channels
    /// </summary>
    public abstract class ChannelBase : IChannel, IDisposable
    {
        #region Fields
        
		private readonly TimeSpan _sendTimeout;
		private readonly bool _fillEnvelopeRecipients;
		private readonly bool _autoReplyPings;

#if MONO
		private readonly IAsyncQueue<Message> _messageBuffer;
		private readonly IAsyncQueue<Command> _commandBuffer;
		private readonly IAsyncQueue<Notification> _notificationBuffer;
		private readonly IAsyncQueue<Session> _sessionBuffer;
#else
		private readonly BufferBlock<Message> _messageBuffer;
		private readonly BufferBlock<Command> _commandBuffer;
		private readonly BufferBlock<Notification> _notificationBuffer;
		private readonly BufferBlock<Session> _sessionBuffer;
#endif

        private Task _consumeTransportTask;

        protected readonly CancellationTokenSource _channelCancellationTokenSource;                
        private bool _isDisposing;

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new instance of ChannelBase
        /// </summary>
        /// <param name="transport"></param>
        /// <param name="sendTimeout"></param>
        /// <param name="buffersLimit"></param>
        /// <param name="fillEnvelopeRecipients">Indicates if the from and to properties of sent and received envelopes should be filled with the session information if not defined.</param>
        /// <param name="autoReplyPings">Indicates if the channel should reply automatically to ping request commands. In this case, the ping command are not returned by the ReceiveCommandAsync method.</param>
        public ChannelBase(ITransport transport, TimeSpan sendTimeout, int buffersLimit, bool fillEnvelopeRecipients, bool autoReplyPings)
        {
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            this.Transport = transport;
            this.Transport.Closing += Transport_Closing;

            _sendTimeout = sendTimeout;
{'fraction_non_alphanumeric': 0.07925867507886436, 'fraction_numerical': 0.0, 'mean_word_length': 3.343321917808219, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '673074', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1228, 'n_words': 380}