TeamsNetphoneLink/TeamsNetphoneLinkWPF/WPF/MVVM/DashboardViewModel.cs
2025-03-25 22:43:13 +01:00

250 lines
7.6 KiB
C#

using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Media;
namespace TeamsNetphoneLink.WPF.MVVM
{
public static class StatusPanelNames
{
public const string TeamsLocalAPIStatus = nameof(TeamsLocalAPIStatus);
public const string TeamsGraphAPIStatus = nameof(TeamsGraphAPIStatus);
public const string NetphoneCLMGRStatus = nameof(NetphoneCLMGRStatus);
public const string TeamsMeetingStatus = nameof(TeamsMeetingStatus);
public const string NetphoneCallStatus = nameof(NetphoneCallStatus);
}
public class DashboardViewModel : INotifyPropertyChanged
{
// Parameterloser Konstruktor
public DashboardViewModel()
{
// Initialisieren Sie hier Standardwerte, falls erforderlich
TeamsLocalAPIStatusText = "Nicht verbunden";
TeamsLocalAPIStatusBackground = new SolidColorBrush(Colors.Red);
TeamsGraphAPIStatusText = "Konfiguration fehlt";
TeamsGraphAPIStatusBackground = new SolidColorBrush(Colors.Red);
NetphoneCLMGRStatusText = "Nicht verbunden";
NetphoneCLMGRStatusBackground = new SolidColorBrush(Colors.Red);
TeamsMeetingStatusText = "Not Active";
TeamsMeetingStatusBackground = new SolidColorBrush(Colors.DarkOrange);
NetphoneCallStatusText = "Not Active";
NetphoneCallStatusBackground = new SolidColorBrush(Colors.DarkOrange);
AppTitle2 = "Teams Netphone Link";
VersionText = "Aktuell";
VersionVisibility = Visibility.Visible;
VersionBackground = new SolidColorBrush(Colors.Green);
}
private string _appTitle;
private string _versionText;
private Visibility _versionVisibility;
private Brush _versionBackground;
private string _teamsLocalAPIStatusText;
private Brush _teamsLocalAPIStatusBackground;
private string _teamsGraphAPIStatusText;
private Brush _teamsGraphAPIStatusBackground;
private string _netphoneCLMGRStatusText;
private Brush _netphoneCLMGRStatusBackground;
private string _teamsMeetingStatusText;
private Brush _teamsMeetingStatusBackground;
private string _netphoneCallStatusText;
private Brush _netphoneCallStatusBackground;
public string TeamsLocalAPIStatusText
{
get => _teamsLocalAPIStatusText;
set
{
_teamsLocalAPIStatusText = value;
OnPropertyChanged();
}
}
public Brush TeamsLocalAPIStatusBackground
{
get => _teamsLocalAPIStatusBackground;
set
{
_teamsLocalAPIStatusBackground = value;
OnPropertyChanged();
}
}
public string TeamsGraphAPIStatusText
{
get => _teamsGraphAPIStatusText;
set
{
_teamsGraphAPIStatusText = value;
OnPropertyChanged();
}
}
public Brush TeamsGraphAPIStatusBackground
{
get => _teamsGraphAPIStatusBackground;
set
{
_teamsGraphAPIStatusBackground = value;
OnPropertyChanged();
}
}
public string NetphoneCLMGRStatusText
{
get => _netphoneCLMGRStatusText;
set
{
_netphoneCLMGRStatusText = value;
OnPropertyChanged();
}
}
public Brush NetphoneCLMGRStatusBackground
{
get => _netphoneCLMGRStatusBackground;
set
{
_netphoneCLMGRStatusBackground = value;
OnPropertyChanged();
}
}
public string TeamsMeetingStatusText
{
get => _teamsMeetingStatusText;
set
{
_teamsMeetingStatusText = value;
OnPropertyChanged();
}
}
public Brush TeamsMeetingStatusBackground
{
get => _teamsMeetingStatusBackground;
set
{
_teamsMeetingStatusBackground = value;
OnPropertyChanged();
}
}
public string NetphoneCallStatusText
{
get => _netphoneCallStatusText;
set
{
_netphoneCallStatusText = value;
OnPropertyChanged();
}
}
public Brush NetphoneCallStatusBackground
{
get => _netphoneCallStatusBackground;
set
{
_netphoneCallStatusBackground = value;
OnPropertyChanged();
}
}
public string AppTitle2
{
get => _appTitle;
set
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
_appTitle = value;
OnPropertyChanged();
});
}
}
public string VersionText
{
get => _versionText;
set
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
_versionText = value;
OnPropertyChanged();
});
}
}
public Visibility VersionVisibility
{
get => _versionVisibility;
set
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
_versionVisibility = value;
OnPropertyChanged();
});
}
}
public Brush VersionBackground
{
get => _versionBackground;
set
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
_versionBackground = value;
OnPropertyChanged();
});
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
// Method to update status panel
public void UpdateStatusPanel(string statusPanelName, Color color, string text)
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
// Get the type of the ViewModel
var type = GetType();
// Construct property names for Text and Background
string textPropertyName = $"{statusPanelName}Text";
string backgroundPropertyName = $"{statusPanelName}Background";
// Get the properties using reflection
PropertyInfo textProperty = type.GetProperty(textPropertyName); //CS8600
PropertyInfo backgroundProperty = type.GetProperty(backgroundPropertyName); //CS8600
if (textProperty != null && backgroundProperty != null)
{
// Update the Text property
textProperty.SetValue(this, text);
// Update the Background property
backgroundProperty.SetValue(this, new SolidColorBrush(color));
}
else
{
throw new ArgumentException($"Invalid status panel name: {statusPanelName}");
}
});
}
}
}