public static bool Evaluate(
            GrmOperand operand,
            GrmOperator oper,
            T left,
            string right,
            GrmRuleSetContext context)
        {
            IGrmOperatorComparer <T> comparerForOperand = GrmComparerFactory <T> .GetComparerForOperand(operand);

            switch (oper)
            {
            case GrmOperator.LessThan:
                return(comparerForOperand.LessThan(left, right));

            case GrmOperator.GreaterThan:
                return(comparerForOperand.GreaterThan(left, right));

            case GrmOperator.Equal:
                return(comparerForOperand.Equal(left, right));

            case GrmOperator.NotEqual:
                return(comparerForOperand.NotEqual(left, right));

            case GrmOperator.LessThanEqual:
                return(comparerForOperand.LessThanEqual(left, right));

            case GrmOperator.GreaterThanEqual:
                return(comparerForOperand.GreaterThanEqual(left, right));

            case GrmOperator.StartsWith:
                return(comparerForOperand.StartsWith(left, right, context.ContextJson));

            case GrmOperator.Contains:
                return(comparerForOperand.Contains(left, right));

            case GrmOperator.LikeRegex:
                return(comparerForOperand.LikeRegex(left, right, context.ContextJson));

            case GrmOperator.In:
                return(comparerForOperand.In(left, right));

            case GrmOperator.NotIn:
                return(comparerForOperand.NotIn(left, right));

            default:
                throw new ArgumentException("Operator could not be parsed, operator: " + oper.ToString());
            }
        }
        public GrmRuleSet EvaluateRequirement(string packageName, string vmName)
        {
            GrmRuleSetContext context = new GrmRuleSetContext()
            {
                PackageName = packageName,
                VmName      = vmName
            };

            foreach (GrmRuleSet grmRuleSet in this.GrmRuleSets)
            {
                if (!((IEnumerable <string>)RegistryManager.Instance.Guest[vmName].GrmDonotShowRuleList).Contains <string>(grmRuleSet.RuleId))
                {
                    context.RuleSetId = grmRuleSet.RuleId;
                    bool flag1 = false;
                    foreach (GrmRule rule in grmRuleSet.Rules)
                    {
                        bool flag2 = true;
                        foreach (GrmExpression expression in rule.Expressions)
                        {
                            flag2 = flag2 && expression.EvaluateExpression(context);
                            if (!flag2)
                            {
                                break;
                            }
                        }
                        if (flag2)
                        {
                            flag1 = true;
                            break;
                        }
                    }
                    if (flag1)
                    {
                        return(grmRuleSet);
                    }
                }
            }
            return((GrmRuleSet)null);
        }
 public bool EvaluateExpression(GrmRuleSetContext context)
 {
     try
     {
         if (context != null)
         {
             context.ContextJson = this.ContextJson;
         }
         int         num         = (int)Enum.Parse(typeof(GrmOperand), this.LeftOperand, true);
         GrmOperator grmOperator = (GrmOperator)Enum.Parse(typeof(GrmOperator), this.Operator, true);
         return(EvaluatorFactory.CreateandReturnEvaluator((GrmOperand)num).Evaluate(context, grmOperator, this.RightOperand));
     }
     catch (Exception ex)
     {
         Logger.Error("Exception while parsing operand for grmrule. operand: {0} operator: {1} rulesetid:{2} exception: {3}", (object)this.LeftOperand, (object)this.Operator, (object)context?.RuleSetId, (object)ex.Message);
         if (!GrmExpression._rulesetsWithException.Contains(context?.RuleSetId))
         {
             GrmExpression._rulesetsWithException.Add(context?.RuleSetId);
             ClientStats.SendMiscellaneousStatsAsync("grm_evaluation_error", RegistryManager.Instance.UserGuid, context?.RuleSetId, RegistryManager.Instance.ClientVersion, RegistryManager.Instance.Version, "bgp", context?.PackageName, ex.Message, (string)null, context?.VmName);
         }
         return(false);
     }
 }