} // isMandatory /// <summary> ///Field is Displayed /// </summary> /// <param name="eval"></param> /// <returns></returns> public bool IsDisplayed(Evaluatee eval) { // ** static content ** // not displayed if (!IsDisplayedf) { return(false); } // no restrictions String logic = DisplayLogic; if (logic == null || logic.Equals("")) { return(true); } // ** dynamic content ** if (eval != null) { bool retValue = Evaluator.EvaluateLogic(eval, logic); //if(Build.isVerbose()) //log.finest(ColumnName // + " (" + logic + ") => " + retValue); return(retValue); } return(true); }
public void ShouldCreateInstance() { // arrange var employee = new Employee(101, "John Doe"); // act var result = new Evaluatee(employee); // assert Assert.Equal(employee, result.Employee); Assert.NotNull(result.Evaluations); }
// constructors public Employee(uint number, string name) : base() { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } Number = number; Name = name; Profile = new PersonalProfile(this); Evaluatee = new Evaluatee(this); SkillEvaluator = new SkillEvaluator(this); }
/// <summary> ///Evaluate Logic. ///<code> ///format := <expression> [<logic> <expression>] ///expression := @<context>@<exLogic><value> ///logic := <|> | <&> ///exLogic := <=> | <!> | <^> | <<> | <>> ///context := any global or window context ///value := strings can be with ' or " ///logic operators := AND or OR with the prevoius result from left to right ///Example '@AD_Table@=Test | @Language@=GERGER /// </code> /// </summary> /// <param name="source">class implementing get_ValueAsString(variable)</param> /// <param name="logic">logic string</param> /// <returns>locic result</returns> public static bool EvaluateLogic(Evaluatee source, String logic) { // Conditional StringTokenizer st = new StringTokenizer(logic.Trim(), "&|", true); try { int it = st.CountTokens(); if (((it / 2) - ((it + 1) / 2)) == 0) // only uneven arguments { //log.severe("Logic does not comply with format " // + "'<expression> [<logic> <expression>]' => " + logic); return(false); } bool retValue = EvaluateLogicTuple(source, st.NextToken()); while (st.HasMoreTokens()) { String logOp = st.NextToken().Trim(); bool temp = EvaluateLogicTuple(source, st.NextToken()); if (logOp.Equals("&")) { retValue = retValue & temp; } else if (logOp.Equals("|")) { retValue = retValue | temp; } else { //Common.////ErrorLog.FillErrorLog("Evaluatot.EvaluateLogic()", "DynamicDisplay", "Logic operant '|' or '&' expected => " + logic, VAdvantage.Framework.Message.MessageType.ERROR); //log.warning("Logic operant '|' or '&' expected => " + logic); return(false); } } return(retValue); } catch { return(false); } }
} // isEditable /// <summary> ///Is field is mandatory /// </summary> /// <param name="eval">context value</param> /// <returns>true if mandatory</returns> public bool IsMandatory(Evaluatee eval) { if (IsVirtualColumn) { return(false); } // Not Mandatory String logic = mandatoryLogic; if (!IsMandatoryUI && (logic == null || logic.Length == 0)) { return(false); } // Numeric Keys and Created/Updated as well as // DocumentNo/Value/ASI ars not mandatory (persistency layer manages them) if ((IsKey && ColumnName.EndsWith("_ID")) || ColumnName.StartsWith("Created") || ColumnName.StartsWith("Updated") || ColumnName.Equals("Value") || ColumnName.Equals("DocumentNo") || ColumnName.Equals("M_AttributeSetInstance_ID")) // 0 is valid { return(false); } // Mandatory Logic if (logic != null && logic.Length > 0) { if (Evaluator.EvaluateLogic(eval, logic)) { return(true); } } // Mandatory only if displayed return(IsDisplayed(eval)); } // isMandatory
/// <summary> ///Check if All Variables are Defined /// </summary> /// <param name="source">source</param> /// <param name="logic">logic info</param> /// <returns>true if fully defined</returns> public static bool IsAllVariablesDefined(Evaluatee source, string logic) { if (logic == null || logic.Length == 0) { return(true); } // int pos = 0; while (pos < logic.Length) { int first = logic.IndexOf('@', pos); if (first == -1) { return(true); } //int second = logic.Substring(first + 1); int second = logic.IndexOf('@', first + 1); if (second == -1) { //log.severe("No second @ in Logic: " + logic); return(false); } //string variable = logic.substring(first + 1, second - 1); string variable = logic.Substring(first + 1, second - 1); String eval = source.GetValueAsString(variable); //log.finest(variable + "=" + eval); if (eval == null || eval.Length == 0) { return(false); } // pos = second + 1; } return(true); }
/// <summary> ///Evaluate @context@=value or @context@!value or @context@^value. ///<pre> ///value: strips ' and " always (no escape or mid stream) ///value: can also be a context variable ///</pre> ///@param source /// </summary> /// <param name="source">class implementing get_ValueAsString(variable)</param> /// <param name="logic">logic tuple</param> /// <returns>true or false</returns> private static bool EvaluateLogicTuple(Evaluatee source, string logic) { StringTokenizer st = new StringTokenizer(logic.Trim(), "!=^><", true); if (st.CountTokens() != 3) { //log.warning("Logic tuple does not comply with format " // + "'@context@=value' where operand could be one of '=!^><' => " + logic); return(false); } // First Part String first = st.NextToken().Trim(); // get '@tag@' String firstEval = first.Trim(); if (first.IndexOf('@') != -1) // variable { first = first.Replace('@', ' ').Trim(); // strip 'tag' //firstEval = source.get_ValueAsString(first); // replace with it's value firstEval = source.GetValueAsString(first); if (firstEval == null) { firstEval = ""; } } firstEval = firstEval.Replace('\'', ' ').Replace('"', ' ').Trim(); // strip ' and " // Comperator String operand = st.NextToken(); // Second Part String second = st.NextToken(); // get value String secondEval = second.Trim(); if (second.IndexOf('@') != -1) // variable { second = second.Replace('@', ' ').Trim(); // strip tag //secondEval = source.get_ValueAsString(second); // replace with it's value secondEval = source.GetValueAsString(second); // replace with it's value if (secondEval == null) { secondEval = ""; } } secondEval = secondEval.Replace('\'', ' ').Replace('"', ' ').Trim(); // strip ' and " // Handling of ID compare (null => 0) if (first.IndexOf("_ID") != -1 && firstEval.Length == 0) { firstEval = "0"; } if (second.IndexOf("_ID") != -1 && secondEval.Length == 0) { secondEval = "0"; } // Logical Comparison bool result = EvaluateLogicTuple(firstEval, operand, secondEval); //if (log.isLevelFinest()) // log.finest(logic // + " => \"" + firstEval + "\" " + operand + " \"" + secondEval + "\" => " + result); // return(result); }
/// <summary> ///Is it Editable - checks IsActive, IsUpdateable, and isDisplayed /// </summary> /// <param name="ctx">context</param> /// <param name="eval">context value</param> /// <param name="tabReadOnly">is tab readonly</param> /// <param name="rowReadOnly">data roe read only</param> /// <param name="tabLinkColumn">link column</param> /// <param name="inserting">is new record</param> /// <returns>if readonly then false</returns> public bool IsEditable(Ctx ctx, Evaluatee eval, bool tabReadOnly, bool rowReadOnly, String tabLinkColumn, bool inserting) { if (IsVirtualColumn) { return(false); } // Fields always enabled (are usually not updateable) if (ColumnName.Equals("Posted") || (ColumnName.Equals("Record_ID") && displayType == FieldType.Button)) // Zoom { return(true); } // Fields always updareable if (IsAlwaysUpdateable) // Zoom { return(true); } // Tab or field is R/O if (tabReadOnly || IsReadOnly) { //if(Build.isVerbose()) //log.finest(ColumnName + " NO - TabRO=" + tabReadOnly + ", FieldRO=" + IsReadOnly); return(false); } // Not Updateable - only editable if new updateable row if (!IsUpdateable && !inserting) { //if(Build.isVerbose()) //log.finest(ColumnName + " NO - FieldUpdateable=" + IsUpdateable); return(false); } // Field is the Link Column of the tab String linkColumn = tabLinkColumn; if (ColumnName.Equals(linkColumn)) { //if(Build.isVerbose()) //log.finest(ColumnName + " NO - LinkColumn"); return(false); } //FIXME comment this out need to go back server for this information // Role Access & Column Access // if (ctx != null) // { // int AD_Client_ID = ctx.getAD_Client_ID(windowNo); // int AD_Org_ID = ctx.getAD_Org_ID(windowNo); // String keyColumn = tabKeyColumn; // if ("EntityType".Equals(keyColumn)) // keyColumn = "AD_EntityType_ID"; // if (!keyColumn.endsWith("_ID")) // keyColumn += "_ID"; // AD_Language_ID // int Record_ID = ctx.getContextAsInt(keyColumn); // MRole role = MRole.getDefault(ctx, false); //if (!role.canUpdate(AD_Client_ID, AD_Org_ID, AD_Table_ID, Record_ID, false)) //return false; //if (!role.isColumnAccess(AD_Table_ID, AD_Column_ID, false)) // return false; // } if (rowReadOnly) { return(false); } if (!isColumnAccess) { return(false); } // Do we have a readonly rule String logic = ReadOnlyLogic; if (logic != null && logic.Length > 0) { bool retValue = !Evaluator.EvaluateLogic(eval, logic); //if(Build.isVerbose()) //log.finest(ColumnName + " R/O(" + logic + ") => R/W-" + retValue); if (!retValue) { return(false); } } // Always editable if Active if (ColumnName.Equals("Processing") || ColumnName.Equals("DocAction") || ColumnName.Equals("GenerateTo")) { return(true); } // Record is Processed *** if (ctx != null && (ctx.IsProcessed(windowNo) || ctx.IsProcessing(windowNo))) { return(false); } // IsActive field is editable, if record not processed if (ColumnName.Equals("IsActive")) { return(true); } // Record is not Active if (ctx != null && !ctx.IsActive(windowNo)) { //if(Build.isVerbose()) // log.finest(ColumnName + " Record not active"); return(false); } if (inserting) { return(true); } // ultimately visibily decides return(IsDisplayed(eval)); } // isEditable