public void EvalCustomVariables(XmlNode productCustomVars) { if (productCustomVars != null && productCustomVars.HasChildNodes) { RequirementHandlers reqHandlers = new RequirementHandlers(); foreach (XmlNode CustomVar in productCustomVars.ChildNodes) { ProductSettings.ProductRequirement requirement = new ProductSettings.ProductRequirement { Type = XmlParser.GetStringValue(CustomVar, "Type"), LogicalOperator = XmlParser.GetStringAttribute(CustomVar, "Keys", "logicalOp") }; if (string.IsNullOrEmpty(requirement.LogicalOperator)) { requirement.LogicalOperator = Enum.GetName(typeof(RequirementHandlers.LogicalOperatorType), RequirementHandlers.LogicalOperatorType.AND); //default value } requirement.Keys = new List <ProductSettings.RequirementKey>(); foreach (XmlNode requirementKey in CustomVar.SelectNodes("Keys/Key")) { ProductSettings.RequirementKey reqKey; reqKey.KeyValue = XmlParser.GetStringValue(requirementKey); reqKey.KeyType = XmlParser.GetStringAttribute(requirementKey, "type"); requirement.Keys.Add(reqKey); } string newElementName = XmlParser.GetStringAttribute(CustomVar, "name"); if (newElementName != "") { XmlElement elem = xmlDoc.CreateElement(newElementName); elem.InnerText = reqHandlers.EvalRequirement(requirement); productCustomVars.AppendChild(elem); } } } }
private List <ProductSettings.ProductRequirement> ExtractProductRequirement(XmlNodeList requirementsNode) { List <ProductSettings.ProductRequirement> requirementList = new List <ProductSettings.ProductRequirement>(); foreach (XmlNode requirementNode in requirementsNode) { ProductSettings.ProductRequirement requirement = new ProductSettings.ProductRequirement { Type = XmlParser.GetStringValue(requirementNode, "Type"), LogicalOperator = XmlParser.GetStringAttribute(requirementNode, "Keys", "logicalOp"), Delta = XmlParser.GetStringValue(requirementNode, "Delta") }; if (string.IsNullOrEmpty(requirement.LogicalOperator)) { requirement.LogicalOperator = Enum.GetName(typeof(RequirementHandlers.LogicalOperatorType), RequirementHandlers.LogicalOperatorType.AND); //default value } requirement.Keys = new List <ProductSettings.RequirementKey>(); foreach (XmlNode requirementKey in requirementNode.SelectNodes("Keys/Key")) { ProductSettings.RequirementKey reqKey; reqKey.KeyValue = XmlParser.GetStringValue(requirementKey); reqKey.KeyType = XmlParser.GetStringAttribute(requirementKey, "type"); requirement.Keys.Add(reqKey); } requirement.Value = XmlParser.GetStringValue(requirementNode, "Value"); requirement.ValueOperator = XmlParser.GetStringAttribute(requirementNode, "Value", "compareOp"); requirementList.Add(requirement); } return(requirementList); }
public bool HandlersReqResult(ProductSettings.ProductRequirement requirement) { bool resB = false; try { string[] KeysArr = RequirementToArray(requirement); LogicalOperatorType logicaloperatorType = (LogicalOperatorType)Enum.Parse(typeof(LogicalOperatorType), requirement.LogicalOperator); CompareOperationType operatorType = (CompareOperationType)Enum.Parse(typeof(CompareOperationType), requirement.ValueOperator); string requirementType = requirement.Type.ToLower(); string methodResult = EvalMethod(requirementType, KeysArr, logicaloperatorType); resB = EvalOperator(methodResult, requirementType, requirement.Value, operatorType, logicaloperatorType); #if DEBUG Logger.GetLogger().Info(requirement.Type + ((KeysArr.Count() > 1) ? " {" + logicaloperatorType + "}" : "") + " (" + string.Join(", ", KeysArr) + ") <" + operatorType + "> [" + requirement.Value + "] => " + resB); #endif } #if DEBUG catch (Exception e) #else catch (Exception) #endif { #if DEBUG Logger.GetLogger().Error("Product Requirement " + requirement.Type + "failed with error message: " + e.Message); #endif } return(resB); }
public string EvalRequirement(ProductSettings.ProductRequirement requirement) { string[] KeysArr = RequirementToArray(requirement); LogicalOperatorType logicaloperatorType = (LogicalOperatorType)Enum.Parse(typeof(LogicalOperatorType), requirement.LogicalOperator); string resStr = EvalMethod(requirement.Type.ToLower(), KeysArr, logicaloperatorType); #if DEBUG Logger.GetLogger().Info(requirement.Type + ((KeysArr.Count() > 1) ? " {" + logicaloperatorType + "}" : "") + " (" + string.Join(", ", KeysArr) + ") => " + resStr); #endif return(resStr); }
public static string[] RequirementToArray(ProductSettings.ProductRequirement requirement) { List <string> KeyReqList = new List <string>(); foreach (var reqKeyName in requirement.Keys) { KeyReqList.Add(reqKeyName.KeyValue); } return(KeyReqList.ToArray()); //requirement.Keys.ToArray(); }