Ejemplo n.º 1
0
        /// <summary>
        /// Add the client item.
        /// </summary>
        /// <param name="machineName">The name of the machine the client is connected to.</param>
        /// <param name="client">The client connected to the machine.</param>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void AddClient(string machineName, Nequeo.Client.Manage.IInteractionClient client)
        {
            if (String.IsNullOrEmpty(machineName))
            {
                throw new ArgumentNullException("machineName");
            }
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            lock (_lockClientObject)
            {
                // Add the item.
                _clientList.Add(machineName, client);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find the client.
        /// </summary>
        /// <param name="machineName">The name of the machine the client is connected to.</param>
        /// <returns>The client; else null.</returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        public Nequeo.Client.Manage.IInteractionClient FindClient(string machineName)
        {
            if (String.IsNullOrEmpty(machineName))
            {
                throw new ArgumentNullException("machineName");
            }

            // Attempt to find the client for the machine name.
            Nequeo.Client.Manage.IInteractionClient client = null;
            bool ret = _clientList.TryGetValue(machineName, out client);

            if (ret)
            {
                return(client);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Remove the client item.
        /// </summary>
        /// <param name="machineName">The name of the machine the client is connected to.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void RemoveClient(string machineName)
        {
            if (String.IsNullOrEmpty(machineName))
            {
                throw new ArgumentNullException("machineName");
            }

            lock (_lockClientObject)
            {
                // Find the client.
                Nequeo.Client.Manage.IInteractionClient client = FindClient(machineName);
                if (client != null)
                {
                    // Close the connection.
                    client.Close();
                    client.Dispose();
                }

                // Remove the item.
                _clientList.Remove(machineName);
            }
        }
Ejemplo n.º 4
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    if (_clientList != null)
                    {
                        // Close and dispose of all connections.
                        foreach (KeyValuePair <string, Nequeo.Client.Manage.IInteractionClient> item in _clientList)
                        {
                            if (item.Value != null)
                            {
                                try
                                {
                                    item.Value.Close();
                                    item.Value.Dispose();
                                }
                                finally
                                {
                                    Nequeo.Client.Manage.IInteractionClient client = item.Value;
                                    client = null;
                                }
                            }
                        }
                    }

                    if (_activeList != null)
                    {
                        // Close and dispose of all connections.
                        foreach (KeyValuePair <string, ActiveConnectionModel> item in _activeList)
                        {
                            if (item.Value != null)
                            {
                                try
                                {
                                    // For each host.
                                    foreach (SendToHostModel host in item.Value.Hosts)
                                    {
                                        try
                                        {
                                            // Release the reference.
                                            host.Host      = null;
                                            host.Receivers = null;
                                        }
                                        catch { }
                                    }
                                    SendToHostModel[] hosts = item.Value.Hosts;
                                    hosts = null;

                                    // For each port.
                                    foreach (SendToPortModel port in item.Value.Ports)
                                    {
                                        try
                                        {
                                            // Release the reference.
                                            port.Name = null;
                                        }
                                        catch { }
                                    }
                                    SendToPortModel[] ports = item.Value.Ports;
                                    ports = null;
                                }
                                finally
                                {
                                    ActiveConnectionModel model = item.Value;
                                    model = null;
                                }
                            }
                        }
                    }

                    // Dispose managed resources.
                    if (_clientList != null)
                    {
                        _clientList.Clear();
                    }

                    if (_activeList != null)
                    {
                        _activeList.Clear();
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _clientList       = null;
                _activeList       = null;
                _lockClientObject = null;
                _lockActiveObject = null;
            }
        }