/// <summary>
        /// Set the host type.
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="type">The host type.</param>
        /// <param name="context">The communication data.</param>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static void SetHostType(string hostName, string type, Nequeo.Xml.Authorisation.Communication.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Get the host reference.
                    host.type = (!String.IsNullOrEmpty(type) ? type : "");

                    // Save the new data.
                    SaveCommunicationDataAsync(context);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Set the number of active connections.
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="activeConnections">The number of active connections on the host.</param>
        /// <param name="context">The communication data.</param>
        public static void SetHostActiveConnections(string hostName, int activeConnections, Nequeo.Xml.Authorisation.Communication.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Get the host reference.
                    host.activeConnections = (activeConnections < 1 ? 0 : activeConnections);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Get the host type.
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>The host type; else null.</returns>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static string GetHostType(string hostName, Nequeo.Xml.Authorisation.Communication.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Get the host reference.
                    return(host.type);
                }

                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Decrements active connections on the host.
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="context">The communication data.</param>
        internal static void DecrementHostActiveConnections(string hostName, Nequeo.Xml.Authorisation.Communication.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Decrement the active connection count.
                    if (host.activeConnections > 0)
                    {
                        host.activeConnections = host.activeConnections - 1;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Does the host exist.
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>True if the host exists; else false.</returns>
        public static bool HostExists(string hostName, Nequeo.Xml.Authorisation.Communication.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Return true the host exists.
                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Remove the host.
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>The object containing the new data; else null.</returns>
        public static bool RemoveHost(string hostName, Nequeo.Xml.Authorisation.Communication.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Find the index of the hosts to remove.
                    context.hosts = context.hosts.Remove(u => u.Equals(host));

                    // Save the new data.
                    SaveCommunicationDataAsync(context);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Set the host index number.
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="index">The host index number.</param>
        /// <param name="context">The communication data.</param>
        public static void SetHostIndex(string hostName, int index, Nequeo.Xml.Authorisation.Communication.Data.context context)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }
            if (index < 1)
            {
                throw new IndexOutOfRangeException("A valid index must be supplied.");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Get the host reference.
                    host.index = index;

                    // Save the new data.
                    SaveCommunicationDataAsync(context);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Add a new host
        /// </summary>
        /// <param name="hostName">The unique host name.</param>
        /// <param name="index">The index number of the host.</param>
        /// <param name="domain">The domain of the host.</param>
        /// <param name="type">The host type.</param>
        /// <param name="context">The communication data.</param>
        /// <param name="activeConnections">The number of active connection on the host.</param>
        /// <returns>The object containing the new data; else null.</returns>
        public static bool AddHost(string hostName, int index, string domain, string type,
                                   Nequeo.Xml.Authorisation.Communication.Data.context context, int activeConnections = 0)
        {
            // Validate.
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }
            if (String.IsNullOrEmpty(domain))
            {
                throw new ArgumentNullException("domain");
            }
            if (index < 1)
            {
                throw new IndexOutOfRangeException("A valid index must be supplied.");
            }

            try
            {
                // Find all host unique identifier.
                Communication.Data.contextHost host = null;

                try
                {
                    host = context.hosts.First(u => u.name.ToLower() == hostName.ToLower());
                }
                catch { }

                if (host != null)
                {
                    // Get the host reference.
                    host.index             = index;
                    host.domain            = domain;
                    host.activeConnections = (activeConnections < 0 ? 0 : activeConnections);
                    host.type = (!String.IsNullOrEmpty(type) ? type : "");

                    // Save the new data.
                    SaveCommunicationDataAsync(context);
                    return(true);
                }
                else
                {
                    // Load all the hosts into a temp list.
                    List <Communication.Data.contextHost> tempHosts = new List <Communication.Data.contextHost>(context.hosts);
                    Communication.Data.contextHost        hostData  = new Communication.Data.contextHost()
                    {
                        name              = hostName,
                        index             = index,
                        domain            = domain,
                        activeConnections = (activeConnections < 0 ? 0 : activeConnections),
                        type              = (!String.IsNullOrEmpty(type) ? type : ""),
                    };

                    // Add the host from the list.
                    tempHosts.Add(hostData);

                    // Assign the new host list to the
                    // new context data.
                    context.hosts = tempHosts.ToArray();

                    // Save the new data.
                    SaveCommunicationDataAsync(context);
                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }