コード例 #1
0
 public EditDeviceWindow(UdpDevice u)
 {
     InitializeComponent();
     toEdit      = u;
     initialName = string.Copy(u.DeviceName);
     RefreshEditFields();
 }
コード例 #2
0
        private void Load()
        {
            try
            {
                var s = MyUtils.RetrieveSettings();
                if (s != null)
                {
                    if (s.udps.Count != 0)
                    {
                        MyUtils.UdpDevices.Clear();
                    }

                    foreach (var u in s.udps)
                    {
                        if (MyUtils.ValidateIp(u.Ip))
                        {
                            var ad = new UdpDevice(u.DeviceName, u.Ip, u.Port, u.Lines, u.Smoothing);
                            //ad.Smoothing = 0;
                            MyUtils.UdpDevices.Add(ad);
                        }
                    }
                    loadedAudioDevice = s.audioDevice;
                    Save(loadedAudioDevice);
                }
            }
            catch (Exception ex)
            {
                this.ShowMessageAsync("Error", "Loading devices failed!\n\nError message:\n" + ex.Message, MessageDialogStyle.Affirmative);
                MyUtils.UdpDevices.Clear();
            }
        }
コード例 #3
0
 public EditDeviceWindow(UdpDevice u, MainWindow x)
 {
     InitializeComponent();
     toEdit      = u;
     initialName = string.Copy(u.DeviceName);
     RefreshEditFields();
     mainWindowInstance = x;
 }
コード例 #4
0
 private void BtnSave_Click(object sender, RoutedEventArgs e)
 {
     if (!CheckIP())
     {
         return;
     }
     try
     {
         var toSet = MyUtils.UdpDevices.Find(x => x.DeviceName == initialName);
         MyUtils.UdpDevices.Remove(toSet);
         toSet = new UdpDevice(txtName.Text, txtIp.Text, (int)nudPort.Value, (int)nudLines.Value, (int)sldSmoothing.Value);
         MyUtils.UdpDevices.Add(toSet);
         Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error when saving the device:\n\n\nError message:\n" + ex.Message);
     }
 }
コード例 #5
0
 private void BtnRestore_Click(object sender, RoutedEventArgs e)
 {
     toEdit = MyUtils.UdpDevices.Find(x => x.DeviceName == initialName).DeepCopy();
     RefreshEditFields();
 }
コード例 #6
0
        public async void AddDeviceDialogAsync(string ipaddr)
        {
            var devicename = "";
            var ip         = ipaddr;
            var lines      = 32;

            var x = new MetroDialogSettings
            {
                AffirmativeButtonText = "Next",
                NegativeButtonText    = "Cancel"
            };

            devicename = await this.ShowInputAsync("New Device", "How should the device be called?", x);

            if (string.IsNullOrEmpty(devicename))
            {
                return;
            }

            var exist = MyUtils.UdpDevices.Find(o => o.DeviceName == devicename);

            if (exist != null)
            {
                await this.ShowMessageAsync("Error!", "A device with that name already exists!");

                return;
            }

            var porttext = "";

            x.DefaultText = "4210";
            porttext      = await this.ShowInputAsync("New Device", "On what UDP-Port should the data be sent?", x);

            if (!int.TryParse(porttext, out var port))
            {
                port = -1;
            }

            while (port <= 0)
            {
                porttext = await this.ShowInputAsync("Invalid Number!", "On what UDP-Port should the data be sent?", x);

                if (string.IsNullOrEmpty(porttext))
                {
                    return;
                }

                if (!int.TryParse(porttext, out port))
                {
                    port = -1;
                }
            }

            x.DefaultText = "2";
            var smtext = "";

            smtext = await this.ShowInputAsync("New Device", "How much should the spectrum be smoothed?", x);

            if (!int.TryParse(smtext, out var smoothing))
            {
                smoothing = -1;
            }

            while ((smoothing <= 0 || smoothing > 100))
            {
                smtext = await this.ShowInputAsync("Invalid Number!", "How much should the spectrum be smoothed?", x);

                if (string.IsNullOrEmpty(smtext))
                {
                    return;
                }

                if (!int.TryParse(smtext, out smoothing))
                {
                    smoothing = -1;
                }
            }

            x.AffirmativeButtonText = "Add Device";
            x.NegativeButtonText    = "Cancel Device Creation";
            var res = await this.ShowMessageAsync("Confirm", "Name: " + devicename + "\nIP-Address: " + ip + "\nLines: " + lines, MessageDialogStyle.AffirmativeAndNegative, x);

            if (res == MessageDialogResult.Negative)
            {
                return;
            }

            try
            {
                var newDev = new UdpDevice(devicename, ip, port, lines, smoothing)
                {
                    Smooth = true
                };
                MyUtils.UdpDevices.Add(newDev);
                foreach (Window window in Application.Current.Windows)
                {
                    if (window.GetType() == typeof(MainWindow))
                    {
                        (window as MainWindow).Save();
                        (window as MainWindow).RefreshDeviceList();
                    }
                }
                await this.ShowMessageAsync("Success!", "Device created successfully!");
            }
            catch
            {
                await this.ShowInputAsync("Error", "Something went wrong while creating the new device!");
            }
        }
