/// <summary> /// Remove the single context item. /// </summary> /// <param name="context">The single context to remove from the list.</param> /// <exception cref="System.ArgumentNullException"></exception> public void Remove(Nequeo.Net.Provider.ISingleContextBase context) { if (context == null) { throw new ArgumentNullException("context"); } lock (_lockObject) { try { long index = -1; // For each context item foreach (KeyValuePair <long, Nequeo.Net.Provider.ISingleContextBase> item in _contextList) { // If the contexts are equal. if (item.Value.Equals(context)) { // Get the item index // and stop the search. index = item.Key; break; } } // Remove the item. if (index > -1) { _contextList.Remove(index); } } catch { } } }
/// <summary> /// Add the single context item. /// </summary> /// <param name="context">The single context to add to the list.</param> /// <exception cref="System.Exception"></exception> /// <exception cref="System.ArgumentNullException"></exception> public void Add(Nequeo.Net.Provider.ISingleContextBase context) { if (context == null) { throw new ArgumentNullException("context"); } lock (_lockObject) { _index++; // Add the item. _contextList.Add(_index, context); } }
/// <summary> /// On client diconnected. /// </summary> /// <param name="context">The client context.</param> private async void ClientDisconnectedEx(Nequeo.Net.Provider.ISingleContextBase context) { await Nequeo.Threading.AsyncOperationResult <bool> . RunTask(() => { lock (_lockObject) { try { // Get the client. Nequeo.Net.Data.ConnectionContext conn = _clients[context.ConnectionID]; // Close the connection. Nequeo.Net.NetClient client = conn.Client; client.Dispose(); // Remove the client. _clients.Remove(context.ConnectionID); // Decrement the server count. Find the current load balance server // this client is connected to. IEnumerable <Data.contextServer> balanceServers = _loadServers.servers.Where(u => u.name.ToLower() == conn.LoadBalanceServer.ToLower()); // If the server has been found. if (balanceServers.Count() > 0) { // Get the first server. Data.contextServer balanceServer = balanceServers.First(); // Get the current client count. int currentCount = balanceServer.count; // If the current count is not zero // then decrement to count else do // not go less than zero. if (currentCount > 0) { balanceServer.count = currentCount - 1; } } } catch { } } }); }
/// <summary> /// The action to perform. /// </summary> /// <param name="state">The state object passed.</param> private void ActionMethod(object state) { lock (_lockObject) { // For each context item foreach (KeyValuePair <long, Net.Sockets.IServerContext> item in _contextList) { try { // Get the current server context. Net.Sockets.IServerContext current = item.Value; if (current != null) { // If the context has timed out // then close the connection. if (current.HasTimedOut(_timeout)) { current.Close(); } } } catch { } } // For each context item foreach (KeyValuePair <long, Nequeo.Net.IMemberContext> item in _memberList) { try { // Get the current server context. Nequeo.Net.IMemberContext current = item.Value; if (current != null) { // If the context has timed out // then close the connection. if (current.HasTimedOut(_timeout)) { current.Close(); } } } catch { } } // For each context item foreach (KeyValuePair <long, Nequeo.Net.Provider.ISingleContextBase> item in _singleList) { try { // Get the current server context. Nequeo.Net.Provider.ISingleContextBase current = item.Value; if (current != null) { // If the context has timed out // then close the connection. if (current.HasTimedOut(_timeout)) { current.Close(); } } } catch { } } } }
/// <summary> /// On client diconnected. /// </summary> /// <param name="context">The client context.</param> private void ClientDisconnected(Nequeo.Net.Provider.ISingleContextBase context) { // Remove the client. ClientDisconnectedEx(context); }