/// <summary> /// Add the active model. /// </summary> /// <param name="machineName">The name of the machine the client is connected to.</param> /// <param name="model">The active connection model.</param> /// <exception cref="System.Exception"></exception> /// <exception cref="System.ArgumentNullException"></exception> public void AddActive(string machineName, ActiveConnectionModel model) { if (String.IsNullOrEmpty(machineName)) { throw new ArgumentNullException("machineName"); } if (model == null) { throw new ArgumentNullException("model"); } lock (_lockActiveObject) { // Add the item. _activeList.Add(machineName, model); } }
/// <summary> /// Combine all active receiver hosts. /// </summary> /// <param name="model">The active connection model.</param> /// <returns>The collection of receiver hosts.</returns> public string[] CombineReceiverHosts(ActiveConnectionModel model) { if (model == null) { return(null); } List <string> differenceList = new List <string>(); // For each host model add all the receivers. foreach (SendToHostModel item in model.Hosts) { differenceList.Add(item.Host); } // Get the combined list. return(differenceList.Count > 0 ? differenceList.ToArray() : null); }
/// <summary> /// Find the active model. /// </summary> /// <param name="machineName">The name of the machine the client is connected to.</param> /// <returns>The active model; else null.</returns> public ActiveConnectionModel FindActive(string machineName) { if (String.IsNullOrEmpty(machineName)) { throw new ArgumentNullException("machineName"); } // Attempt to find the client for the machine name. ActiveConnectionModel model = null; bool ret = _activeList.TryGetValue(machineName, out model); if (ret) { return(model); } else { return(null); } }
// 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; } }