<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xemio.GameLibrary.Common;
using Xemio.GameLibrary.Events;
using Xemio.GameLibrary.Events.Logging;
using Xemio.GameLibrary.Network.Events;

namespace Xemio.GameLibrary.Network.Packages
{
    internal class ServerPackageReceiver
    {
        #region Fields
        private readonly Server _server;
        private readonly EventManager _eventManager;
        private readonly ThreadInvoker _threadInvoker;
        #endregion Fields

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerPackageReceiver"/> class.
        /// </summary>
        /// <param name="server">The server.</param>
        public ServerPackageReceiver(Server server)
        {
            this._server = server;

            this._eventManager = XGL.Components.Get<EventManager>();
            this._threadInvoker = XGL.Components.Get<ThreadInvoker>();
        }
        #endregion Constructors

        #region Methods
        /// <summary>
        /// Starts to receive packages for the specified connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public void StartReceivingPackages(IConnection connection)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    while (connection.Connected)
                    {
                        Package package = connection.Receive();
                        if (package != null)
                        {
                            this._threadInvoker.Invoke(() => this._server.OnReceivePackage(package, connection));
                            this._eventManager.Publish(new ReceivedPackageEvent(package));
                        }
                    }
                }
                catch (Exception ex)
                {
                    this._eventManager.Publish(new ExceptionEvent(ex));

                    this._server.Connections.Remove(connection);
                    this._server.OnClientLeft(connection);
                }
            });
        }
        #endregion Methods<commit_msg>Removed an error in our network code.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xemio.GameLibrary.Common;
using Xemio.GameLibrary.Events;
using Xemio.GameLibrary.Events.Logging;
using Xemio.GameLibrary.Network.Events;

namespace Xemio.GameLibrary.Network.Packages
{
    internal class ServerPackageReceiver
    {
        #region Fields
        private readonly Server _server;
        private readonly EventManager _eventManager;
        private readonly ThreadInvoker _threadInvoker;
        #endregion Fields

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerPackageReceiver"/> class.
        /// </summary>
        /// <param name="server">The server.</param>
        public ServerPackageReceiver(Server server)
        {
            this._server = server;

            this._eventManager = XGL.Components.Get<EventManager>();
            this._threadInvoker = XGL.Components.Get<ThreadInvoker>();
        }
        #endregion Constructors

        #region Methods
        /// <summary>
        /// Starts to receive packages for the specified connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public void StartReceivingPackages(IConnection connection)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    while (connection.Connected)
                    {
                        Package package = connection.Receive();
                        if (package != null)
                        {
                            this._threadInvoker.Invoke(() => this._server.OnReceivePackage(package, connection));
                            this._eventManager.Publish(new ReceivedPackageEvent(package, connection));
                        }
                    }
                }
                catch (Exception ex)
                {
                    this._eventManager.Publish(new ExceptionEvent(ex));

                    this._server.Connections.Remove(connection);
                    this._server.OnClientLeft(connection);
                }
            });
        }
        #endregion Methods
{'fraction_non_alphanumeric': 0.09054770318021202, 'fraction_numerical': 0.0, 'mean_word_length': 1.6438995913601868, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, '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': '2770828', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1023, 'n_words': 224}