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 static IGrmOperatorComparer <T> GetComparerForOperand(
            GrmOperand operand)
        {
            switch (operand)
            {
            case GrmOperand.AppVersionCode:
            case GrmOperand.Ram:
            case GrmOperand.PhysicalRam:
            case GrmOperand.CpuCoresAllocated:
            case GrmOperand.PhysicalCoresAvailable:
            case GrmOperand.Dpi:
            case GrmOperand.Fps:
            case GrmOperand.AppRunningCountAcrossInstances:
                return((IGrmOperatorComparer <T>) new GenericComparer <int>());

            case GrmOperand.ProductVersion:
                return((IGrmOperatorComparer <T>) new VersionComparer());

            case GrmOperand.Geo:
            case GrmOperand.Gpu:
            case GrmOperand.GlMode:
            case GrmOperand.EngineMode:
            case GrmOperand.Resolution:
            case GrmOperand.GuestOs:
            case GrmOperand.Oem:
            case GrmOperand.BootParam:
            case GrmOperand.DeviceProfile:
            case GrmOperand.ASTCTexture:
            case GrmOperand.ABIMode:
                return((IGrmOperatorComparer <T>) new GrmStringComparer());

            case GrmOperand.Is64Bit:
            case GrmOperand.CustomKeyMappingExists:
                return((IGrmOperatorComparer <T>) new BooleanComparer());

            case GrmOperand.InstalledOems:
                return((IGrmOperatorComparer <T>) new StringListComparer());

            default:
                if (typeof(T).IsAssignableFrom(typeof(int)))
                {
                    return((IGrmOperatorComparer <T>) new GenericComparer <int>());
                }
                if (typeof(T).IsAssignableFrom(typeof(long)))
                {
                    return((IGrmOperatorComparer <T>) new GenericComparer <long>());
                }
                if (typeof(T).IsAssignableFrom(typeof(bool)))
                {
                    return((IGrmOperatorComparer <T>) new BooleanComparer());
                }
                if (typeof(T).IsAssignableFrom(typeof(string)))
                {
                    return((IGrmOperatorComparer <T>) new GrmStringComparer());
                }
                if (typeof(T).IsAssignableFrom(typeof(double)))
                {
                    return((IGrmOperatorComparer <T>) new GenericComparer <double>());
                }
                if (typeof(T).IsAssignableFrom(typeof(Decimal)))
                {
                    return((IGrmOperatorComparer <T>) new GenericComparer <Decimal>());
                }
                if (typeof(T).IsAssignableFrom(typeof(DateTime)))
                {
                    return((IGrmOperatorComparer <T>) new GenericComparer <DateTime>());
                }
                if (typeof(T).IsAssignableFrom(typeof(Version)))
                {
                    return((IGrmOperatorComparer <T>) new VersionComparer());
                }
                if (typeof(T).IsAssignableFrom(typeof(List <string>)))
                {
                    return((IGrmOperatorComparer <T>) new StringListComparer());
                }
                throw new ArgumentException("No comparer found for operand " + operand.ToString());
            }
        }
Пример #3
0
        public static IRequirementEvaluator CreateandReturnEvaluator(
            GrmOperand operand)
        {
            switch (operand)
            {
            case GrmOperand.AppVersionCode:
                return((IRequirementEvaluator) new AppVersionEvaluator());

            case GrmOperand.ProductVersion:
                return((IRequirementEvaluator) new ProductVersionEvaluator());

            case GrmOperand.Geo:
                return((IRequirementEvaluator) new GeoEvaluator());

            case GrmOperand.Gpu:
                return((IRequirementEvaluator) new GpuEvaluator());

            case GrmOperand.Ram:
                return((IRequirementEvaluator) new RamEvaluator());

            case GrmOperand.PhysicalRam:
                return((IRequirementEvaluator) new PhysicalRamEvaluator());

            case GrmOperand.GlMode:
                return((IRequirementEvaluator) new GlModeEvaluator());

            case GrmOperand.EngineMode:
                return((IRequirementEvaluator) new EngineModeEvaluator());

            case GrmOperand.Is64Bit:
                return((IRequirementEvaluator) new Is64BitEvaluator());

            case GrmOperand.CpuCoresAllocated:
                return((IRequirementEvaluator) new CpuCoresAllocatedEvaluator());

            case GrmOperand.PhysicalCoresAvailable:
                return((IRequirementEvaluator) new PhysicalCoresAvailableEvaluator());

            case GrmOperand.Dpi:
                return((IRequirementEvaluator) new DpiEvaluator());

            case GrmOperand.Fps:
                return((IRequirementEvaluator) new FpsEvaluator());

            case GrmOperand.Resolution:
                return((IRequirementEvaluator) new ResolutionEvaluator());

            case GrmOperand.GuestOs:
                return((IRequirementEvaluator) new GuestOsEvaluator());

            case GrmOperand.Oem:
                return((IRequirementEvaluator) new OemEvaluator());

            case GrmOperand.InstalledOems:
                return((IRequirementEvaluator) new InstalledOemEvaluator());

            case GrmOperand.CustomKeyMappingExists:
                return((IRequirementEvaluator) new CustomKeyMappingExistsEvaluator());

            case GrmOperand.RegistryKeyValue:
                return((IRequirementEvaluator) new RegistryKeyValueEvaluator());

            case GrmOperand.BootParam:
                return((IRequirementEvaluator) new BootParamEvaluator());

            case GrmOperand.DeviceProfile:
                return((IRequirementEvaluator) new DeviceProfileEvaluator());

            case GrmOperand.ASTCTexture:
                return((IRequirementEvaluator) new ASTCTextureEvaluator());

            case GrmOperand.ABIMode:
                return((IRequirementEvaluator) new ABIModeEvaluator());

            case GrmOperand.AppRunningCountAcrossInstances:
                return((IRequirementEvaluator) new AppRunningCountAcrossInstancesEvaluator());

            default:
                return((IRequirementEvaluator)null);
            }
        }