コード例 #1
0
    public DeskbandTestWindow(
        ILoggerFactory loggerFactory,
        LogLevelSignal logLevelSignal,
        IAppSettingsService appSettingsService,
        CrossProcessSignal processSignal)
    {
        if (loggerFactory == null)
        {
            throw new ArgumentNullException(nameof(loggerFactory));
        }

        this._logLevelSignal     = logLevelSignal ?? throw new ArgumentNullException(nameof(logLevelSignal));
        this._appSettingsService = appSettingsService
                                   ?? throw new ArgumentNullException(nameof(appSettingsService));
        this._processSignal = processSignal ?? throw new ArgumentNullException(nameof(processSignal));
        this._log           = loggerFactory.CreateLogger(this.GetType().Name);

        this.InitializeComponent();

        this._control = new DeskbandControl(loggerFactory);
        this.Content  = this._control;

        this.Reload();
        this._control.Loaded += this.HandleControlLoaded;
    }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: rwasef1830/MonBand
    protected override void OnStartup(StartupEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException(nameof(e));
        }

        try
        {
            base.OnStartup(e);

            var appSettingsService = new AppSettingsService();
            var processSignal      = new CrossProcessSignal(IAppSettingsService.ReloadEventName);

            if (e.Args.FirstOrDefault() == "deskband-test")
            {
                this._loggerFactory = LoggerConfiguration.CreateLoggerFactory(
                    LogLevel.Information,
                    appSettingsService.GetLogFilePath("DeskbandTest"),
                    this._logLevelSignal);
                this._log = this._loggerFactory.CreateLogger(this.GetType().Name);

                this.MainWindow = new DeskbandTestWindow(
                    this._loggerFactory,
                    this._logLevelSignal,
                    appSettingsService,
                    processSignal);
            }
            else
            {
                this._loggerFactory = LoggerConfiguration.CreateLoggerFactory(
                    LogLevel.Information,
                    appSettingsService.GetLogFilePath("Settings"),
                    this._logLevelSignal);
                this._log = this._loggerFactory.CreateLogger(this.GetType().Name);

                this.MainWindow = new SettingsWindow(
                    this._loggerFactory,
                    this._logLevelSignal,
                    appSettingsService,
                    processSignal);
            }

            this.MainWindow.Show();
        }
        catch (Exception ex)
        {
            this._log?.LogError(ex, "MonBand initialization failed");
            MessageBox.Show(
                ex.Message,
                "MonBand initialization failed",
                MessageBoxButton.OK,
                MessageBoxImage.Error);
        }
    }
コード例 #3
0
    public Deskband()
    {
        this._appSettingsService = new AppSettingsService();
        this._logLevelSignal     = new LogLevelSignal();
        this._loggerFactory      = LoggerConfiguration.CreateLoggerFactory(
            LogLevel.Information,
            this._appSettingsService.GetLogFilePath("Deskband"),
            this._logLevelSignal);
        this._log           = this._loggerFactory.CreateLogger(this.GetType().Name);
        this._processSignal = new CrossProcessSignal(IAppSettingsService.ReloadEventName);
        this._control       = null !;

        try
        {
            var appSettings = this._appSettingsService.LoadOrCreate <SettingsModel>();
            this._logLevelSignal.Update(appSettings.LogLevel);

            this._control  = new DeskbandControl(this._loggerFactory);
            this.UIElement = this._control;

            this.Options.MinHorizontalSize = new Size(150, 30);
            this.Options.HorizontalSize    = new Size(150, 30);
            this.Options.MinVerticalSize   = new Size(60, 150);
            this.Options.VerticalSize      = new Size(60, 150);
            this.Options.Title             = "MonBand";
            this.Options.ShowTitle         = false;
            this.Options.IsFixed           = false;
            this.Options.HeightIncrement   = 1;
            this.Options.HeightCanChange   = true;

            this.Reload();
            this._control.Loaded += this.HandleControlLoaded;
        }
        catch (Exception ex)
        {
            this._log.LogError(ex, "MonBand initialization failed");
            MessageBox.Show(
                ex.ToString(),
                "Failed to load MonBand Deskband",
                MessageBoxButton.OK,
                MessageBoxImage.Error);
        }
    }
コード例 #4
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);
    }