public void UpdateHosts(object selectedItems) { Debug.WriteLine("Update triggered"); var itemsFromList = (System.Collections.IList)selectedItems; ObservableCollection <Server> serversToUpdate = new ObservableCollection <Server>(); WMIManager wm = new WMIManager(); foreach (Server server in itemsFromList) { serversToUpdate.Add(server); } foreach (Server server in serversToUpdate) { Server hostValues = wm.WMICall(server.Name.Trim()); if (hostValues != null) { ServerList.Remove(server); DalManager.Instance.DeleteServer(server); // Validation variable for checking if the server is inside the list or not. bool serverInList = false; // Lets check if the server is in the list already foreach (Server s in serverList) { // We need to trim since s.Name is equal 250 length "DONT KNOW WHY" if (hostValues.Name == s.Name.Trim()) { serverInList = true; } } if (!serverInList) { Debug.WriteLine("We are in here"); hostValues.Status = "Prod"; Server updatedServer = DalManager.Instance.CheckServer(hostValues); serverList.Add(updatedServer); } } } }
public void AddNewHost(object obj) { // Collecting information on the typed hostname or IP with WMIManager. // Then we set the returned server object to ours. // Making sure that we have a value to search for. if (!string.IsNullOrEmpty(server.Name)) { // Validation variable for checking if the server is inside the list or not. bool serverInList = false; WMIManager wm = new WMIManager(); Server hostValues = wm.WMICall(server.Name); // Handling if WMI failes to get values from host if (hostValues != null) { // Lets check if the server is in the list already foreach (Server s in serverList) { // We need to trim since s.Name is equal 250 length "DONT KNOW WHY" if (hostValues.Name == s.Name.Trim()) { serverInList = true; } } // If the server is not in the list, we create it in DB and adds it to the list if (!serverInList) { server = hostValues; server.Status = "Prod"; server = DalManager.Instance.CheckServer(server); serverList.Add(server); } } } }