Beispiel #1
0
        private void FastObjectListView1_SubItemChecking(object sender, SubItemCheckingEventArgs e)
        {
            try
            {
                if (SnifferStarted)//deal with the small hang on activation
                {
                    throw new OperationInProgressException();
                }

                if (!checkboxcanbeclicked)
                {
                    e.Canceled = true;
                    return;
                }

                fastObjectListView1.SelectObject(e.RowObject);
                Device device = e.RowObject as Device;
                if (device.IsGateway || device.IsLocalDevice)
                {
                    throw new Controller.GatewayTargeted();
                }
                device.GatewayMAC = GetGatewayMAC();
                device.GatewayIP  = GetGatewayIP();
                device.LocalIP    = GetLocalIP();

                if (e.NewValue == CheckState.Checked && e.Column.Index == 6 && !device.BlockerActive && !device.RedirectorActive)
                {
                    try
                    {
                        device.Blocked       = true;
                        device.BlockerActive = true;
                        device.DeviceStatus  = "Offline";
                        device.BlockOrRedirect();
                        fastObjectListView1.UpdateObject(device);
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96;
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (e.NewValue == CheckState.Checked && e.Column.Index == 5 && !device.RedirectorActive && !device.BlockerActive)
                {
                    try
                    {
                        new Thread(() =>
                        {
                            loading = new Loading();
                            loading.ShowDialog();
                        }).Start();

                        device.Blocked          = true;
                        device.Redirected       = true;
                        device.RedirectorActive = true;
                        device.BlockOrRedirect();
                        GetReady();
                        device.LimiterStarted = true;
                        device.DownloadCap    = 0;
                        device.UploadCap      = 0;
                        if (!ValuesTimer.Enabled)
                        {
                            //PopulateDeviceList();
                            //PopulateCalled = true;
                            ValuesTimer.Start();
                        }
                        LoDevices = fastObjectListView1.Objects.Cast <Device>().ToList();
                        new Thread(() =>
                        {
                            LimiterClass LimitDevice = new LimiterClass(device);
                            LimitDevice.StartLimiter();
                        }).Start();
                        loading.BeginInvoke(new Action(() => { loading.Close(); }));
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96;
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (e.NewValue == CheckState.Unchecked && e.Column.Index == 6 && device.BlockerActive)
                {
                    try
                    {
                        device.Blocked       = false;
                        device.BlockerActive = false;
                        device.DeviceStatus  = "Online";
                        fastObjectListView1.UpdateObject(device);
                        PopulateForBlocker();
                        foreach (var Dev in LODFB)
                        {
                            if (Dev.Blocked)
                            {
                                return;
                            }
                        }
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96px;
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (e.NewValue == CheckState.Unchecked && e.Column.Index == 5 && device.RedirectorActive)
                {
                    try
                    {
                        device.Blocked          = false;
                        device.Redirected       = false;
                        device.RedirectorActive = false;
                        device.LimiterStarted   = false;
                        device.DownloadCap      = 0;
                        device.UploadCap        = 0;
                        device.DownloadSpeed    = "";
                        device.UploadSpeed      = "";
                        fastObjectListView1.UpdateObject(device);
                        foreach (Device Device in LoDevices)
                        {
                            if (Device.LimiterStarted)
                            {
                                return;
                            }
                        }
                        ValuesTimer.Stop();
                        PopulateCalled = false;
                        fastObjectListView1.UpdateObject(device);
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96px;
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    e.Canceled = true;
                    e.NewValue = e.CurrentValue;
                }
            }
            catch (Controller.GatewayTargeted)
            {
                MetroMessageBox.Show(this, "This operation can not target the gateway or your own ip address!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
                e.Canceled = true;
            }
            catch (OperationInProgressException)
            {
                MetroMessageBox.Show(this, "The Speed Limiter can't be used while the sniffer is active!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
        }