public static bool updateComputerModel(DomainModel domainModel, Computer computer) { bool needRefresh = false; // Update & adding of new computers foreach (var computerModel in domainModel.getComputers()) { if (computerModel.computer.nameLong == computer.nameLong) { if (computer.isAlive != computerModel.computer.isAlive) { needRefresh = true; } computerModel.computer = computer; return(needRefresh); } } foreach (var subdomainModel in domainModel.getDomains()) { if ((needRefresh = (needRefresh || updateComputerModel(subdomainModel, computer)))) { return(needRefresh); } } return(needRefresh); }
public static bool updateDomainModel(DomainModel oldDomainModel, DomainModel domainModel, bool showOnComputers, bool showOffComputers, System.Collections.IList selectedComputers) { bool needRefresh = false; // Update & adding of new computers foreach (var computerModel in domainModel.getComputers()) { var oldComputerModel = oldDomainModel.getComputer(computerModel.computer.name); if (oldComputerModel != null) { if ((computerModel.computer.isAlive && showOnComputers) || (!computerModel.computer.isAlive && showOffComputers)) { // If an update is needed if (oldComputerModel.computer.isAlive != computerModel.computer.isAlive) { foreach (var item in selectedComputers) { if (item is ComputerModel && (item as ComputerModel).computer.nameLong == computerModel.computer.nameLong) { needRefresh = true; } } } oldComputerModel.computer = computerModel.computer; } else { oldDomainModel.removeComputer(computerModel); } } else if ((computerModel.computer.isAlive && showOnComputers) || (!computerModel.computer.isAlive && showOffComputers)) { oldDomainModel.addComputer(computerModel); } } // Update & adding of new models foreach (var subdomainModel in domainModel.getDomains()) { var oldSubdomainModel = oldDomainModel.getDomain(subdomainModel.name); if (oldSubdomainModel != null) { needRefresh = needRefresh || updateDomainModel(oldSubdomainModel, subdomainModel, showOnComputers, showOffComputers, selectedComputers); } else { oldDomainModel.addDomain(subdomainModel); } } // Removing of old computers foreach (string computerToRemove in oldDomainModel.getComputers().Select(c => c.computer.name). Except(domainModel.getComputers().Select(c => c.computer.name)). ToList()) { oldDomainModel.removeComputer(computerToRemove); } // Removing of old domains foreach (string domainToRemove in oldDomainModel.getDomains().Select(d => d.name). Except(domainModel.getDomains().Select(d => d.name)). ToList()) { oldDomainModel.removeDomain(domainToRemove); } return(needRefresh); }