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 MainWindow() { App.logger.Info($"{Assembly.GetExecutingAssembly().GetName().Name} - v{Assembly.GetExecutingAssembly().GetName().Version}"); InitializeComponent(); // Detail panels computerDetails.mainWindow = this; computersDetails.mainWindow = this; // Error panel errorHandler = new ErrorHandlerWindow(); errorHandler.warningIndicator = WarningImage; // Error panel configurationHandler = new ConfigurationWindow(); // App level exception handler Application.Current.DispatcherUnhandledException += (sender, e) => { errorHandler.addError(e.Exception); e.Handled = true; }; // Auto updater var timer = new DispatcherTimer(); timer.Tick += async(source, e) => { timer.Stop(); try { await updateListComputers(); } catch (Exception ex) { errorHandler.addError(ex); } finally { timer.Start(); } }; timer.Interval = new TimeSpan(0, 0, App.config.getInt("scantimeout", 30)); timer.Start(); }