private void AddPortRule(object sender, EventArgs e) { try { var profileType = (treeView.SelectedNode.Tag as IFirewallProfile)?.Type; if (profileType == null) { return; } var addPortDialog = new AddPortForm(); if (addPortDialog.ShowDialog() != DialogResult.OK) { return; } var newPortRule = FirewallManager.Instance.CreatePortRule( profileType.Value, "!!TETS!! " + Guid.NewGuid().ToString("B"), FirewallAction.Allow, addPortDialog.PortNumber, addPortDialog.FirewallProtocol ); var editDialog = new EditRuleForm(newPortRule); if (editDialog.ShowDialog() == DialogResult.OK) { FirewallManager.Instance.Rules.Add(newPortRule); RefreshTreeView(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddApplicationRule(object sender, EventArgs e) { try { var profileType = (treeView.SelectedNode.Tag as IFirewallProfile)?.Type; if (profileType == null) { return; } if (ofd_app.ShowDialog() != DialogResult.OK) { return; } var newAppRule = FirewallManager.Instance.CreateApplicationRule( profileType.Value, "!!TETS!! " + Guid.NewGuid().ToString("B"), FirewallAction.Allow, ofd_app.FileName ); newAppRule.Direction = FirewallDirection.Outbound; var editDialog = new EditRuleForm(newAppRule); if (editDialog.ShowDialog() == DialogResult.OK) { FirewallManager.Instance.Rules.Add(newAppRule); RefreshTreeView(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }