Пример #1
0
 public virtual ModelVariable this[Type type]
 {
     //Find first, fail if not found, although make it easier to debug
     get
     {
         ModelVariables found = this.FindType(type);
         if (found == null || found.Count <= 0)
         {
             throw new IndexOutOfRangeException(this.Name + "['" + type + "'] is not found");
         }
         return(found.First);
     }
 }
Пример #2
0
        ///<summary>Finds a model variable in this collection of the specified type</summary>
        public virtual ModelVariables       FindType(Type type)
        {
            //Find a matching variable, of the specified type
            ModelVariables found = new ModelVariables();

            foreach (ModelVariable variable in this)
            {
                if (variable.Type == type)
                {
                    found.Add(variable);
                }
            }

            return(found);
        }
Пример #3
0
        protected bool                          MeetsRequirements(ModelRequirements requirements, out ModelRequirement failedrequirement)
        {
            if (requirements != null)
            {
                //Loop over all requirements
                foreach (ModelRequirement requirement in requirements)
                {
                    //Ignore disabled requirements
                    if (requirement.Weight == 0 || requirement.Disabled)
                    {
                        continue;
                    }

                    //By default were just looking at this specific variable instance
                    //However if 'Global' is enabled, consider this variable on any models of this type
                    List <Object> currentValues = new List <Object>();
                    if (requirement.Global)
                    {
                        //Note: We do this check everytime, since models could have been added dynamically
                        if (requirement.Variable != null)
                        {
                            foreach (Model model in this.Models.FindType(requirement.Variable.Model.GetType()))
                            {
                                ModelVariables variables = model.Variables.Find(requirement.Variable.Name);
                                foreach (ModelVariable variable in variables)
                                {
                                    currentValues.Add(variable.CachedValue);
                                }
                            }
                        }
                        else
                        {
                            currentValues.Add(true);
                        }
                    }
                    else
                    {
                        if (requirement.Variable == null)
                        {
                            throw new ModelException(this, "Variable is null?");
                        }
                        currentValues.Add(requirement.Variable.CachedValue);
                    }

                    //See if this requirement is met
                    bool matched = false;
                    foreach (Object value in currentValues)
                    {
                        if (requirement.Evaluate(value))
                        {
                            matched = true;
                            break;
                        }
                    }

                    //Stop on first mis-match, (ie: at least one requirement didn't match)
                    if (!matched)
                    {
                        //First failed requirement
                        //Note: This has to be order based, since production checks conditions in-order
                        //and will fail (and throw) according to the first one not meet
                        failedrequirement = requirement;
                        return(false);
                    }
                }
            }

            failedrequirement = null;
            return(true);
        }
Пример #4
0
 public override void                        Reload()
 {
     //Clear, so they will be dynamically setup by reflection again
     _actions   = null;
     _variables = null;
 }