{"id":18402251,"url":"https://github.com/iotsharp/ruleengine","last_synced_at":"2025-04-12T17:57:54.899Z","repository":{"id":97704690,"uuid":"253824812","full_name":"IoTSharp/RuleEngine","owner":"IoTSharp","description":"RuleEngine","archived":false,"fork":false,"pushed_at":"2020-04-07T16:06:00.000Z","size":127,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T17:57:53.890Z","etag":null,"topics":["iotsharp","irule","ruleengine"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IoTSharp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-07T14:51:48.000Z","updated_at":"2022-12-13T10:18:27.000Z","dependencies_parsed_at":"2023-05-28T09:00:41.539Z","dependency_job_id":null,"html_url":"https://github.com/IoTSharp/RuleEngine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IoTSharp%2FRuleEngine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IoTSharp%2FRuleEngine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IoTSharp%2FRuleEngine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IoTSharp%2FRuleEngine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IoTSharp","download_url":"https://codeload.github.com/IoTSharp/RuleEngine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610385,"owners_count":21132920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iotsharp","irule","ruleengine"],"created_at":"2024-11-06T02:42:00.742Z","updated_at":"2025-04-12T17:57:54.876Z","avatar_url":"https://github.com/IoTSharp.png","language":"C#","readme":"# IoTSharp.RuleEngine\n\n\n# About  IoTSharp.RuleEngine \n IoTSharp.RuleEngine is a https://github.com/gsoulavy/RuleEngine fork, I'm  will  implement a rule engine for IoTSharp based on https://github.com/gsoulavy/RuleEngine, so, thanks to Gab Soulavy for the great work.\n \n \n\n### Purpose\n\nThis simple rule engine is a .NET Standard library 2.0, which uses Microsoft's DLR DynamicExpressionParser in the background. The goal was to make a simple engine which is easy to use and compatible with many projects.\n\n### Use\n\n\n##### Workflow Rules Engine\n\n下面的示例实现了 在输入的数据中通过规则链MsgT_Exit_Waste 中的 STATION_NAME  不为空并且不以“某某某收费站”开头的数据输出， 这是个简单的例子 只有 Then , 没有Else  \n\n```\n         Rule rule = new Rule()\n            {\n                RuleName = \"data\",\n                ErrorType = ErrorType.Error,\n                ErrorMessage = \"未能找到数据\",\n                Expression = \"f.MsgT_Exit_Waste!=null\",\n                ThenSelect = \"MsgT_Exit_Waste\",\n                Then = new Rule()\n                {\n                    Expression = \"f.STATION_NAME!=null \u0026\u0026 !f.STATION_NAME.StartsWith(\\\"某某收费站\\\")\",\n                    ThenSelect = \"STATION_NAME\",\n                    ErrorMessage = \"收费站配置信息错误\",\n                    RuleName = \"moumou\",\n                    RuleExpressionType = RuleExpressionType.LambdaExpression\n                }\n            };\n            var  engine = new RulesEngine(rule);\n            var result = engine.Execute(Properties.Resources.MsgT_Exit_Waste);\n            Assert.True(result.Result);\n            Assert.Equal(\"新疆米东北主线站\", result.Output);\n```\n\n\n#### Instantiating the kernel\n\nThe IKernel interface is implemented with Kerner in order to support Inverson Of Control.\n\n```cs\nIKernel ruleEngine = new Kernel();\n```\n\n##### Role of the IRule\nThe engine is designed to use any object as a rule which implements IRule interface in order to make it easy to use with an ORM.\n\n```cs\npublic interface IRule\n{\n    string Key { get; set; }\n    string Expression { get; set; }\n}\n```\n```cs\n//...\nvoid AddRule(IRule rule);\n//...\n```\n\n\n##### Simple Validation\nString expressions can be simply against the object passed to the engine.\u003cbr/\u003e\nCreating a fact:\n```cs\nvar fact = new Person {Age = 37, Income = 45000, NumberOfChildren = 3};\n```\n\nValidating the fact:\n```cs\nvar result = ruleEngine.Validate(fact, \"(f.Age \u003e 3 \u0026\u0026 f.Income \u003e 100000) || f.NumberOfChildren \u003e 5\");\n// result = false\n```\n\n##### Validate All\nMore than one expreession can be added to the engine\n```cs\nvar rules = new List\u003cRule\u003e\n{\n    new Rule {Key = \"1\", Expression = \"(f.Age \u003e 3 \u0026\u0026 f.Income \u003c 50000) || f.NumberOfChildren \u003e 2\"},\n    new Rule {Key = \"2\", Expression = \"(f.Age \u003e 3 \u0026\u0026 f.Income \u003e 100000) || f.NumberOfChildren \u003e 5\"}\n};\n\nruleEngine.AddRules(rules);\n\n// Validate against all rules when no key passed\nvar result = ruleEngine.ValidateAll(f);\n// result = false\n\n// Only validate against rules with the matching key\nvar result = ruleEngine.ValidateAll(f, \"1\");\n// result = true\n```\n\n##### Validate Any\nThe calls are the same as the case of validate all, however it returns true if any case is true.\n```cs\nvar rules = new List\u003cRule\u003e\n{\n    new Rule {Key = \"1\", Expression = \"(f.Age \u003e 3 \u0026\u0026 f.Income \u003c 50000) || f.NumberOfChildren \u003e 2\"},\n    new Rule {Key = \"2\", Expression = \"(f.Age \u003e 3 \u0026\u0026 f.Income \u003e 100000) || f.NumberOfChildren \u003e 5\"}\n};\n\nruleEngine.AddRules(rules);\n\n// Validate against all rules when no key passed\nvar result = ruleEngine.ValidateAny(f);\n// result = true\n\n// Only validate against rules with the matching key\nvar result = ruleEngine.ValidateAny(f, \"1\");\n// result = true\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiotsharp%2Fruleengine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiotsharp%2Fruleengine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiotsharp%2Fruleengine/lists"}