Exemplo n.º 1
0
        public IEnumerable <RuleDto> ReadRules(ProfileDto profile, RuleDirectionDto direction)
        {
            int p = (int)profile, dir = (int)direction;
            var rules = rulesRepository
                        .Read(r => r.Direction == dir && r.Profile == p);

            return(mapper.Map <IEnumerable <RuleDto> >(rules));
        }
Exemplo n.º 2
0
        private bool TryGetRules(
            string name, ProfileDto profile, RuleDirectionDto direction,
            out IEnumerable <FirewallRuleDto> matchingRules)
        {
            matchingRules = GetRules(profile, direction)
                            .Where(r => r.Name == name);

            return(matchingRules.Count() > 0);
        }
Exemplo n.º 3
0
        public IEnumerable <FirewallRuleDto> GetRules(ProfileDto profile, RuleDirectionDto direction)
        {
            foreach (var group in groupedRules)
            {
                if (group.Profile == profile && group.Direction == direction)
                {
                    return(group.Rules);
                }
            }

            return(Enumerable.Empty <FirewallRuleDto>());
        }
Exemplo n.º 4
0
        private void DrawDirection(RuleDirectionDto direction, Bitmap icon)
        {
            var text     = direction.ToString();
            var font     = new Font("Consolas", 9.5f, FontStyle.Regular, GraphicsUnit.Point);
            var graphics = Graphics.FromImage(icon);
            var textSize = graphics.MeasureString(text, font);

            var rectangle = new RectangleF(
                new PointF(icon.Width - textSize.Width + 2, icon.Height - textSize.Height + 2),
                new SizeF(textSize.Width - 2, textSize.Height - 2));

            var brush = new SolidBrush(Color.FromArgb(170, Color.Black));

            graphics.FillPath(brush, RoundedRect(rectangle, 2));
            graphics.DrawString(text, font, Brushes.White, rectangle.Location);
        }
Exemplo n.º 5
0
        private void UpdateRulesGroup(ProfileDto profile, RuleDirectionDto direction, FirewallRuleDto firewallRuleDto)
        {
            Group group = null;

            foreach (var g in groupedRules)
            {
                if (g.Profile == profile && g.Direction == direction)
                {
                    group = g; break;
                }
            }

            group = group ?? new Group
            {
                Direction = direction,
                Profile   = profile,
                Rules     = Enumerable.Empty <FirewallRuleDto>()
            };

            group.Rules = group.Rules
                          .Concat(new[] { firewallRuleDto })
                          .OrderBy(r => r.Name);
        }
Exemplo n.º 6
0
 public IEnumerable <FirewallRuleDto> GetMatchingRules(
     string name, ProfileDto profile, RuleDirectionDto direction)
 {
     TryGetRules(name, profile, direction, out var rules);
     return(rules);
 }