public static async Task <DomainModel> createDomainModel(Domain domain, ErrorHandlerWindow erroHandler)
        {
            DomainModel domainModel = new DomainModel()
            {
                name = domain.name
            };

            foreach (Computer c in domain.computers)
            {
                domainModel.addComputer(new ComputerModel()
                {
                    computer = c
                });

                // If the computer is alive, save its values in the database
                if (c.isAlive)
                {
                    try {
                        var info = App.computerInfoStore.getComputerInfoByName(c.nameLong);

                        if (info == null || (DateTime.Now - info.lastUpdate).TotalDays > 30)
                        {
                            App.computerInfoStore.updateOrInsertComputerInfo(new ComputerInfo()
                            {
                                name       = c.nameLong,
                                ipAddress  = c.getIpAddress().ToString(),
                                macAddress = await c.getMacAddress(),
                                lastUpdate = DateTime.Now
                            });
                        }
                    } catch (Exception e) {
                        erroHandler.addError(e);
                    }
                }
            }

            foreach (Domain d in domain.domains)
            {
                domainModel.addDomain(await createDomainModel(d, erroHandler));
            }

            return(domainModel);
        }
        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);
        }