Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / WPF

Custom Rule Engine in WPF - MVVM

Rate me:
Please Sign up or sign in to vote.
4.98/5 (18 votes)
11 Sep 2010CPOL8 min read 75.2K   1.3K   95  
Custom Rule Engine approach which can evaluate complex combinations of business rules. A sample application is provided in WPF following the MVVM pattern.
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Data.EntityClient;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

[assembly: EdmSchemaAttribute()]

namespace CustomRulesMVVM.Models
{
    #region Contexts
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public partial class CustomRuleEntities : ObjectContext
    {
        #region Constructors
    
        /// <summary>
        /// Initializes a new CustomRuleEntities object using the connection string found in the 'CustomRuleEntities' section of the application configuration file.
        /// </summary>
        public CustomRuleEntities() : base("name=CustomRuleEntities", "CustomRuleEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new CustomRuleEntities object.
        /// </summary>
        public CustomRuleEntities(string connectionString) : base(connectionString, "CustomRuleEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new CustomRuleEntities object.
        /// </summary>
        public CustomRuleEntities(EntityConnection connection) : base(connection, "CustomRuleEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        #endregion
    
        #region Partial Methods
    
        partial void OnContextCreated();
    
        #endregion
    
        #region Function Imports
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="screenID">No Metadata Documentation available.</param>
        public ObjectResult<SelectRules_Result> SelectRules(Nullable<global::System.Int32> screenID)
        {
            ObjectParameter screenIDParameter;
            if (screenID.HasValue)
            {
                screenIDParameter = new ObjectParameter("screenID", screenID);
            }
            else
            {
                screenIDParameter = new ObjectParameter("screenID", typeof(global::System.Int32));
            }
    
            return base.ExecuteFunction<SelectRules_Result>("SelectRules", screenIDParameter);
        }

        #endregion
    }
    

    #endregion
    
    #region ComplexTypes
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmComplexTypeAttribute(NamespaceName="sqlexpressModel", Name="SelectRules_Result")]
    [DataContractAttribute(IsReference=true)]
    [Serializable()]
    public partial class SelectRules_Result : ComplexObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new SelectRules_Result object.
        /// </summary>
        /// <param name="screenID">Initial value of the ScreenID property.</param>
        /// <param name="operator">Initial value of the Operator property.</param>
        /// <param name="source">Initial value of the Source property.</param>
        /// <param name="ruleGroupID">Initial value of the RuleGroupID property.</param>
        /// <param name="ruleDescription">Initial value of the RuleDescription property.</param>
        public static SelectRules_Result CreateSelectRules_Result(global::System.Int32 screenID, global::System.String @operator, global::System.Int32 source, global::System.Int32 ruleGroupID, global::System.String ruleDescription)
        {
            SelectRules_Result selectRules_Result = new SelectRules_Result();
            selectRules_Result.ScreenID = screenID;
            selectRules_Result.Operator = @operator;
            selectRules_Result.Source = source;
            selectRules_Result.RuleGroupID = ruleGroupID;
            selectRules_Result.RuleDescription = ruleDescription;
            return selectRules_Result;
        }

        #endregion
        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ScreenID
        {
            get
            {
                return _ScreenID;
            }
            set
            {
                OnScreenIDChanging(value);
                ReportPropertyChanging("ScreenID");
                _ScreenID = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("ScreenID");
                OnScreenIDChanged();
            }
        }
        private global::System.Int32 _ScreenID;
        partial void OnScreenIDChanging(global::System.Int32 value);
        partial void OnScreenIDChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String ResultText
        {
            get
            {
                return _ResultText;
            }
            set
            {
                OnResultTextChanging(value);
                ReportPropertyChanging("ResultText");
                _ResultText = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("ResultText");
                OnResultTextChanged();
            }
        }
        private global::System.String _ResultText;
        partial void OnResultTextChanging(global::System.String value);
        partial void OnResultTextChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String CodeLHS
        {
            get
            {
                return _CodeLHS;
            }
            set
            {
                OnCodeLHSChanging(value);
                ReportPropertyChanging("CodeLHS");
                _CodeLHS = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("CodeLHS");
                OnCodeLHSChanged();
            }
        }
        private global::System.String _CodeLHS;
        partial void OnCodeLHSChanging(global::System.String value);
        partial void OnCodeLHSChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Operator
        {
            get
            {
                return _Operator;
            }
            set
            {
                OnOperatorChanging(value);
                ReportPropertyChanging("Operator");
                _Operator = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Operator");
                OnOperatorChanged();
            }
        }
        private global::System.String _Operator;
        partial void OnOperatorChanging(global::System.String value);
        partial void OnOperatorChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String ValueRHS
        {
            get
            {
                return _ValueRHS;
            }
            set
            {
                OnValueRHSChanging(value);
                ReportPropertyChanging("ValueRHS");
                _ValueRHS = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("ValueRHS");
                OnValueRHSChanged();
            }
        }
        private global::System.String _ValueRHS;
        partial void OnValueRHSChanging(global::System.String value);
        partial void OnValueRHSChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 Source
        {
            get
            {
                return _Source;
            }
            set
            {
                OnSourceChanging(value);
                ReportPropertyChanging("Source");
                _Source = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("Source");
                OnSourceChanged();
            }
        }
        private global::System.Int32 _Source;
        partial void OnSourceChanging(global::System.Int32 value);
        partial void OnSourceChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 RuleGroupID
        {
            get
            {
                return _RuleGroupID;
            }
            set
            {
                OnRuleGroupIDChanging(value);
                ReportPropertyChanging("RuleGroupID");
                _RuleGroupID = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("RuleGroupID");
                OnRuleGroupIDChanged();
            }
        }
        private global::System.Int32 _RuleGroupID;
        partial void OnRuleGroupIDChanging(global::System.Int32 value);
        partial void OnRuleGroupIDChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String RuleJoinOperator
        {
            get
            {
                return _RuleJoinOperator;
            }
            set
            {
                OnRuleJoinOperatorChanging(value);
                ReportPropertyChanging("RuleJoinOperator");
                _RuleJoinOperator = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("RuleJoinOperator");
                OnRuleJoinOperatorChanged();
            }
        }
        private global::System.String _RuleJoinOperator;
        partial void OnRuleJoinOperatorChanging(global::System.String value);
        partial void OnRuleJoinOperatorChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> RuleSeqNum
        {
            get
            {
                return _RuleSeqNum;
            }
            set
            {
                OnRuleSeqNumChanging(value);
                ReportPropertyChanging("RuleSeqNum");
                _RuleSeqNum = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("RuleSeqNum");
                OnRuleSeqNumChanged();
            }
        }
        private Nullable<global::System.Int32> _RuleSeqNum;
        partial void OnRuleSeqNumChanging(Nullable<global::System.Int32> value);
        partial void OnRuleSeqNumChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String RuleGroupJoinOperator
        {
            get
            {
                return _RuleGroupJoinOperator;
            }
            set
            {
                OnRuleGroupJoinOperatorChanging(value);
                ReportPropertyChanging("RuleGroupJoinOperator");
                _RuleGroupJoinOperator = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("RuleGroupJoinOperator");
                OnRuleGroupJoinOperatorChanged();
            }
        }
        private global::System.String _RuleGroupJoinOperator;
        partial void OnRuleGroupJoinOperatorChanging(global::System.String value);
        partial void OnRuleGroupJoinOperatorChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> RuleGroupSeqNum
        {
            get
            {
                return _RuleGroupSeqNum;
            }
            set
            {
                OnRuleGroupSeqNumChanging(value);
                ReportPropertyChanging("RuleGroupSeqNum");
                _RuleGroupSeqNum = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("RuleGroupSeqNum");
                OnRuleGroupSeqNumChanged();
            }
        }
        private Nullable<global::System.Int32> _RuleGroupSeqNum;
        partial void OnRuleGroupSeqNumChanging(Nullable<global::System.Int32> value);
        partial void OnRuleGroupSeqNumChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String RuleDescription
        {
            get
            {
                return _RuleDescription;
            }
            set
            {
                OnRuleDescriptionChanging(value);
                ReportPropertyChanging("RuleDescription");
                _RuleDescription = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("RuleDescription");
                OnRuleDescriptionChanged();
            }
        }
        private global::System.String _RuleDescription;
        partial void OnRuleDescriptionChanging(global::System.String value);
        partial void OnRuleDescriptionChanged();

        #endregion
    }

    #endregion
    
}

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) CA-CIB
Singapore Singapore
I am a .Net developer, currently working in Singapore worked wiith Societe Generale Global Solution Centre, Bangalore and was previously with Cognizant.I have more than 8 years of .Net experience in BFSI domain. I am an experienced developer in C#, VB.Net, Silverlight, WPF, WCF, LINQ, Entity Framework, SSIS, NHibernate, ASP.Net and SQL Server.

Comments and Discussions