Ejemplo n.º 1
0
        public virtual ModelVariable    DetermineVariable(String name)
        {
            ModelVariable v = null;

            //[ModelVariable]
            if (this.Model.Variables.Find(name).Count > 0)
            {
                v = this.Model.Variables[name];
            }

            //If not found, then is could be a dynamic variable (Columns.Count)
            Object instance = this.Model;

            if (v == null && name != null)
            {
                //Loop over the parts (ie: Command.Connection.IsOpen)
                string[] parts = name.TrimEnd('(', ')').Split('.');
                for (int i = 0; i < parts.Length; i++)
                {
                    String part = parts[i];
                    if (String.IsNullOrEmpty(part))
                    {
                        continue;
                    }

                    //Reflection
                    MemberInfo[] members = instance.GetType().GetMember(part, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                    if (members == null || members.Length == 0)
                    {
                        throw new ModelException(this, "Unable to find variable: '" + part + "'");
                    }

                    MemberInfo member = members[0];//TODO: Abmigious, more than one?

                    //Variable
                    v = new ModelVariable(this.Model, instance, members[0], name, null);
                    if (i + 1 < parts.Length)
                    {
                        instance = v.CurrentValue;
                    }

                    //Stop iterating once we hit a null
                    if (instance == null)
                    {
                        break;
                    }
                }

                if (v != null)
                {
                    this.Model.Variables.Add(v);
                }
            }

            if (v == null)
            {
                throw new ModelException(this, "Unable to find variable: '" + name + "'");
            }
            return(v);
        }
Ejemplo n.º 2
0
        ///<summary>Find a requirement from the variable specified</summary>
        public virtual ModelRequirement     Find(ModelVariable variable)
        {
            //Find a matching variable, of the specified type
            foreach (ModelRequirement requirement in this)
            {
                if (requirement.Variable == variable)
                {
                    return(requirement);
                }
            }

            //Otherwise
            return(null);
        }
Ejemplo n.º 3
0
        //Accessors
        public virtual void                    SetAttributeValues(ModelRangeAttribute attr)
        {
            base.SetAttributeValues(attr);
            if (attr != null)
            {
                _conjunction = attr.Conjunction;

                //Specified variable
                if (attr.Variable != null && this.Model != null)
                {
                    _variable = DetermineVariable(attr.Variable);
                }

                //Copy the value array (so modifications don't muck with the original static model)
                _values.Clear();
                _values.Add(attr._values);
            }
        }
Ejemplo n.º 4
0
        public ModelRequirement(ModelAction action, ModelRequirementAttribute attr, ModelVariable variable, ModelValue value)
            : base(action != null ? action.Model : null, attr)
        {
            //Action
            _action = action;

            //Variable
            if (variable != null)
            {
                _variable = variable;
                if (variable.BitMask)
                {
                    this.BitMask = true;
                }
            }
            //if(_variable == null)
            //    throw new ModelException(this, "An empty variable is not a valid requirement", null);

            //Only override the attr, if values are really specified
            if (value != null)
            {
                _values = new ModelValues(value);
            }

            //BitMask
            //TODO: Better place to expand this, (incase values added later).
            if (this.BitMask)
            {
                this.AddBitCombinations();
            }

            //Infer dynamic variable(s)
            this.InferDynamicVariables();

            //Requirements assoicated with actions, are not global.  They are tied to that particular
            //instance of the model, and it's instance of state variables.  However if not assoicated
            //with actions, the default behavior is that their global, they apply to all models
            //that contain that state variable, unless explicitly indicated otherwise.
            _global = (action == null);
        }
Ejemplo n.º 5
0
 public ModelRequirement(ModelAction action, ModelVariable variable, ModelValue value)
     : this(action, null, variable, value)
 {
     //Delegate
 }
Ejemplo n.º 6
0
        bool _global = true;                                    //global requirement (ie: any)

        //Constructor
        public ModelRequirement(ModelVariable variable, Object value)
            : this(variable, new ModelValue(value))
        {
            //Delegate
        }
Ejemplo n.º 7
0
 ///<summary>Add a requirement to this collection from the variable and the value specified</summary>
 public virtual ModelRequirement     Add(ModelVariable variable, object value)
 {
     return(this.Add(new ModelRequirement(variable, new ModelValue(value))));
 }