/// <summary> /// This method is used to delete a client application from NGRID while NGRID is running. /// Used by NGRIDController to allow user to remove an application from NGRIDManager GUI. /// It does all necessary tasks to remove application (Updates XML file, removes application from needed /// collections of system...). /// </summary> /// <param name="name">Name of the application to remove</param> /// <returns>Removed client application</returns> public NGRIDClientApplication RemoveApplication(string name) { //Remove from application list and communicaton layer NGRIDClientApplication clientApplication = null; lock (_clientApplicationList.Applications) { if (_clientApplicationList.Applications.ContainsKey(name)) { clientApplication = _clientApplicationList.Applications[name]; if (clientApplication.ConnectedCommunicatorCount > 0) { throw new NGRIDException("Client application can not be removed. It has " + clientApplication.ConnectedCommunicatorCount + " communicators connected. Please stop theese communicators first."); } clientApplication.MessageReceived -= RemoteApplication_MessageReceived; _communicationLayer.RemoveRemoteApplication(clientApplication); _clientApplicationList.Applications.Remove(name); } } if (clientApplication == null) { throw new NGRIDException("There is no client application with name " + name); } clientApplication.Stop(true); //Remove from settings lock (_settings.Applications) { for (var i = 0; i < _settings.Applications.Count; i++) { if (_settings.Applications[i].Name.Equals(name, StringComparison.OrdinalIgnoreCase)) { _settings.Applications.RemoveAt(i); _settings.SaveToXml(); break; } } } return(clientApplication); }