示例#1
0
        static void PerformCalculations(RuleDirection direction, int numberOfDigits, int overallIdenticalNumber, int subsequentIdenticalNumber)
        {
            RuleChecker overarchingChecker = CreateOverarchingRules(numberOfDigits);
            RuleChecker iterativeChecker   = CreateIterativeRules(direction, overallIdenticalNumber, subsequentIdenticalNumber);

            Console.WriteLine(string.Format(Strings.NumberDisplay, new RandomGenerator(iterativeChecker, overarchingChecker).Generate(direction)));
            Console.ReadKey();
        }
示例#2
0
        public static RuleChecker CreateIterativeRules(RuleDirection direction, int overallIdenticalNumber, int subsequentIdenticalNumber)
        {
            RuleChecker checker = new RuleChecker(direction);

            checker.AddRule(new OverallIdenticalNumbersRule(overallIdenticalNumber));
            checker.AddRule(new NotMoreThanYSubsequentNumbersIdenticalRule(subsequentIdenticalNumber));

            return(checker);
        }
        public void addRule(string path, RuleAction ruleAction, RuleDirection ruleDir, RuleProtocol ruleProtoc)
        {
            string      appName     = path;
            INetFwRule2 inboundRule = (INetFwRule2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));

            inboundRule.Enabled         = true;
            inboundRule.ApplicationName = appName;

            inboundRule.Protocol  = (int)ruleProtoc;
            inboundRule.Direction = (NET_FW_RULE_DIRECTION_)ruleDir;
            inboundRule.Profiles  = 7;
            inboundRule.Name      = "_BM_FW_" + ((int)ruleDir).ToString() + ((int)ruleAction).ToString() + ((int)ruleProtoc).ToString() + "_" + appName.Substring(appName.LastIndexOf(@"\") + 1, appName.Length - appName.LastIndexOf(@"\") - 5);
            inboundRule.Action    = (NET_FW_ACTION_)ruleAction;

            INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));

            firewallPolicy.Rules.Add(inboundRule);
        }
示例#4
0
        // My modification
        public void Add(string name, Action action, int protocol, RuleDirection direction,
                        string localAddresses, string localPorts, string remoteAddresses, string remotePorts)
        {
            Type ruleType = Type.GetTypeFromProgID("HNetCfg.FWRule");
            var  fwRule   = (INetFwRule)Activator.CreateInstance(ruleType);

            fwRule.Name      = name ?? "Generic Rule Name";
            fwRule.Action    = (NET_FW_ACTION_)action;
            fwRule.Protocol  = protocol;
            fwRule.Direction = (NET_FW_RULE_DIRECTION_)direction;

            fwRule.LocalAddresses = localAddresses;
            fwRule.LocalPorts     = localPorts;

            fwRule.RemoteAddresses = remoteAddresses;
            fwRule.RemotePorts     = remotePorts;

            fwRule.Enabled = true;

            _rules.Add(fwRule);
        }
示例#5
0
 public string Generate(RuleDirection direction)
 {
     return((direction == RuleDirection.Direct) ? GenerateDirectNumber() : GenerateReverseNumber());
 }
示例#6
0
文件: Rule.cs 项目: wmw23/Carbon
        public Rule(string name, bool enabled, RuleDirection direction, RuleProfile profile, string grouping, string localIPAddress,
                    string localPort, string remoteIPAddress, string remotePort, string protocol, string edgeTraversal, RuleAction action,
                    RuleInterfaceType interfaceType, RuleSecurity security, string source, string description, string program, string service)
        {
            Name      = name;
            Enabled   = enabled;
            Direction = direction;
            Profile   = profile;
            if (Profile == RuleProfile.Any)
            {
                Profiles = "Any";
            }
            else
            {
                var profiles = new List <string>();
                if (IsDomainProfile)
                {
                    profiles.Add("Domain");
                }
                if (IsPrivateProfile)
                {
                    profiles.Add("Private");
                }
                if (IsPublicProfile)
                {
                    profiles.Add("Public");
                }
                Profiles = string.Join(",", profiles.ToArray());
            }

            Grouping        = LoadIndirectString(grouping);
            LocalIPAddress  = localIPAddress;
            LocalPort       = localPort;
            RemoteIPAddress = remoteIPAddress;
            RemotePort      = remotePort;
            Protocol        = protocol;
            EdgeTraversal   = edgeTraversal;
            switch (edgeTraversal.ToLowerInvariant())
            {
            case "yes":
                EdgeTraversalPolicy = RuleEdgeTraversalPolicy.Yes;
                break;

            case "no":
                EdgeTraversalPolicy = RuleEdgeTraversalPolicy.No;
                break;

            case "defer to user":
                EdgeTraversalPolicy = RuleEdgeTraversalPolicy.DeferUser;
                break;

            case "defer to application":
                EdgeTraversalPolicy = RuleEdgeTraversalPolicy.DeferApp;
                break;
            }
            Action        = action;
            InterfaceType = interfaceType;
            Security      = security;
            Source        = source;
            Description   = description;
            Program       = program;
            Service       = service;
        }
示例#7
0
 public RuleChecker(RuleDirection direction)
 {
     Rules     = new List <IRule>();
     Direction = direction;
 }