/// <summary> /// The click event handler for the "Limiter" button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LimiterButton_Click(object sender, EventArgs e) { try { //No selected device if (DeviceList.SelectedObjects.Count == 0) { throw new ArgumentNullException(); } var device = DeviceList.SelectedObject as Device; //Check if the selected device is a gateway or own device if (device.IsGateway || device.IsLocalDevice) { throw new CustomExceptions.LocalHostTargeted(); } //Check if device is redirected before applying a speed limit if (!device.Redirected) { throw new CustomExceptions.RedirectionNotActiveException(); } LimiterSpeed ls = new LimiterSpeed(device); if (ls.ShowDialog() == DialogResult.OK) { if (device.Limited) { DeviceList.UpdateObject(device); } ls.Dispose(); } } catch (ArgumentNullException) { MetroMessageBox.Show(this, "Choose a device first and activate redirection for it!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (CustomExceptions.LocalHostTargeted) { MetroMessageBox.Show(this, "This operation can not target the gateway or your own ip address!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (CustomExceptions.RedirectionNotActiveException) { MetroMessageBox.Show(this, "Redirection must be active for this device!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void metroTile2_Click(object sender, EventArgs e) { try { if (fastObjectListView1.SelectedObjects.Count == 0) { throw new ArgumentException(); } var device = fastObjectListView1.SelectedObject as Device; if (device.IsGateway || device.IsLocalDevice) { throw new Controller.LocalHostTargeted(); } if (!device.Redirected) { throw new RedirectionNotActiveException(); } LimiterSpeed ls = new LimiterSpeed(device); if (ls.ShowDialog() == DialogResult.OK) { if (device.LimiterStarted) { fastObjectListView1.UpdateObject(device); ls.Dispose(); } else { MetroMessageBox.Show(this, "Start redirection first!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (ArgumentException) { MetroMessageBox.Show(this, "Choose a device first and activate redirection for it!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Controller.LocalHostTargeted) { MetroMessageBox.Show(this, "This operation can not target the gateway or your own ip address!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (RedirectionNotActiveException) { MetroMessageBox.Show(this, "Redirection must be active for this device!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }