Beispiel #1
0
 private void DetachRuleControl(RuleControl rc)
 {
     if (rc.Next != null)
     {
         rc.Next.SetPrevious(rc.Previous);
     }
     if (rc.Previous != null)
     {
         rc.Previous.Next = rc.Next;
     }
 }
Beispiel #2
0
        private void AttachRuleControl(RuleControl rc, RuleControl prev, RuleControl next)
        {
            if (prev != null)
            {
                prev.Next = rc;
            }
            if (next != null)
            {
                next.SetPrevious(rc);
            }

            rc.SetPrevious(prev);
            rc.Next = next;
        }
Beispiel #3
0
        private RuleControl FindRuleControlFromPoint(RuleControl dragging, int Y, int dirY)
        {
            var pt = pnlRules.PointToClient(new Point(pnlRules.Width / 2, Y));

            while (pnlRules.ClientRectangle.Contains(pt))
            {
                if (pnlRules.GetChildAtPoint(pt) is RuleControl ruleControl && ruleControl != dragging)
                {
                    return(ruleControl);
                }
                pt.Y += dirY * 31;
            }

            return(null);
        }
Beispiel #4
0
        private RuleControl AddRulesToPanel(IEnumerable <RuleDto> rules)
        {
            var         removeRules = new List <RuleDto>();
            RuleControl prev        = null;
            RuleControl head        = null;

            foreach (var rule in rules)
            {
                var ruleControl = ProcessRule(rule, removeRules, prev);
                if (ruleControl != null)
                {
                    head = head ?? ruleControl;
                    ruleControl.HideForm   += (rc) => { HideForm(); };
                    ruleControl.DeleteRule += (rc, r) =>
                    {
                        var deleteResult = ruleService.Delete(r.Id);
                        if (deleteResult.Successful)
                        {
                            DetachRuleControl(rc);
                            pnlRules.Controls.Remove(rc);
                        }
                    };
                    ruleControl.UpdateRule += (rc, r) => { ruleService.Update(r); };
                    pnlRules.Controls.Add(ruleControl);

                    if (prev != null)
                    {
                        prev.Next = ruleControl;
                    }

                    prev = ruleControl;
                }
            }

            foreach (var ruleToDelete in removeRules)
            {
                ruleService.Delete(ruleToDelete.Id);
            }

            ResetRulesScroll();

            return(head);
        }
Beispiel #5
0
        private RuleControl ProcessRule(RuleDto rule, List <RuleDto> removeRules, RuleControl prev)
        {
            var matchingFwRules      = firewallService.GetMatchingRules(rule.Name, rule.Profile, rule.Direction);
            var matchingFwRulesCount = matchingFwRules.Count();

            if (matchingFwRulesCount == 0)
            {
                DeleteRule(rule, removeRules);
            }
            else
            {
                FirewallRuleDto fwRule = null;
                if (matchingFwRulesCount > 1)
                {
                    using (var selectRule = new SelectRuleForm(rule, matchingFwRules))
                    {
                        if (selectRule.ShowDialog() == DialogResult.OK)
                        {
                            fwRule = selectRule.SelectedRule;
                        }
                    }
                }
                else
                {
                    fwRule = matchingFwRules.Single();
                }

                if (fwRule == null)
                {
                    DeleteRule(rule, removeRules);
                }
                else
                {
                    var ruleControl = prev == null
                        ? new RuleControl(rule, fwRule, FIRST_RULE_LOCATION, firewallService)
                        : new RuleControl(rule, fwRule, prev, firewallService);
                    return(ruleControl);
                }
            }

            return(null);
        }
Beispiel #6
0
        public void SetPrevious(RuleControl nextPrevious, bool updateLocation = true)
        {
            if (Previous != null && !Previous.IsDisposed)
            {
                Previous.LocationChanged -= UpdateLocation;
            }

            if (nextPrevious != null)
            {
                nextPrevious.LocationChanged += UpdateLocation;
            }

            Previous = nextPrevious;
            if (updateLocation)
            {
                Location = Previous != null
                      ? LocationFromPrevious()
                      : FIRST_RULE_LOCATION;
            }
        }
Beispiel #7
0
        private RuleControl(
            RuleDto rule, FirewallRuleDto firewallRuleDto,
            RuleControl previous, Point?location,
            IFirewallService firewallService)
        {
            if (previous == null && location == null)
            {
                throw new ArgumentNullException(
                          $"{nameof(previous)},{nameof(location)}");
            }

            InitializeComponent();

            Previous             = previous;
            Rule                 = rule;
            this.firewallRuleDto = firewallRuleDto;
            this.firewallService = firewallService;

            MyInitializeComponent(location);
        }
Beispiel #8
0
 public RuleControl(
     RuleDto rule, FirewallRuleDto firewallRuleDto,
     RuleControl previous, IFirewallService firewallService)
     : this(rule, firewallRuleDto, previous, null, firewallService)
 {
 }