public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { EvaluateMacroConfig config = rawConfig as EvaluateMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as EvaluateMacroConfig"); } ConditionEvaluator evaluator = EvaluatorSelector.Select(config.Evaluator); byte[] data = Encoding.UTF8.GetBytes(config.Value); int len = data.Length; int pos = 0; IProcessorState state = new GlobalRunSpec.ProcessorState(environmentSettings, vars, data, Encoding.UTF8); bool result = evaluator(state, ref len, ref pos, out bool faulted); Parameter p = new Parameter { IsVariable = true, Name = config.VariableName }; setter(p, result.ToString()); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { SwitchMacroConfig config = rawConfig as SwitchMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as SwitchMacroConfig"); } ConditionEvaluator evaluator = EvaluatorSelector.Select(config.Evaluator, Cpp2StyleEvaluatorDefinition.Evaluate); string result = string.Empty; // default if no condition assigns a value foreach (KeyValuePair <string, string> switchInfo in config.Switches) { string condition = switchInfo.Key; string value = switchInfo.Value; if (string.IsNullOrEmpty(condition)) { // no condition, this is the default. result = value; break; } else { byte[] conditionBytes = Encoding.UTF8.GetBytes(condition); int length = conditionBytes.Length; int position = 0; IProcessorState state = new GlobalRunSpec.ProcessorState(environmentSettings, vars, conditionBytes, Encoding.UTF8); if (evaluator(state, ref length, ref position, out bool faulted)) { result = value; break; } } } Parameter p; if (parameters.TryGetParameterDefinition(config.VariableName, out ITemplateParameter existingParam)) { // If there is an existing parameter with this name, it must be reused so it can be referenced by name // for other processing, for example: if the parameter had value forms defined for creating variants. // When the param already exists, use its definition, but set IsVariable = true for consistency. p = (Parameter)existingParam; p.IsVariable = true; } else { p = new Parameter { IsVariable = true, Name = config.VariableName }; } vars[config.VariableName] = result.ToString(); setter(p, result.ToString()); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { SwitchMacroConfig config = rawConfig as SwitchMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as SwitchMacroConfig"); } ConditionEvaluator evaluator = EvaluatorSelector.Select(config.Evaluator, Cpp2StyleEvaluatorDefinition.Evaluate); string result = string.Empty; // default if no condition assigns a value foreach (KeyValuePair <string, string> switchInfo in config.Switches) { string condition = switchInfo.Key; string value = switchInfo.Value; if (string.IsNullOrEmpty(condition)) { // no condition, this is the default. result = value; break; } else { byte[] conditionBytes = Encoding.UTF8.GetBytes(condition); int length = conditionBytes.Length; int position = 0; IProcessorState state = new GlobalRunSpec.ProcessorState(environmentSettings, vars, conditionBytes, Encoding.UTF8); if (evaluator(state, ref length, ref position, out bool faulted)) { result = value; break; } } } Parameter p = new Parameter { IsVariable = true, Name = config.VariableName, DataType = config.DataType }; vars[config.VariableName] = result.ToString(); setter(p, result.ToString()); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { EvaluateMacroConfig config = rawConfig as EvaluateMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as EvaluateMacroConfig"); } ConditionEvaluator evaluator = EvaluatorSelector.Select(config.Evaluator, Cpp2StyleEvaluatorDefinition.Evaluate); byte[] data = Encoding.UTF8.GetBytes(config.Value); int len = data.Length; int pos = 0; IProcessorState state = new GlobalRunSpec.ProcessorState(environmentSettings, vars, data, Encoding.UTF8); bool result = evaluator(state, ref len, ref pos, out bool faulted); Parameter p; if (parameters.TryGetParameterDefinition(config.VariableName, out ITemplateParameter existingParam)) { // If there is an existing parameter with this name, it must be reused so it can be referenced by name // for other processing, for example: if the parameter had value forms defined for creating variants. // When the param already exists, use its definition, but set IsVariable = true for consistency. p = (Parameter)existingParam; p.IsVariable = true; if (string.IsNullOrEmpty(p.DataType)) { p.DataType = config.DataType; } } else { p = new Parameter { IsVariable = true, Name = config.VariableName, DataType = config.DataType }; } vars[config.VariableName] = result.ToString(); setter(p, result.ToString()); }
public void Evaluate(string variableName, IVariableCollection vars, JObject def, IParameterSet parameters, ParameterSetter setter) { string evaluatorName = def.ToString("evaluator"); ConditionEvaluator evaluator = EvaluatorSelector.Select(evaluatorName); byte[] data = Encoding.UTF8.GetBytes(def.ToString("action")); int len = data.Length; int pos = 0; IProcessorState state = new GlobalRunSpec.ProcessorState(vars, data, Encoding.UTF8); bool res = evaluator(state, ref len, ref pos); Parameter p = new Parameter { IsVariable = true, Name = variableName }; setter(p, res.ToString()); }