-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachineCloneWindow.xaml.cs
More file actions
151 lines (139 loc) · 7.02 KB
/
Copy pathMachineCloneWindow.xaml.cs
File metadata and controls
151 lines (139 loc) · 7.02 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System.Windows;
using DanteConfigEditor.Models;
using DanteConfigEditor.Services;
namespace DanteConfigEditor;
public partial class MachineCloneWindow : Window
{
private readonly UiLanguage _language;
public MachineCloneWindow(
UiLanguage language,
bool useLightTheme,
string sourceName,
string suggestedName)
{
InitializeComponent();
_language = language;
DialogThemeService.Apply(this, useLightTheme);
NewNameTextBox.Text = suggestedName;
ApplyLanguage(sourceName);
NewNameTextBox.SelectAll();
NewNameTextBox.Focus();
}
public MachineCloneOptions? Options { get; private set; }
private void ApplyLanguage(string sourceName)
{
Title = L("Dupliquer la machine", "Duplicate device");
HeadingTextBlock.Text = Title;
IntroTextBlock.Text = L(
$"Créer un rôle indépendant à partir de « {sourceName} ».",
$"Create an independent role from “{sourceName}”.");
NewNameLabel.Content = L("Nouveau nom", "New name");
NameRulesTextBlock.Text = L(
"31 caractères maximum : lettres, chiffres et tirets, sans espace.",
"Maximum 31 characters: letters, digits and hyphens, without spaces.");
LabelsGroupBox.Header = L("Labels de canaux", "Channel labels");
PreserveTxLabelsCheckBox.Content = L("Conserver les labels TX", "Keep Tx labels");
PreserveRxLabelsCheckBox.Content = L("Conserver les labels RX", "Keep Rx labels");
SettingsGroupBox.Header = L("Paramètres", "Settings");
PreserveSettingsCheckBox.Content = L(
"Conserver sample rate, encodage et latence",
"Keep sample rate, encoding and latency");
PreservePreferredMasterCheckBox.Content = L(
"Conserver Preferred Master",
"Keep Preferred Master");
AdvancedGroupBox.Header = L("Options avancées", "Advanced options");
PreserveNetworkCheckBox.Content = L(
"Conserver les interfaces et adresses réseau",
"Keep network interfaces and addresses");
PreserveSubscriptionsCheckBox.Content = L(
"Conserver les subscriptions RX de cette machine",
"Keep this device's Rx subscriptions");
PreserveFlowsCheckBox.Content = L(
"Conserver les flows multicast TX",
"Keep Tx multicast flows");
AdvancedWarningTextBlock.Text = L(
"Ces options peuvent recopier des adresses ou références propres au projet source. "
+ "La validation bloquera les incohérences détectées.",
"These options may copy addresses or references specific to the source project. "
+ "Validation will block detected inconsistencies.");
IdentityNoticeTextBlock.Text = L(
"L'identité matérielle n'est jamais copiée. La nouvelle machine sera un rôle générique hors ligne.",
"Hardware identity is never copied. The new device will be a generic offline role.");
DuplicateButton.Content = L("Dupliquer", "Duplicate");
CancelButton.Content = L("Annuler", "Cancel");
NewNameTextBox.ToolTip = L(
"Nom de la copie dans ce projet. Le nom de la machine source reste inchangé.",
"Name of the copy in this project. The source device name remains unchanged.");
PreserveTxLabelsCheckBox.ToolTip = L(
"Recopie les noms actuels des canaux TX dans la nouvelle machine.",
"Copies the current Tx channel names to the new device.");
PreserveRxLabelsCheckBox.ToolTip = L(
"Recopie les noms actuels des canaux RX dans la nouvelle machine.",
"Copies the current Rx channel names to the new device.");
PreserveSettingsCheckBox.ToolTip = L(
"Recopie uniquement les réglages audio génériques : fréquence, encodage et latence.",
"Copies only generic audio settings: sample rate, encoding and latency.");
PreservePreferredMasterCheckBox.ToolTip = L(
"Conserve le statut Preferred Master. À utiliser seulement si ce choix reste cohérent dans le projet.",
"Keeps Preferred Master status. Use only when this remains consistent in the project.");
PreserveNetworkCheckBox.ToolTip = L(
"Option avancée : recopie les interfaces et adresses. La validation bloque les doublons détectés.",
"Advanced option: copies interfaces and addresses. Validation blocks detected duplicates.");
PreserveSubscriptionsCheckBox.ToolTip = L(
"Option avancée : recopie les sources affectées aux RX de la machine.",
"Advanced option: copies sources assigned to this device's Rx channels.");
PreserveFlowsCheckBox.ToolTip = L(
"Option avancée : recopie les définitions de flows multicast TX.",
"Advanced option: copies Tx multicast flow definitions.");
DuplicateButton.ToolTip = L(
"Crée la nouvelle machine sans modifier la machine source.",
"Creates the new device without changing the source device.");
CancelButton.ToolTip = L("Ferme sans dupliquer.", "Closes without duplicating.");
}
private void DuplicateButton_Click(object sender, RoutedEventArgs e)
{
string name = NewNameTextBox.Text.Trim();
string? error = DanteNameRules.ValidateDeviceName(name);
if (error is not null)
{
MessageBox.Show(
this,
_language == UiLanguage.English
? TranslateNameError(error)
: error,
L("Nom invalide", "Invalid name"),
MessageBoxButton.OK,
MessageBoxImage.Error);
return;
}
Options = new MachineCloneOptions
{
NewName = name,
PreserveTxLabels = PreserveTxLabelsCheckBox.IsChecked == true,
PreserveRxLabels = PreserveRxLabelsCheckBox.IsChecked == true,
PreserveDeviceSettings = PreserveSettingsCheckBox.IsChecked == true,
PreserveNetworkConfiguration = PreserveNetworkCheckBox.IsChecked == true,
PreserveSubscriptions = PreserveSubscriptionsCheckBox.IsChecked == true,
PreserveMulticastFlows = PreserveFlowsCheckBox.IsChecked == true,
PreservePreferredMaster = PreservePreferredMasterCheckBox.IsChecked == true
};
DialogResult = true;
}
private string TranslateNameError(string error)
{
if (error.Contains("obligatoire", StringComparison.OrdinalIgnoreCase))
{
return "The device name is required.";
}
if (error.Contains("31", StringComparison.Ordinal))
{
return "The device name must not exceed 31 characters.";
}
return "The device name may only contain letters, digits and hyphens, "
+ "and may not start or end with a hyphen.";
}
private string L(string french, string english)
{
return _language == UiLanguage.English ? english : french;
}
}