Example #1
0
        public static BaseRule LoadFromDescription(string desc)
        {
            int    typeNameIndex = desc.IndexOf("<PARAMS>");
            string typeName      = desc.Substring(0, typeNameIndex);

            //parameters are added upon instantiation
            BaseRule result = RuleFactory.GetInstance().CreateRuleInstance(Type.GetType("GeneticMarket.Logic.Rules." + typeName)) as BaseRule;

            //we only need to load parameter values
            int    endParamIndex = desc.Length - 1;
            string paramsString  = desc.Substring(typeNameIndex + 8, endParamIndex - typeNameIndex - 8);

            string[] paramsKeyValues = paramsString.Split('|');

            for (int i = 0; i < paramsKeyValues.Length; i++)
            {
                if (paramsKeyValues[i].Length == 0)
                {
                    continue;
                }

                string[] parts = paramsKeyValues[i].Split('=');
                string   key   = parts[0];
                string   value = parts[1];

                IRuleParameter argObject = result.parameters[key];
                bool           isDouble  = (argObject is DoubleRuleParameter);

                if (isDouble)
                {
                    result[key] = double.Parse(value);
                }
                else
                {
                    result[key] = int.Parse(value);
                }
            }

            return(result);
        }
Example #2
0
        public void CopyState(IRule target)
        {
            if (!(target is BaseRule))
            {
                throw new Exception("Cannot accept IRule operands");
            }

            BaseRule brTarget = target as BaseRule;

            foreach (string key in parameters.Keys)
            {
                brTarget.parameters[key].Value = parameters[key].Value;
            }

            foreach (string key in indicators.Keys)
            {
                brTarget.indicators.Add(key, indicators[key]);
            }

            brTarget.container = container;
            brTarget.idCache   = -1;
            brTarget.descCache = null;
        }