Files
IT-Nexus/agent-cs/UI/NotificationWindow.xaml.cs

60 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using ITNexusAgent.Models;
using ITNexusAgent.Services;
using System.Windows;
using System.Windows.Media;
namespace ITNexusAgent.UI;
public partial class NotificationWindow : Window
{
private readonly Announcement _ann;
private readonly ApiService? _api;
public NotificationWindow(Announcement ann)
{
InitializeComponent();
_ann = ann;
var (hex, label, icon) = ann.Type switch
{
"warning" => ("#DC3545", "WICHTIGE WARNUNG", "⚠️"),
"maintenance" => ("#E67E22", "WARTUNGSANKÜNDIGUNG", "🔧"),
_ => ("#5865F2", "INFORMATION", ""),
};
var color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(hex);
var brush = new SolidColorBrush(color);
var iconBg = new SolidColorBrush(System.Windows.Media.Color.FromArgb(40, color.R, color.G, color.B));
TopAccent.Background = brush;
IconBox.Background = iconBg;
IconBox.BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(80, color.R, color.G, color.B));
IconBox.BorderThickness = new Thickness(1);
IconText.Text = icon;
TypeLabel.Text = label;
TypeLabel.Foreground = brush;
TitleText.Text = ann.Title;
MessageText.Text = ann.Message;
ConfirmButton.Background = brush;
MetaText.Text = $"IT Nexus Mitteilung";
try
{
var cfg = AgentConfig.Load(@"C:\ProgramData\IT Nexus Agent\config.json");
_api = new ApiService(cfg.ServerUrl, cfg.AgentKey);
}
catch { }
}
private async void ConfirmButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (_api != null)
await _api.AckAnnouncementAsync(_ann.Id, Environment.MachineName);
}
catch { }
Close();
}
}