/// <summary>
        /// Converts a raw NetIncomingMessage to an IncomingEntityMessage object
        /// </summary>
        /// <param name="message">raw network message</param>
        /// <returns>An IncomingEntityMessage object</returns>
        public IncomingEntityMessage HandleEntityNetworkMessage(NetIncomingMessage message)
        {
            var messageType = (EntityMessage) message.ReadByte();
            int uid;
            IncomingEntityMessage result = IncomingEntityMessage.Null;

            switch (messageType)
            {
                case EntityMessage.ComponentMessage:
                    uid = message.ReadInt32();
                    IncomingEntityComponentMessage messageContent = HandleEntityComponentNetworkMessage(message);
                    result = new IncomingEntityMessage(uid, EntityMessage.ComponentMessage, messageContent,
                                                       message.SenderConnection);

                    if (_messageProfiling)
                    {
                        //Log the message
                        var logger = IoCManager.Resolve<IMessageLogger>();
                        logger.LogIncomingComponentNetMessage(result.Uid, result.MessageType,
                                                              messageContent.ComponentFamily,
                                                              messageContent.MessageParameters.ToArray());
                    }

                    break;
                case EntityMessage.SystemMessage: //TODO: Not happy with this resolving the entmgr everytime a message comes in.
                    EntityManager eMgr = (EntityManager)IoCManager.Resolve<IEntityManager>();
                    eMgr.EntitySystemManager.HandleSystemMessage(new EntitySystemData(message.SenderConnection, message));
                    break;
                case EntityMessage.PositionMessage:
                    uid = message.ReadInt32();
                    //TODO: Handle position messages!
                    break;
                case EntityMessage.GetSVars:
                    uid = message.ReadInt32();
                    result = new IncomingEntityMessage(uid, EntityMessage.GetSVars, message, message.SenderConnection);
                    break;
            }
            return result;
        }
        /// <summary>
        /// Handles an incoming entity message
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public IncomingEntityMessage HandleEntityNetworkMessage(NetIncomingMessage message)
        {
            var messageType = (EntityMessage) message.ReadByte();
            int uid = 0;
            IncomingEntityMessage incomingEntityMessage = IncomingEntityMessage.Null;
            switch (messageType)
            {
                case EntityMessage.ComponentMessage:
                    uid = message.ReadInt32();
                    incomingEntityMessage = new IncomingEntityMessage(uid, EntityMessage.ComponentMessage,
                                                                      HandleEntityComponentNetworkMessage(message),
                                                                      message.SenderConnection);
                    break;
                case EntityMessage.SystemMessage: //TODO: Not happy with this resolving the entmgr everytime a message comes in.
                    EntityManager eMgr = (EntityManager)IoCManager.Resolve<IEntityManager>();
                    eMgr.EntitySystemManager.HandleSystemMessage(new EntitySystemData(message.SenderConnection, message));
                    break;
                case EntityMessage.PositionMessage:
                    uid = message.ReadInt32();
                    //TODO: Handle position messages!
                    break;
                case EntityMessage.ComponentInstantiationMessage:
                    uid = message.ReadInt32();
                    incomingEntityMessage = new IncomingEntityMessage(uid,
                                                                      EntityMessage.ComponentInstantiationMessage,
                                                                      (ComponentFamily)
                                                                      UnPackParams(message).First(),
                                                                      message.SenderConnection);
                    break;
                case EntityMessage.SetSVar:
                    uid = message.ReadInt32();
                    incomingEntityMessage = new IncomingEntityMessage(uid,
                                                                      EntityMessage.SetSVar,
                                                                      MarshalComponentParameter.Deserialize(message),
                                                                      message.SenderConnection);
                    break;
                case EntityMessage.GetSVars:
                    uid = message.ReadInt32();
                    incomingEntityMessage = new IncomingEntityMessage(uid,
                                                                      EntityMessage.GetSVars, null,
                                                                      message.SenderConnection);
                    break;
            }

            if (_messageProfiling)
            {
                var logger = IoCManager.Resolve<IMessageLogger>();

                if (messageType == EntityMessage.ComponentMessage)
                {
                    var messageContent = (IncomingEntityComponentMessage) incomingEntityMessage.Message;
                    logger.LogIncomingComponentNetMessage(message.SenderConnection.RemoteUniqueIdentifier,
                                                          uid,
                                                          messageType,
                                                          messageContent.ComponentFamily,
                                                          PackParamsForLog(messageContent.MessageParameters.ToArray()));
                }
                else if (messageType == EntityMessage.ComponentInstantiationMessage)
                {
                    logger.LogIncomingComponentNetMessage(message.SenderConnection.RemoteUniqueIdentifier,
                                                          uid,
                                                          messageType,
                                                          (ComponentFamily) incomingEntityMessage.Message,
                                                          new object[0]);
                }
            }

            return incomingEntityMessage;
        }