コード例 #1
0
    public SettingsWindow(
        ILoggerFactory loggerFactory,
        LogLevelSignal logLevelSignal,
        IAppSettingsService appSettingsService,
        CrossProcessSignal processSignal)
    {
        this.LoggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));

        if (appSettingsService == null)
        {
            throw new ArgumentNullException(nameof(appSettingsService));
        }

        if (processSignal == null)
        {
            throw new ArgumentNullException(nameof(processSignal));
        }

        this.Settings = appSettingsService.LoadOrCreate <SettingsModel>();
        logLevelSignal.Update(this.Settings.LogLevel);

        this.LogLevels = Enum.GetValues(typeof(LogLevel)).Cast <LogLevel>().ToList();

        this.SaveAndApplyConfigurationCommand = new DelegateCommand(
            _ =>
        {
            this.Settings.SnmpPollers = this.SnmpMonitors.Pollers.ToList();
            this.Settings.PerformanceCounterPollers = this.PerformanceCounterMonitors.Pollers.ToList();
            appSettingsService.Save(this.Settings);
            logLevelSignal.Update(this.Settings.LogLevel);
            processSignal.Signal();
            this.Close();
        });
        this.ExitCommand = new DelegateCommand(_ => this.Close());

        this.InitializeComponent();

        this.SnmpMonitors.Pollers = new ObservableCollection <SnmpPollerConfig>(this.Settings.SnmpPollers);
        this.PerformanceCounterMonitors.Pollers =
            new ObservableCollection <PerformanceCounterPollerConfig>(this.Settings.PerformanceCounterPollers);
    }