Пример #1
0
        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {
            var nicName = this.comboBoxAvailableNetworkInterfaces.SelectedItem as string;
            var enableNetworkLoadTotal    = this.checkBoxEnableNetworkLoadTotal.IsChecked.Value;
            var enableNetworkLoadSent     = this.checkBoxEnableNetworkLoadSent.IsChecked.Value;
            var enableNetworkLoadReceived = this.checkBoxEnableNetworkLoadReceived.IsChecked.Value;
            var networkLoadTotal          = this.upDownNetworkLoadTotal.Value.Value;
            var networkLoadReceived       = this.upDownNetworkLoadReceived.Value.Value;
            var networkLoadSent           = this.upDownNetworkLoadSent.Value.Value;

            var nic = new NetworkInterfaceToMonitor();

            nic.NetworkInterface = nicName;
            nic.EnableCheckNetworkLoadDownload = enableNetworkLoadReceived;
            nic.EnableCheckNetworkLoadUpload   = enableNetworkLoadSent;
            nic.EnableCheckNetworkLoadTotal    = enableNetworkLoadTotal;
            nic.NetworkLoadDownload            = networkLoadReceived;
            nic.NetworkLoadUpload = networkLoadSent;
            nic.NetworkLoadTotal  = networkLoadTotal;

            // Avoid to add a element twice.
            if (this.editNetworkInterfaceToMonitor == null)
            {
                // Add new mode.
                if (this.allNetworkInterfaces != null)
                {
                    for (int i = 0; i < this.allNetworkInterfaces.Length; i++)
                    {
                        if (this.allNetworkInterfaces[i] == nic)
                        {
                            MessageBox.Show(String.Format(Wsapm.Resources.Wsapm.AddNetworkInterfaceWindow_NetworkInterfaceAlreadyAdded, nic.NetworkInterface), Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                }
            }
            else
            {
                // Edit mode.
                if (nic != this.editNetworkInterfaceToMonitor)
                {
                    // Element was changed.
                    if (this.allNetworkInterfaces != null)
                    {
                        for (int i = 0; i < this.allNetworkInterfaces.Length; i++)
                        {
                            if (this.allNetworkInterfaces[i] == nic)
                            {
                                MessageBox.Show(String.Format(Wsapm.Resources.Wsapm.AddNetworkInterfaceWindow_NetworkInterfaceAlreadyAdded, nic.NetworkInterface), Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }
                        }
                    }
                }
            }

            this.networkInterfaceToMonitor = nic;
            this.DialogResult = true;
            this.Close();
        }
Пример #2
0
 public AddNetworkInterfaceWindow(NetworkInterfaceToMonitor networkInterfaceToMonitorToEdit, NetworkInterfaceToMonitor[] allNetworkInterfaces)
     : this(allNetworkInterfaces)
 {
     this.Title = Wsapm.Resources.Wsapm.AddNetworkInterfaceWindow_TitleEdit;
     this.editNetworkInterfaceToMonitor = networkInterfaceToMonitorToEdit.Copy();
 }