Exemple #1
0
        private void InitUI()
        {
            string ipFromStr = null;
            string ipToStr   = null;

            Dispatcher.Invoke((Action)(() => ipFromStr = this.textBoxIPFrom.Text));
            Dispatcher.Invoke((Action)(() => ipToStr = this.textBoxIPTo.Text));

            if (!NetworkTools.IsStringIPAddress(ipFromStr))
            {
                MessageBox.Show(Wsapm.Resources.Wsapm.NetworkMachineChoiceWindow_MessageIPFromNoRealIP, Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!NetworkTools.IsStringIPAddress(ipToStr))
            {
                MessageBox.Show(Wsapm.Resources.Wsapm.NetworkMachineChoiceWindow_MessageIPToNoRealIP, Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var ipFrom = IPAddress.Parse(ipFromStr);
            var ipTo   = IPAddress.Parse(ipToStr);

            var ipRange  = NetworkTools.GetIPAddressRange(ipFrom, ipTo);
            var machines = NetworkTools.GetNetworkMachinesInLocalNetworkFromIPAddressRange(ipRange, cancellationTokenSource.Token);

            if (machines == null || machines.Length == 0)
            {
                return;
            }

            //var machines = DecaTec.Toolkit.Tools.NetworkTools.GetComputersInLocalNetwork();
            colView = CollectionViewSource.GetDefaultView(machines);
            Dispatcher.Invoke((Action)(() => this.networkMachineDataGrid.ItemsSource = colView));
            Dispatcher.Invoke((Action)(() => this.networkMachineDataGrid.Items.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending))));
        }
Exemple #2
0
        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {
            var name = this.textBoxName.Text.Trim();
            var ip   = this.textBoxIPAddress.Text;

            var machine = new NetworkMachine();

            if (!string.IsNullOrEmpty(name))
            {
                machine.Name = name;
            }

            if (!string.IsNullOrEmpty(ip))
            {
                if (NetworkTools.IsStringIPAddress(ip))
                {
                    machine.IPAddress = IPAddress.Parse(ip);
                }
                else
                {
                    MessageBox.Show(Wsapm.Resources.Wsapm.AddNetworkMachineWindow_MessageIPNoRealIP, Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            if (string.IsNullOrEmpty(machine.Name) && machine.IPAddress == null)
            {
                MessageBox.Show(String.Format(Wsapm.Resources.Wsapm.AddNetworkMachineWindow_NoInfoError, Environment.NewLine), Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Avoid to add a element twice.
            if (this.editNetworkMachineCopy == null)
            {
                // Add new mode.
                if (this.allNetworkMachines != null)
                {
                    for (int i = 0; i < this.allNetworkMachines.Length; i++)
                    {
                        if (this.allNetworkMachines[i] == machine)
                        {
                            MessageBox.Show(String.Format(Wsapm.Resources.Wsapm.AddNetworkMachineWindow_NetworkMachineAlreadyAdded, machine.ToString()), Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                }
            }
            else
            {
                // Edit mode.
                if (machine == this.editNetworkMachineCopy)
                {
                    // Element was not changed.
                    this.DialogResult = false;
                    this.Close();
                    return;
                }
                else
                {
                    // Element was changed.
                    if (this.allNetworkMachines != null)
                    {
                        for (int i = 0; i < this.allNetworkMachines.Length; i++)
                        {
                            if (this.allNetworkMachines[i] == machine)
                            {
                                MessageBox.Show(String.Format(Wsapm.Resources.Wsapm.AddNetworkMachineWindow_NetworkMachineAlreadyAdded, machine.ToString()), Wsapm.Resources.Wsapm.General_MessageBoxErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }
                        }
                    }
                }
            }

            this.networkMachine = machine;
            this.DialogResult   = true;
            this.Close();
        }