public static void Serialize(BasicCondition _condition, ref XmlElement result) { if (result == null || _condition == null) { return; } if (result.Name != BasicCondition.xmlNodeName) { return; } Type cType = _condition.GetType(); result.SetAttribute("Type", cType.Name); FieldInfo[] variables = cType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int vi = 0; vi < variables.Length; ++vi) { FieldInfo var = variables[vi]; if (!Attribute.IsDefined(var, typeof(DtVariable))) { continue; } object value = var.GetValue(_condition); string valueStr = ParseUtil.SerializeValue(value); DtVariable varAtr = (DtVariable)Attribute.GetCustomAttribute(var, typeof(DtVariable)); result.SetAttribute(varAtr.xmlAtrName, valueStr); } }
// return root node of this sub tree public static DTNode LoadSubTree(XmlNode i_xmlNode) { XmlAttribute nameAttr = i_xmlNode.Attributes[DTNode.xmlNodeNameAtrName_]; string nodeName = nameAttr != null ? nameAttr.Value : ""; DTNode node = new DTNode(nodeName); for (int i = 0; i < i_xmlNode.ChildNodes.Count; ++i) { var curNode = i_xmlNode.ChildNodes[i]; if (curNode.Name.Equals(DTNode.xmlNodeName_)) { node.subNodes_.Add(LoadSubTree(curNode)); } else if (curNode.Name.Equals(BasicCondition.xmlNodeName)) { BasicCondition condition = BasicCondition.Deserialize(curNode as XmlElement); if (condition != null) { node.conditions_.Add(condition); } } else if (curNode.Name.Equals(BasicResult.xmlNodeName)) { BasicResult result = BasicResult.Deserialize(curNode as XmlElement); if (result != null) { node.results_.Add(result); } } } return(node); }
// not real deep copy, only copy DtVariables for editor public static DTNode DeepCopy(DTNode i_node) { DTNode retNode = new DTNode(i_node.nodeName_); for (int i = 0; i < i_node.conditions_.Count; ++i) { Type conditionType = i_node.conditions_[i].GetType(); BasicCondition tempCondition = Activator.CreateInstance(conditionType) as BasicCondition; FieldInfo[] conditionVariables = conditionType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int vi = 0; vi < conditionVariables.Length; ++vi) { FieldInfo var = conditionVariables[vi]; if (Attribute.IsDefined(var, typeof(DtVariable))) { if (var.FieldType == typeof(string) || var.FieldType.IsArray || !var.FieldType.IsClass) { var.SetValue(tempCondition, var.GetValue(i_node.conditions_[i])); } else { System.Object value = Activator.CreateInstance(var.FieldType, var.GetValue(i_node.conditions_[i])); var.SetValue(tempCondition, value); } } } retNode.conditions_.Add(tempCondition); } for (int i = 0; i < i_node.results_.Count; ++i) { Type resultType = i_node.results_[i].GetType(); BasicResult tempResult = Activator.CreateInstance(resultType) as BasicResult; FieldInfo[] resultVariables = resultType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int vi = 0; vi < resultVariables.Length; ++vi) { FieldInfo var = resultVariables[vi]; if (Attribute.IsDefined(var, typeof(DtVariable))) { if (var.FieldType == typeof(string) || var.FieldType.IsArray || !var.FieldType.IsClass) { var.SetValue(tempResult, var.GetValue(i_node.results_[i])); } else { System.Object value = Activator.CreateInstance(var.FieldType, var.GetValue(i_node.results_[i])); var.SetValue(tempResult, value); } } } retNode.results_.Add(tempResult); } for (int i = 0; i < i_node.subNodes_.Count; ++i) { retNode.subNodes_.Add(DeepCopy(i_node.subNodes_[i])); } return(retNode); }
public void SetCondition(BasicCondition Condition, ConditionUIParser Parser) { this.Condition = Condition; //this.DynamicLabel.SetParameters(Condition.Parameters); //this.DynamicLabel.SetTextFormat(Condition.Type.Text); //this.DynamicLabel.SetParser(Parser); this.DynamicLabel.SetText(Condition.Type.Text.ToString()); this.DynamicLabel.SetColors(ConditionParser.Colors); this.DynamicLabel.RedrawText(); }
protected virtual string CompileBasicCondition(SqlResult ctx, BasicCondition x) { var sql = Wrap(x.Column) + " " + x.Operator + " " + Parameter(ctx, x.Value); if (x.IsNot) { return($"NOT ({sql})"); } return(sql); }
protected virtual string CompileBasicCondition(SqlResult ctx, BasicCondition x) { var sql = $"{Wrap(x.Column)} {checkOperator(x.Operator)} {Parameter(ctx, x.Value)}"; if (x.IsNot) { return($"NOT ({sql})"); } return(sql); }
public void GetOneComponent_Prefers_Engine(string engine, string column) { Query query = new Query() .Where("generic", "foo") .ForSqlServer(q => q.Where("mssql", "foo")); BasicCondition where = query.GetOneComponent("where", engine) as BasicCondition; Assert.NotNull(where); Assert.Equal(column, where.Column); }
public void NewCondition() { BasicCondition c = new BasicCondition(); c.Type = ((ConditionHandlerWidget)TypeTabs.Tabs[0].Widgets[0]).ConditionType; c.Identifier = ":" + c.Type.Identifier; c.Parameters = c.Type.CreateBlankParameters(); this.Conditions.Add(c); RedrawConditions(); SetAllEnabled(true); ConditionList.SetSelectedIndex(this.Conditions.Count - 1); RemoveConditionButton.SetEnabled(true); ApplyButton.SetEnabled(true); }
public void SetCondition(BasicCondition Condition) { this.ActiveCondition = Condition; if (this.ActiveCondition != null && this.ActiveCondition.Type != this.ConditionType) { this.ActiveCondition.Identifier = ":" + this.ConditionType.Identifier; this.ActiveCondition.Type = this.ConditionType; this.ActiveCondition.Parameters = this.ConditionType.CreateBlankParameters(); } else if (this.ActiveCondition == null) { RadioBox.SetChecked(false); } UIParser.Load(Condition); }
public ConditionHandlerWidget(ConditionType ConditionType, IContainer Parent) : base(Parent) { this.ConditionType = ConditionType; RadioBox = new RadioBox(this); RadioBox.SetText(ConditionType.Name); RadioBox.OnCheckChanged += delegate(BaseEventArgs e) { if (RadioBox.Checked) { BasicCondition condition = GetConditionsWindow().SelectedCondition; this.SetCondition(condition); GetConditionsWindow().SetActiveType(this); } }; UIParser = new ConditionUIParser(ConditionType.UI, this); UIParser.Load(null); }
// every level, only one child will be select to enter or to execute (from the first to the last) private void DecideTree(DTNode node) { DTNode tempNode = node; while (true) { #if UNITY_EDITOR if (searchMarker_) { nodeNameLists_.Add(tempNode.nodeName_); } #endif for (int i = 0; i < tempNode.results_.Count; ++i) { OverrideFinalDecision(tempNode.results_[i]); } bool enterNextLevel = false; for (int i = 0; i < tempNode.subNodes_.Count; ++i) { bool passAllConditions = true; for (int j = 0; j < tempNode.subNodes_[i].conditions_.Count; j++) { BasicCondition tempCond = tempNode.subNodes_[i].conditions_[j]; if ((tempCond.IsConditionMet() && tempCond.nor) || (!tempCond.IsConditionMet() && !tempCond.nor)) { passAllConditions = false; break; } } if (passAllConditions) { tempNode = tempNode.subNodes_[i]; enterNextLevel = true; break; } } if (!enterNextLevel) { return; } } }
public void ConditionChanged() { if (SuspendIndexChange || this.Conditions.Count == 0) { return; } BasicCondition condition = this.Conditions[ConditionList.SelectedIndex]; for (int i = 0; i < TypeTabs.Tabs.Count; i++) { foreach (ConditionHandlerWidget chw in TypeTabs.Tabs[i].Widgets) { if (chw.ConditionType == condition.Type) { chw.SetSelected(true); chw.SetCondition(condition); } } } }
public static XmlElement SaveSubTree(DTNode i_node, XmlDocument i_ownerDoc) { XmlElement elem = i_ownerDoc.CreateElement(DTNode.xmlNodeName_); elem.SetAttribute(DTNode.xmlNodeNameAtrName_, i_node.nodeName_); for (int i = 0; i < i_node.conditions_.Count; ++i) { XmlElement conditionElem = i_ownerDoc.CreateElement(BasicCondition.xmlNodeName); BasicCondition.Serialize(i_node.conditions_[i], ref conditionElem); elem.AppendChild(conditionElem); } for (int i = 0; i < i_node.results_.Count; ++i) { XmlElement resultElem = i_ownerDoc.CreateElement(BasicResult.xmlNodeName); BasicResult.Serialize(i_node.results_[i], ref resultElem); elem.AppendChild(resultElem); } for (int i = 0; i < i_node.subNodes_.Count; ++i) { elem.AppendChild(SaveSubTree(i_node.subNodes_[i], i_ownerDoc)); } return(elem); }
public static BasicCondition Deserialize(XmlElement _node) { if (_node == null) { return(null); } if (_node.Name != BasicCondition.xmlNodeName) { return(null); } string typeStr = _node.Attributes["Type"].Value; if (typeStr == null) { return(null); } // should use qualified assemble name for reflection if type is included in namespace: Type cType = Type.GetType(GetQualifiedTypeName(typeStr)); if (cType == null) { return(null); } // start parse: BasicCondition result = (BasicCondition)Activator.CreateInstance(cType); FieldInfo[] variables = cType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int vi = 0; vi < variables.Length; ++vi) { FieldInfo var = variables[vi]; if (!Attribute.IsDefined(var, typeof(DtVariable))) { continue; } DtVariable varAtr = (DtVariable)Attribute.GetCustomAttribute(var, typeof(DtVariable)); XmlAttribute tempAttr = _node.Attributes[varAtr.xmlAtrName]; if (tempAttr == null) { continue; } string valueStr = tempAttr.Value; if (valueStr == null) { Debug.LogError("Can't find condition value " + varAtr.xmlAtrName + "in condition node."); continue; } Type _fType = var.FieldType; object value = ParseUtil.ParseValue(_fType, valueStr); if (value == null) { Debug.LogError("Can't parse condition value " + varAtr.xmlAtrName + "in condition node."); continue; } var.SetValue(result, value); } return(result); }
public void Load(BasicCondition Condition) { this.Condition = Condition; this.LoadingData = true; if (this.Condition != null) { if (this.WasNull) { foreach (string name in WidgetLookup.Keys) { SetWidgetEnabled(WidgetLookup[name], EnabledLookup[name]); } } foreach (Widget w in WidgetLookup.Values) { if (w is DynamicLabel) { //((DynamicLabel) w).SetParameters(Condition.Parameters); } } this.WasNull = false; foreach (string key in LoadFormat.Keys) { Widget w = GetWidgetFromName(key); if (w == null) { throw new Exception($"Could not find widget with identifier '{key}'"); } object value = null; if (LoadFormat[key] is Dictionary <string, object> ) { foreach (string conditional in ((Dictionary <string, object>)LoadFormat[key]).Keys) { object conditionvalue = ((Dictionary <string, object>)LoadFormat[key])[conditional]; if (Utilities.EvaluateBooleanExpression(conditional, Condition.Parameters, this)) { string cvaluestring = conditionvalue.ToString(); bool text = cvaluestring.StartsWith("$"); if (text) { value = Utilities.ProcessText(cvaluestring.Substring(1), Condition.Parameters, this, true); } else { value = Utilities.EvaluateExpression(conditionvalue.ToString(), Condition.Parameters, this); if (value is string && (string)value == conditionvalue.ToString() && !Utilities.IsNumeric((string)value)) { value = Utilities.EvaluateBooleanExpression((string)value, Condition.Parameters, this).ToString().ToLower(); } } break; } } } else if (LoadFormat[key] is string) { string fmt = (string)LoadFormat[key]; bool text = fmt.StartsWith("$"); if (text) { value = Utilities.ProcessText(fmt.Substring(1), Condition.Parameters, this, true); } else { value = Utilities.EvaluateExpression(fmt, Condition.Parameters, this); if (value is string && (string)value == fmt && !Utilities.IsNumeric((string)value)) { value = Utilities.EvaluateBooleanExpression((string)value, Condition.Parameters, this).ToString().ToLower(); } } } string identifier = GetIdentifierFromName(key); w.SetValue(identifier, value); } } else { foreach (Widget w in WidgetLookup.Values) { SetWidgetEnabled(w, false); } this.WasNull = true; } this.LoadingData = false; }