-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddSingleProcessWindow.xaml.cs
More file actions
116 lines (98 loc) · 4.07 KB
/
AddSingleProcessWindow.xaml.cs
File metadata and controls
116 lines (98 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Windows;
namespace TaskPilot
{
public partial class AddSingleProcessWindow : Window
{
public string ProcessName { get; set; } = string.Empty;
public string DisplayName { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string StartCommand { get; set; } = string.Empty;
public bool AutoRestart { get; set; } = false;
public bool IsSelected { get; set; } = true;
private string _originalProcessName = string.Empty;
public AddSingleProcessWindow()
{
InitializeComponent();
}
public AddSingleProcessWindow(MonitoredProgram program) : this()
{
_originalProcessName = program.ProcessName;
// Felder vorausfüllen
ProcessNameTextBox.Text = program.ProcessName;
DisplayNameTextBox.Text = program.DisplayName;
DescriptionTextBox.Text = program.Description ?? string.Empty;
StartCommandTextBox.Text = program.StartCommand ?? string.Empty;
AutoRestartCheckBox.IsChecked = program.AutoRestart;
IsSelectedCheckBox.IsChecked = program.IsSelected;
// UI anpassen
Title = "Prozess bearbeiten";
TitleTextBlock.Text = "Prozess bearbeiten";
AddButton.Content = "Speichern";
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
private void Add_Click(object sender, RoutedEventArgs e)
{
// Validierung
var processName = ProcessNameTextBox.Text?.Trim() ?? string.Empty;
var displayName = DisplayNameTextBox.Text?.Trim() ?? string.Empty;
var description = DescriptionTextBox.Text?.Trim() ?? string.Empty;
var startCommand = StartCommandTextBox.Text?.Trim() ?? string.Empty;
var autoRestart = AutoRestartCheckBox.IsChecked == true;
var isSelected = IsSelectedCheckBox.IsChecked != false; // default true
if (string.IsNullOrWhiteSpace(processName))
{
DialogHelper.ShowValidationError("Prozessname ist erforderlich.");
ProcessNameTextBox.Focus();
return;
}
if (string.IsNullOrWhiteSpace(displayName))
{
DialogHelper.ShowValidationError("Anzeigename ist erforderlich.");
DisplayNameTextBox.Focus();
return;
}
// Prozessname bereinigen (keine .exe, Leerzeichen trimmen)
processName = processName.Replace(".exe", "", StringComparison.OrdinalIgnoreCase).Trim();
if (processName.Contains(" "))
{
DialogHelper.ShowValidationError("Prozessname darf keine Leerzeichen enthalten.");
ProcessNameTextBox.Focus();
return;
}
if (processName.Length > 255)
{
DialogHelper.ShowValidationError("Prozessname ist zu lang (max. 255 Zeichen).");
return;
}
if (displayName.Length > 255)
{
DialogHelper.ShowValidationError("Anzeigename ist zu lang (max. 255 Zeichen).");
return;
}
if (autoRestart && string.IsNullOrWhiteSpace(startCommand))
{
DialogHelper.ShowValidationError("Für Auto-Restart muss ein Startbefehl definiert sein.");
StartCommandTextBox.Focus();
return;
}
if (startCommand.Length > 2000)
{
DialogHelper.ShowValidationError("Startbefehl ist zu lang (max. 2000 Zeichen).");
return;
}
ProcessName = processName;
DisplayName = displayName;
Description = description;
StartCommand = startCommand;
AutoRestart = autoRestart;
IsSelected = isSelected;
DialogResult = true;
Close();
}
}
}