コード例 #7
0
        public async void AddDeviceDialogAsync()
        {
            var devicename = "";
            var ip         = "";
            var lines      = 32;

            var x = new MetroDialogSettings
            {
                AffirmativeButtonText = "Next",
                NegativeButtonText    = "Cancel"
            };

            devicename = await this.ShowInputAsync("New Device", "How should the device be called?", x);

            if (string.IsNullOrEmpty(devicename))
            {
                return;
            }

            var exist = MyUtils.UdpDevices.Find(o => o.DeviceName == devicename);

            if (exist != null)
            {
                await this.ShowMessageAsync("Error!", "A device with that name already exists!");

                return;
            }

            x.DefaultText = "192.168.0.";
            ip            = await this.ShowInputAsync("New Device", "Whats the IP-Address of your device?", x);

            while (!MyUtils.ValidateIp(ip))
            {
                await this.ShowMessageAsync("Error!", "The IP-Address that was entered is invalid!");

                ip = await this.ShowInputAsync("New Device", "Whats the IP-Address of your device?", x);

                if (string.IsNullOrEmpty(ip))
                {
                    return;
                }
            }
            var controller = await this.ShowProgressAsync("Please wait...", "Trying to reach the device");

            controller.SetIndeterminate();
            Thread.Sleep(500);
            var success = MyUtils.IpReachable(ip);
            await controller.CloseAsync();

            if (!success)
            {
                x.AffirmativeButtonText = "Yes";
                var cont = await this.ShowMessageAsync("The device could not be reached!", "Continue anyway?", MessageDialogStyle.AffirmativeAndNegative, x);

                if (cont == MessageDialogResult.Negative)
                {
                    return;
                }
            }

            var porttext = "";

            x.DefaultText = "4210";
            porttext      = await this.ShowInputAsync("New Device", "On what UDP-Port should the data be sent?", x);

            if (!int.TryParse(porttext, out var port))
            {
                port = -1;
            }

            while (port <= 0)
            {
                porttext = await this.ShowInputAsync("Invalid Number!", "On what UDP-Port should the data be sent?", x);

                if (string.IsNullOrEmpty(porttext))
                {
                    return;
                }

                if (!int.TryParse(porttext, out port))
                {
                    port = -1;
                }
            }
            x.DefaultText = "32";
            var linestext = "";

            if (!success)
            {
                linestext = await this.ShowInputAsync("New Device", "How many lines of data should be sent to the device?", x);

                if (!int.TryParse(linestext, out lines))
                {
                    lines = -1;
                }

                while ((lines <= 0 || lines > 1023))
                {
                    linestext = await this.ShowInputAsync("Invalid Number!", "How many lines of data should be sent to the device?", x);

                    if (string.IsNullOrEmpty(linestext))
                    {
                        return;
                    }

                    if (!int.TryParse(linestext, out lines))
                    {
                        lines = -1;
                    }
                }
            }


            x.DefaultText = "2";
            var smtext = "";

            smtext = await this.ShowInputAsync("New Device", "How much should the spectrum be smoothed?", x);

            if (!int.TryParse(smtext, out var smoothing))
            {
                smoothing = -1;
            }

            while ((smoothing <= 0 || smoothing > 100))
            {
                smtext = await this.ShowInputAsync("Invalid Number!", "How much should the spectrum be smoothed?", x);

                if (string.IsNullOrEmpty(smtext))
                {
                    return;
                }

                if (!int.TryParse(smtext, out smoothing))
                {
                    smoothing = -1;
                }
            }

            x.AffirmativeButtonText = "Add Device";
            x.NegativeButtonText    = "Cancel Device Creation";
            var res = await this.ShowMessageAsync("Confirm", "Name: " + devicename + "\nIP-Address: " + ip + "\nLines: " + lines, MessageDialogStyle.AffirmativeAndNegative, x);

            if (res == MessageDialogResult.Negative)
            {
                return;
            }

            try
            {
                var newDev = new UdpDevice(devicename, ip, port, lines, smoothing)
                {
                    Smooth = true
                };
                MyUtils.UdpDevices.Add(newDev);
                Save();
                RefreshDeviceList();
                await this.ShowMessageAsync("Success!", "Device created successfully!");
            }
            catch
            {
                await this.ShowInputAsync("Error", "Something went wrong while creating the new device!");
            }
        }