Click here to Skip to main content
15,895,462 members
Articles / Programming Languages / C#

Use Rules In Your Applications

Rate me:
Please Sign up or sign in to vote.
4.84/5 (19 votes)
29 Aug 2006CPOL2 min read 112.4K   2.7K   93  
A Rules Engine class library with source code and documentation
<?xml version="1.0" encoding="Windows-1252"?>
<!-- edited with XMLSpy v2006 rel. 3 sp1 (http://www.altova.com) by Jeff Bramlett (The Weather Channel) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="Rules">
		<xs:annotation>
			<xs:documentation>The main collection object</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Variables">
					<xs:annotation>
						<xs:documentation>The collection of Variables to  modify with Rules</xs:documentation>
					</xs:annotation>
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Variable" maxOccurs="unbounded">
								<xs:annotation>
									<xs:documentation>The base Value type for this  Rules Engine</xs:documentation>
								</xs:annotation>
								<xs:complexType>
									<xs:simpleContent>
										<xs:extension base="xs:string">
											<xs:attribute name="id" type="xs:string" use="required">
												<xs:annotation>
													<xs:documentation>The unique identifier</xs:documentation>
												</xs:annotation>
											</xs:attribute>
										</xs:extension>
									</xs:simpleContent>
								</xs:complexType>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="Rule" maxOccurs="unbounded">
					<xs:annotation>
						<xs:documentation>The component that does the work.</xs:documentation>
					</xs:annotation>
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Expression" type="xs:string">
								<xs:annotation>
									<xs:documentation>Expression of this Rule for Actions to "match"</xs:documentation>
								</xs:annotation>
							</xs:element>
							<xs:element name="Actions">
								<xs:annotation>
									<xs:documentation>Collection of Actions</xs:documentation>
								</xs:annotation>
								<xs:complexType>
									<xs:sequence minOccurs="0">
										<xs:element name="Action" maxOccurs="unbounded">
											<xs:complexType>
												<xs:sequence>
													<xs:element name="Match" type="xs:string">
														<xs:annotation>
															<xs:documentation>Expression ot evaluate and match to Rule Expression</xs:documentation>
														</xs:annotation>
													</xs:element>
													<xs:element name="Assign" type="xs:string">
														<xs:annotation>
															<xs:documentation>Expression to assign to the Variable identified by the actionId.</xs:documentation>
														</xs:annotation>
													</xs:element>
												</xs:sequence>
												<xs:attribute name="actionId" type="xs:string" use="required">
													<xs:annotation>
														<xs:documentation>Unique Identifier of Rule element to modify</xs:documentation>
													</xs:annotation>
												</xs:attribute>
												<xs:attribute name="type" type="xs:string" use="required">
													<xs:annotation>
														<xs:documentation>The type of modification to make</xs:documentation>
													</xs:annotation>
												</xs:attribute>
											</xs:complexType>
										</xs:element>
									</xs:sequence>
								</xs:complexType>
							</xs:element>
							<xs:element name="SubRules">
								<xs:annotation>
									<xs:documentation>Collection of Rules</xs:documentation>
								</xs:annotation>
								<xs:complexType>
									<xs:sequence minOccurs="0">
										<xs:element name="Rule" maxOccurs="unbounded">
											<xs:complexType>
												<xs:sequence>
													<xs:element name="Expression" type="xs:string"/>
													<xs:element name="Actions">
														<xs:complexType>
															<xs:sequence>
																<xs:element name="Action" maxOccurs="unbounded">
																	<xs:complexType>
																		<xs:sequence>
																			<xs:element name="Match" type="xs:string"/>
																			<xs:element name="Assign" type="xs:string"/>
																		</xs:sequence>
																		<xs:attribute name="actionId" type="xs:string" use="required"/>
																		<xs:attribute name="type" type="xs:string" use="required"/>
																	</xs:complexType>
																</xs:element>
															</xs:sequence>
														</xs:complexType>
													</xs:element>
													<xs:element name="SubRules"/>
												</xs:sequence>
												<xs:attribute name="id" type="xs:string" use="required"/>
												<xs:attribute name="useInferencing" type="xs:string" use="required"/>
											</xs:complexType>
										</xs:element>
									</xs:sequence>
								</xs:complexType>
							</xs:element>
						</xs:sequence>
						<xs:attribute name="id" type="xs:string" use="required">
							<xs:annotation>
								<xs:documentation>The unique identifier</xs:documentation>
							</xs:annotation>
						</xs:attribute>
						<xs:attribute name="useInferencing" type="xs:string" use="required">
							<xs:annotation>
								<xs:documentation>Boolean switch to use this Rule in inferencing</xs:documentation>
							</xs:annotation>
						</xs:attribute>
					</xs:complexType>
				</xs:element>
				<xs:element name="Triggers">
					<xs:annotation>
						<xs:documentation>Collection of Triggers to "Run" rules.</xs:documentation>
					</xs:annotation>
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Trigger" maxOccurs="unbounded">
								<xs:annotation>
									<xs:documentation>A single connection to "Run" a rule when a Variable changes</xs:documentation>
								</xs:annotation>
								<xs:complexType>
									<xs:attribute name="id" type="xs:string" use="required">
										<xs:annotation>
											<xs:documentation>Unique Identifier for this Trigger</xs:documentation>
										</xs:annotation>
									</xs:attribute>
									<xs:attribute name="varID" type="xs:string" use="required">
										<xs:annotation>
											<xs:documentation>Variable ID to watch for modifications</xs:documentation>
										</xs:annotation>
									</xs:attribute>
									<xs:attribute name="ruleID" type="xs:string" use="required">
										<xs:annotation>
											<xs:documentation>Rule to run when the Variable changes in any way.</xs:documentation>
										</xs:annotation>
									</xs:attribute>
								</xs:complexType>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Website: http://www.somedeveloper.us

Comments and Discussions