private static string LogicalOperatorAppend(this LogicalOperatorType logicalOperatorType) { switch (logicalOperatorType) { case LogicalOperatorType.Equal: return(""); case LogicalOperatorType.Greater: return(""); case LogicalOperatorType.Less: return(""); case LogicalOperatorType.UnEqual: return(""); case LogicalOperatorType.Like: return("%"); case LogicalOperatorType.In: return(")"); default: throw new ArgumentOutOfRangeException("logicalOperatorType", logicalOperatorType, null); } }
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 static string CompareLogicalOper(bool[] arrB, LogicalOperatorType operation) { string match = "false"; switch (operation) { case LogicalOperatorType.AND: if (arrB.All(x => x)) { match = "true"; } break; case LogicalOperatorType.OR: if (arrB.Any(x => x)) { match = "true"; } break; case LogicalOperatorType.NOT: if (arrB.All(x => !x)) { match = "true"; } break; default: throw new ArgumentOutOfRangeException(); } return(match); }
private static string GetLogicalOperatorStr(this LogicalOperatorType logicalOperatorType) { switch (logicalOperatorType) { case LogicalOperatorType.Equal: return(" = "); case LogicalOperatorType.Greater: return(" > "); case LogicalOperatorType.Less: return(" < "); case LogicalOperatorType.UnEqual: return(" != "); case LogicalOperatorType.Like: return(" LIKE '%"); case LogicalOperatorType.In: return(" IN ("); default: throw new ArgumentOutOfRangeException("logicalOperatorType", logicalOperatorType, null); } }
public static bool CompareOperation(string value1, string value2, CompareOperationType operation, LogicalOperatorType logicalOperatorType = LogicalOperatorType.OR) { bool val1Parsed = double.TryParse(value1, out double val1); bool val2Parsed = double.TryParse(value2, out double val2); bool match = operation switch { CompareOperationType.Contains => value1.Contains(value2), CompareOperationType.StartsWith => value1.StartsWith(value2), CompareOperationType.EndsWith => value1.EndsWith(value2), CompareOperationType.Equal => (val1Parsed && val2Parsed && Equals(val1, val2)) || value1.Equals(value2), CompareOperationType.Greater => val1Parsed && val2Parsed && val1 > val2, CompareOperationType.GreaterEqual => val1Parsed && val2Parsed && val1 >= val2, CompareOperationType.Less => val1Parsed && val2Parsed && val1 < val2, CompareOperationType.LessEqual => val1Parsed && val2Parsed && val1 <= val2, _ => throw new ArgumentOutOfRangeException(), }; if (logicalOperatorType == LogicalOperatorType.NOT) { match = !match; } return(match); }
public LogicalOperator(LogicalOperatorType logicalOperatorType, NuGetLicenseExpression left, NuGetLicenseExpression right) : base(LicenseOperatorType.LogicalOperator) { LogicalOperatorType = logicalOperatorType; Left = left ?? throw new ArgumentNullException(nameof(left)); Right = right ?? throw new ArgumentNullException(nameof(right)); }
/// <summary> /// Operators the popup. /// </summary> /// <returns>The popup.</returns> /// <param name="_selected">Selected.</param> /// <param name="_options">Options.</param> public static LogicalOperatorType OperatorPopup(LogicalOperatorType _selected, params GUILayoutOption[] _options) { string[] _values = new string[2]; _values[(int)LogicalOperatorType.EQUAL] = "IS"; _values[(int)LogicalOperatorType.NOT] = "NOT"; return((LogicalOperatorType)EditorGUILayout.Popup((int)_selected, _values, _options)); }
public ExpressionBlock(LogicalOperatorType logicalOperator, params IBoolExpression[] expression) { Expressions = new List <IBoolExpression>(); LogicalOperator = logicalOperator; ValidateExpressionParams(expression); AddBoolExpression(expression); }
public static bool CompareOperation(string value1, string value2, CompareOperationType operation, LogicalOperatorType logicalOperatorType = LogicalOperatorType.OR) { bool match; if (operation == CompareOperationType.Contains) { match = value1.Contains(value2); } else if (operation == CompareOperationType.StartsWith) { match = value1.StartsWith(value2); } else if (operation == CompareOperationType.EndsWith) { match = value1.EndsWith(value2); } else { var val1 = Convert.ToDouble(value1); var val2 = Convert.ToDouble(value2); switch (operation) { case CompareOperationType.Equal: match = Equals(val1, val2); break; case CompareOperationType.Greater: match = val1 > val2; break; case CompareOperationType.GreaterEqual: match = val1 >= val2; break; case CompareOperationType.Less: match = val1 < val2; break; case CompareOperationType.LessEqual: match = val1 <= val2; break; default: throw new ArgumentOutOfRangeException(); } } if (logicalOperatorType == LogicalOperatorType.NOT) { match = !match; } return(match); }
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 LogicalOperator(string encoded) { allowSymbols = true; operatorType = OperatorType.Logical; var split = encoded.Split(':'); var enumNumber = int.Parse(split[0]); opType = (LogicalOperatorType)enumNumber; identifier = split[1]; base.type = TokenType.LogicalOperator; }
public override void OnGui() { EditorGUILayout.BeginHorizontal(); m_LogicalType = (LogicalOperatorType)EditorGUILayout.EnumPopup(m_LogicalType); EditorGUILayout.EndHorizontal(); if (m_LogicalType == LogicalOperatorType.NOT) m_MaxChildren = 1; else m_MaxChildren = 2; }
/// <summary> /// Logicals the operator popup. /// </summary> /// <returns>The operator popup.</returns> /// <param name="_selected">Selected.</param> /// <param name="_options">Options.</param> public static LogicalOperatorType LogicalOperatorPopup(LogicalOperatorType _selected, params GUILayoutOption[] _options) { string[] _values = new string[6]; _values[(int)LogicalOperatorType.EQUAL] = "=="; _values[(int)LogicalOperatorType.NOT] = "!="; _values[(int)LogicalOperatorType.LESS] = "<"; _values[(int)LogicalOperatorType.LESS_OR_EQUAL] = "<="; _values[(int)LogicalOperatorType.GREATER] = ">"; _values[(int)LogicalOperatorType.GREATER_OR_EQUAL] = ">="; return((LogicalOperatorType)EditorGUILayout.Popup((int)_selected, _values, _options)); }
public bool HandlersResult(ref ProductSettings.ProductRequirements requirements) { bool resB = true; if ((requirements.RequirementList == null) || (requirements.RequirementList == null) || (requirements.RequirementList.Count + requirements.RequirementsList.Count == 0)) { return(resB); } LogicalOperatorType logicaloperatorType = (LogicalOperatorType)Enum.Parse(typeof(LogicalOperatorType), requirements.LogicalOperator); int reqCount = requirements.RequirementList.Count + requirements.RequirementsList.Count; List <bool> arrBool = new List <bool>(); foreach (var req in requirements.RequirementList) { resB = HandlersReqResult(req); if ((reqCount > 1) && ((resB && (logicaloperatorType == LogicalOperatorType.OR)) || (!resB && (logicaloperatorType == LogicalOperatorType.AND)))) { #if DEBUG Logger.GetLogger().Info(reqCount + " Requirements {" + logicaloperatorType + "} => " + resB); #endif if (!resB) { requirements.UnfulfilledRequirementType = req.Type; requirements.UnfulfilledRequirementDelta = req.Delta; } return(resB); } arrBool.Add(resB); } foreach (ProductSettings.ProductRequirements reqs in requirements.RequirementsList) { ProductSettings.ProductRequirements reqsCopy = reqs; resB = HandlersResult(ref reqsCopy); if ((reqCount > 1) && ((resB && (logicaloperatorType == LogicalOperatorType.OR)) || (!resB && (logicaloperatorType == LogicalOperatorType.AND)))) { #if DEBUG Logger.GetLogger().Info(reqCount + " Requirements {" + logicaloperatorType + "} => " + resB); #endif return(resB); } arrBool.Add(resB); } resB = bool.Parse(CompareLogicalOper(arrBool.ToArray(), logicaloperatorType)); #if DEBUG Logger.GetLogger().Info(((reqCount > 1) ? reqCount.ToString() + " " : "") + "Requirements {" + logicaloperatorType + "} => " + resB); #endif return(resB); }
public Condition(string leftSidePropertyName, BoolComparisonType comparison = BoolComparisonType.Equals, object rightSideValueOrProperty = null, LogicalOperatorType sufixOperator = LogicalOperatorType.And) : base(typeof(T), null, leftSidePropertyName, typeof(K), null, rightSideValueOrProperty, comparison, sufixOperator) { }
private string DrawConditionsWizard(string luaCode) { EditorGUILayout.BeginVertical("button"); EditorGUI.BeginChangeCheck(); // Condition items: ConditionItem itemToDelete = null; foreach (ConditionItem item in conditionItems) { DrawConditionItem(item, ref itemToDelete); } if (itemToDelete != null) { conditionItems.Remove(itemToDelete); } // Logical operator (Any/All) and add new condition button: // Revert and Apply buttons: EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("+", "Add a new condition."), EditorStyles.miniButton, GUILayout.Width(22))) { conditionItems.Add(new ConditionItem()); } conditionsLogicalOperator = (LogicalOperatorType)EditorGUILayout.EnumPopup(conditionsLogicalOperator, GUILayout.Width(48)); EditorGUILayout.LabelField("must be true.", GUILayout.Width(80)); GUILayout.FlexibleSpace(); append = EditorGUILayout.ToggleLeft("Append", append, GUILayout.Width(60)); if (EditorGUI.EndChangeCheck()) { ApplyConditionsWizard(); } if (GUILayout.Button(new GUIContent("Revert", "Cancel these settings."), EditorStyles.miniButton, GUILayout.Width(48))) { luaCode = CancelConditionsWizard(); } if (GUILayout.Button(new GUIContent("Apply", "Apply these settings"), EditorStyles.miniButton, GUILayout.Width(48))) { luaCode = AcceptConditionsWizard(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); return(luaCode); }
public override void OnGui() { EditorGUILayout.BeginHorizontal(); m_LogicalType = (LogicalOperatorType)EditorGUILayout.EnumPopup(m_LogicalType); EditorGUILayout.EndHorizontal(); if (m_LogicalType == LogicalOperatorType.NOT) { m_MaxChildren = 1; } else { m_MaxChildren = 2; } }
public string EvalMethod(string requirementType, string[] KeysArr, LogicalOperatorType logicalOperatorType) { string retStr = ""; switch (requirementType) { case RequirementType.Disk: case RequirementType.Ram: case RequirementType.BrowserVersion: case RequirementType.RegistryKeyValue: case RequirementType.ConfigValue: retStr = methodsMap[requirementType](KeysArr); break; case RequirementType.Processor: case RequirementType.BrowserDefault: case RequirementType.OSVersion: retStr = methodsMap[requirementType](new string[] { }); break; case RequirementType.Process: case RequirementType.BrowserInstalled: case RequirementType.RegistryKeyExists: case RequirementType.HasAdminPrivileges: case RequirementType.UserAdmin: case RequirementType.FileExists: List <bool> arrBool = new List <bool>(); foreach (var key in KeysArr) { arrBool.Add(ToBoolean(methodsMap[requirementType](new string[] { key }))); } retStr = CompareLogicalOper(arrBool.ToArray(), logicalOperatorType); break; default: break; } return(retStr); }
private string DrawConditionsWizard(string luaCode) { EditorGUILayout.BeginVertical("button"); EditorGUI.BeginChangeCheck(); // Condition items: ConditionItem itemToDelete = null; foreach (ConditionItem item in conditionItems) { DrawConditionItem(item, ref itemToDelete); } if (itemToDelete != null) conditionItems.Remove(itemToDelete); // Logical operator (Any/All) and add new condition button: // Revert and Apply buttons: EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("+", "Add a new condition."), EditorStyles.miniButton, GUILayout.Width(22))) { conditionItems.Add(new ConditionItem()); } conditionsLogicalOperator = (LogicalOperatorType) EditorGUILayout.EnumPopup(conditionsLogicalOperator, GUILayout.Width(48)); EditorGUILayout.LabelField("must be true."); GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace(); if (EditorGUI.EndChangeCheck()) ApplyConditionsWizard(); if (GUILayout.Button(new GUIContent("Revert", "Cancel these settings."), EditorStyles.miniButton, GUILayout.Width(48))) { luaCode = CancelConditionsWizard(); } if (GUILayout.Button(new GUIContent("Apply", "Apply these settings"), EditorStyles.miniButton, GUILayout.Width(48))) { luaCode = AcceptConditionsWizard(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); return luaCode; }
public static ParmInfo AddParameter(string parmName, object parmValue, QueryOperatorType parmQueryOperator, LogicalOperatorType parmLogicalOperator, DbType parmDbType, ParameterDirection parmParameterDirection = ParameterDirection.Input) { return(new ParmInfo { Name = parmName, DbType = parmDbType, ParameterDirection = parmParameterDirection, DataValue = parmValue, LogicalOperator = parmLogicalOperator, QueryOperator = QueryOperatorType.Equals }); }
private LogicalOperatorKeyword(LogicalOperatorType logicalOperatorType) { LogicalOperatorType = logicalOperatorType; }
public override string ToString() { return($"{Left.ToString()} {LogicalOperatorType.ToString().ToUpper()} {Right.ToString()}"); }
public override string ToString() { return($"{KeywordType}: {LogicalOperatorType.ToString()}"); }
public LogicalOperator(LogicalOperatorType logicalOperator) { Value = logicalOperator; }
public string GetLogicalOperatorText(LogicalOperatorType logicalOperator) { return (logicalOperator == LogicalOperatorType.All) ? "and" : "or"; }
private bool EvalOperator(string methodResult, string requirementType, string requirementValue, CompareOperationType operatorType, LogicalOperatorType logicalOperatorType) { bool resB = true; switch (requirementType) { case RequirementType.Disk: case RequirementType.Ram: case RequirementType.BrowserDefault: case RequirementType.Processor: case RequirementType.ConfigValue: resB = CompareOperation(methodResult, requirementValue, operatorType, logicalOperatorType); break; case RequirementType.OSVersion: int index = methodResult.IndexOf('.'); resB = CompareOperation(methodResult.Substring(0, index + 2), requirementValue, operatorType, logicalOperatorType); break; case RequirementType.BrowserVersion: case RequirementType.RegistryKeyValue: if (string.IsNullOrEmpty(methodResult)) { resB = (LogicalOperatorType.NOT == logicalOperatorType); } else if (operatorType >= CompareOperationType.Contains || double.TryParse(methodResult, out _)) //True if it succeeds in parsing, false if it fails { resB = CompareOperation(methodResult, requirementValue, operatorType, logicalOperatorType); } else if (IsVersionOnly(methodResult) && IsVersionOnly(requirementValue)) { resB = CompareTwoVersions(methodResult, requirementValue, operatorType); } else { resB = methodResult.Equals(requirementValue); } break; case RequirementType.Process: case RequirementType.BrowserInstalled: case RequirementType.RegistryKeyExists: case RequirementType.HasAdminPrivileges: case RequirementType.UserAdmin: case RequirementType.FileExists: resB = ToBoolean(methodResult) == ToBoolean(requirementValue); break; default: break; } return(resB); }
public static void GetWhere(LinkType linkType, string columnName, object value, LogicalOperatorType logicalOperatorType, ref StringBuilder stringBuilder) { switch (value.GetType().Name) { case "String": case "DateTime": stringBuilder.Append(linkType.GetLinkStr() + columnName + logicalOperatorType.GetLogicalOperatorStr() + "'" + value + "'" + logicalOperatorType.LogicalOperatorAppend() + linkType.LinkAppend()); break; case "Double": case "Decimal": case "Single": stringBuilder.Append(linkType.GetLinkStr() + columnName + logicalOperatorType.GetLogicalOperatorStr() + value + logicalOperatorType.LogicalOperatorAppend() + linkType.LinkAppend()); break; } }
private string DrawConditionsWizard(Rect position, string luaCode) { int originalIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; var rect = new Rect(position.x, position.y, position.width, position.height); var x = position.x; var y = position.y; EditorGUI.BeginChangeCheck(); // Condition items: ConditionItem itemToDelete = null; foreach (ConditionItem item in conditionItems) { var innerHeight = EditorGUIUtility.singleLineHeight + 2; var innerRect = new Rect(x, y, position.width, innerHeight); GUI.BeginGroup(innerRect); DrawConditionItem(new Rect(0, 0, position.width, innerHeight), item, ref itemToDelete); GUI.EndGroup(); y += EditorGUIUtility.singleLineHeight + 2; } if (itemToDelete != null) conditionItems.Remove(itemToDelete); // Bottom row (add condition item, logical operator, Revert & Apply buttons): x = 0; y = position.height - (EditorGUIUtility.singleLineHeight); rect = new Rect(x, y, 22, EditorGUIUtility.singleLineHeight); if (GUI.Button(rect, new GUIContent("+", "Add a new condition."), EditorStyles.miniButton)) { conditionItems.Add(new ConditionItem()); } x += rect.width + 2; rect = new Rect(x, y, 74, EditorGUIUtility.singleLineHeight); conditionsLogicalOperator = (LogicalOperatorType) EditorGUI.EnumPopup(rect, conditionsLogicalOperator); x += rect.width + 2; rect = new Rect(x, y, 128, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(rect, "must be true."); if (EditorGUI.EndChangeCheck()) ApplyConditionsWizard(); EditorGUI.BeginDisabledGroup(conditionItems.Count <= 0); rect = new Rect(position.width - 48 - 4 - 48, y, 48, EditorGUIUtility.singleLineHeight); if (GUI.Button(rect, new GUIContent("Revert", "Cancel these settings."), EditorStyles.miniButton)) { luaCode = CancelConditionsWizard(); } rect = new Rect(position.width - 48, y, 48, EditorGUIUtility.singleLineHeight); if (GUI.Button(rect, new GUIContent("Apply", "Apply these settings"), EditorStyles.miniButton)) { luaCode = AcceptConditionsWizard(); } EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel = originalIndentLevel; return luaCode; }
public string GetLogicalOperatorText(LogicalOperatorType logicalOperator) { return((logicalOperator == LogicalOperatorType.All) ? "and" : "or"); }
public void AddCondition(ICondition condition, LogicalOperatorType logicalOperator) { ConditionLine.Add(condition); ConditionLine.Add(new LogicalOperator(logicalOperator)); }
private string DrawConditionsWizard(Rect position, string luaCode) { int originalIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; var rect = position; var x = position.x; var y = position.y; EditorGUI.BeginChangeCheck(); // Condition items: ConditionItem itemToDelete = null; foreach (ConditionItem item in conditionItems) { var innerHeight = EditorGUIUtility.singleLineHeight + 2; //var innerRect = new Rect(x, y, position.width, innerHeight); DrawConditionItem(new Rect(x, y, position.width, innerHeight), item, ref itemToDelete); y += EditorGUIUtility.singleLineHeight + 2; } if (itemToDelete != null) { conditionItems.Remove(itemToDelete); } // Bottom row (add condition item, logical operator, Revert & Apply buttons): x = position.x; y = position.y + position.height - EditorGUIUtility.singleLineHeight; rect = new Rect(x, y, 22, EditorGUIUtility.singleLineHeight); if (GUI.Button(rect, new GUIContent("+", "Add a new condition."), EditorStyles.miniButton)) { conditionItems.Add(new ConditionItem()); } x += rect.width + 2; rect = new Rect(x, y, 64, EditorGUIUtility.singleLineHeight); conditionsLogicalOperator = (LogicalOperatorType)EditorGUI.EnumPopup(rect, GUIContent.none, conditionsLogicalOperator); x += rect.width + 2; rect = new Rect(x, y, 84, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(rect, "must be true."); x += rect.width + 2; rect = new Rect(x, y, 72, EditorGUIUtility.singleLineHeight); append = EditorGUI.ToggleLeft(rect, "Append", append); if (EditorGUI.EndChangeCheck()) { ApplyConditionsWizard(); } EditorGUI.BeginDisabledGroup(conditionItems.Count <= 0); rect = new Rect(position.x + position.width - 48 - 4 - 48, y, 48, EditorGUIUtility.singleLineHeight); if (GUI.Button(rect, new GUIContent("Revert", "Cancel these settings."), EditorStyles.miniButton)) { luaCode = CancelConditionsWizard(); } rect = new Rect(position.x + position.width - 48, y, 48, EditorGUIUtility.singleLineHeight); GUI.Box(rect, GUIContent.none); if (GUI.Button(rect, new GUIContent("Apply", "Apply these settings"), EditorStyles.miniButton)) { luaCode = AcceptConditionsWizard(); } EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel = originalIndentLevel; return(luaCode); }
public QueryBuilder WithAndOperator() { _operatorType = LogicalOperatorType.And; return(this); }
public Condition(Condition left, LogicalOperatorType type, Condition right) { _leftCondition = left; _logicalOperator = type; _rightCondition = right; }
public QueryBuilder WithOrOperator() { _operatorType = LogicalOperatorType.Or; return(this); }
public ExistenceCondition(QueryBuilder innerExistsQuery, ExistenceType existenceType = ExistenceType.Exists, LogicalOperatorType sufixOperator = LogicalOperatorType.And) { InnerQuery = innerExistsQuery; ExistenceType = existenceType; LogicalOperator = sufixOperator; }
private void AddLogicalExp(LogicalOperatorType type) { if (Placeholder != null && Placeholder.ReplaceCommand != null) { Placeholder.ReplaceCommand.Execute(new LogicalExpression() { Parent = Placeholder.Parent, Type = type }); } }