public ODataValidationSettings()
 {
     // default it to all the operators
     _allowedArithmeticOperators = AllowedArithmeticOperators.All;
     _allowedFunctionNames = AllowedFunctionNames.AllFunctionNames;
     _allowedLogicalOperators = AllowedLogicalOperators.All;
     _allowedQueryParameters = AllowedQueryOptions.All;
     _allowedOrderByProperties = new Collection<string>();
 }
 public ODataValidationSettings()
 {
     // default it to all the operators
     _allowedArithmeticOperators = AllowedArithmeticOperators.All;
     _allowedFunctionNames       = AllowedFunctionNames.AllFunctionNames;
     _allowedLogicalOperators    = AllowedLogicalOperators.All;
     _allowedQueryParameters     = AllowedQueryOptions.All;
     _allowedOrderByProperties   = new Collection <string>();
 }
        private static void ValidateFunction(string functionName, ODataValidationSettings settings)
        {
            AllowedFunctionNames convertedFunctionName = ToODataFunctionNames(functionName);

            if ((settings.AllowedFunctionNames & convertedFunctionName) != convertedFunctionName)
            {
                // this means the given function is not allowed
                throw new ODataException(Error.Format(SRResources.NotAllowedFunctionName, functionName, "AllowedFunctionNames"));
            }
        }
        private static AllowedFunctionNames ToODataFunctionNames(string functionName)
        {
            AllowedFunctionNames result = AllowedFunctionNames.None;

            switch (functionName)
            {
            case "any":
                result = AllowedFunctionNames.Any;
                break;

            case "all":
                result = AllowedFunctionNames.All;
                break;

            case "cast":
                result = AllowedFunctionNames.Cast;
                break;

            case ClrCanonicalFunctions.CeilingFunctionName:
                result = AllowedFunctionNames.Ceiling;
                break;

            case ClrCanonicalFunctions.ConcatFunctionName:
                result = AllowedFunctionNames.Concat;
                break;

            case ClrCanonicalFunctions.DayFunctionName:
                result = AllowedFunctionNames.Day;
                break;

            case ClrCanonicalFunctions.DaysFunctionName:
                result = AllowedFunctionNames.Days;
                break;

            case ClrCanonicalFunctions.EndswithFunctionName:
                result = AllowedFunctionNames.EndsWith;
                break;

            case ClrCanonicalFunctions.FloorFunctionName:
                result = AllowedFunctionNames.Floor;
                break;

            case ClrCanonicalFunctions.HourFunctionName:
                result = AllowedFunctionNames.Hour;
                break;

            case ClrCanonicalFunctions.HoursFunctionName:
                result = AllowedFunctionNames.Hours;
                break;

            case ClrCanonicalFunctions.IndexofFunctionName:
                result = AllowedFunctionNames.IndexOf;
                break;

            case "IsOf":
                result = AllowedFunctionNames.IsOf;
                break;

            case ClrCanonicalFunctions.LengthFunctionName:
                result = AllowedFunctionNames.Length;
                break;

            case ClrCanonicalFunctions.MinuteFunctionName:
                result = AllowedFunctionNames.Minute;
                break;

            case ClrCanonicalFunctions.MinutesFunctionName:
                result = AllowedFunctionNames.Minutes;
                break;

            case ClrCanonicalFunctions.MonthFunctionName:
                result = AllowedFunctionNames.Month;
                break;

            case ClrCanonicalFunctions.MonthsFunctionName:
                result = AllowedFunctionNames.Months;
                break;

            case ClrCanonicalFunctions.RoundFunctionName:
                result = AllowedFunctionNames.Round;
                break;

            case ClrCanonicalFunctions.SecondFunctionName:
                result = AllowedFunctionNames.Second;
                break;

            case ClrCanonicalFunctions.SecondsFunctionName:
                result = AllowedFunctionNames.Seconds;
                break;

            case ClrCanonicalFunctions.StartswithFunctionName:
                result = AllowedFunctionNames.StartsWith;
                break;

            case ClrCanonicalFunctions.SubstringFunctionName:
                result = AllowedFunctionNames.Substring;
                break;

            case ClrCanonicalFunctions.SubstringofFunctionName:
                result = AllowedFunctionNames.SubstringOf;
                break;

            case ClrCanonicalFunctions.TolowerFunctionName:
                result = AllowedFunctionNames.ToLower;
                break;

            case ClrCanonicalFunctions.ToupperFunctionName:
                result = AllowedFunctionNames.ToUpper;
                break;

            case ClrCanonicalFunctions.TrimFunctionName:
                result = AllowedFunctionNames.Trim;
                break;

            case ClrCanonicalFunctions.YearFunctionName:
                result = AllowedFunctionNames.Year;
                break;

            case ClrCanonicalFunctions.YearsFunctionName:
                result = AllowedFunctionNames.Years;
                break;

            default:
                // should never be here
                Contract.Assert(true, "ToODataFunctionNames should never be here.");
                break;
            }

            return(result);
        }