Esempio n. 1
0
        private PermissionPolicyRole GetUserRole()
        {
            PermissionPolicyRole userRole = ObjectSpace.FirstOrDefault <PermissionPolicyRole>(u => u.Name == DefaultUserRoleName);

            if (userRole == null)
            {
                userRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                userRole.Name = DefaultUserRoleName;
                // Allow users to read departments only if their title contains 'Development'.
                const string     protectedDepartment = "Development";
                CriteriaOperator departmentCriteria  = new FunctionOperator(FunctionOperatorType.Contains,
                                                                            new OperandProperty(nameof(Department)), new OperandValue(protectedDepartment)
                                                                            );
                userRole.AddObjectPermission <Department>(SecurityOperations.Read, (!departmentCriteria).ToString() /*"!Contains(Title, 'Development')"*/, SecurityPermissionState.Deny);
                // Allow users to read and modify employee records and their fields by criteria.
                userRole.AddTypePermissionsRecursively <Employee>(SecurityOperations.Read, SecurityPermissionState.Allow);
                userRole.AddTypePermissionsRecursively <Employee>(SecurityOperations.Write, SecurityPermissionState.Allow);
                CriteriaOperator employeeCriteria = new FunctionOperator(FunctionOperatorType.Contains,
                                                                         new OperandProperty(nameof(Employee.Department) + "." + nameof(Department.Title)), new OperandValue(protectedDepartment)
                                                                         );
                userRole.AddObjectPermission <Employee>(SecurityOperations.Delete, employeeCriteria.ToString() /*"Contains(Department.Title, 'Development')"*/, SecurityPermissionState.Allow);
                userRole.AddMemberPermission <Employee>(SecurityOperations.Write, nameof(Employee.LastName), (!employeeCriteria).ToString() /*"!Contains(Department.Title, 'Development')"*/, SecurityPermissionState.Deny);
                // For more information on criteria language syntax (both string and strongly-typed formats), see https://docs.devexpress.com/CoreLibraries/4928/.
            }
            return(userRole);
        }
Esempio n. 2
0
File: Util.cs Progetto: ewin66/dev
        public static DateTime GetServerTime(XPObjectSpace xpObjectSpace)
        {
            CriteriaOperator funcNow    = new FunctionOperator(FunctionOperatorType.Now);
            DateTime         serverTime = (DateTime)xpObjectSpace.Session.Evaluate(typeof(XPObjectType), funcNow, null);

            return(serverTime);
        }
    protected void ModifyFilterExpression(string FieldName, object value, ASPxGridView targetGrid)
    {
        var criterias = CriteriaColumnAffinityResolver.SplitByColumnNames(CriteriaOperator.Parse(targetGrid.FilterExpression)).Item2;

        CriteriaOperator co = null;

        if (FieldName == "ProductName")
        {
            value += "%";
            co     = new FunctionOperator("Like", new OperandProperty(FieldName), new OperandValue(value));
        }
        else
        {
            co = new BinaryOperator(FieldName, value, BinaryOperatorType.Equal);
        }
        if (!criterias.Keys.Contains(FieldName))
        {
            criterias.Add(FieldName, co);
        }
        else
        {
            criterias[FieldName] = co;
        }
        targetGrid.FilterExpression = CriteriaOperator.ToString(GroupOperator.And(criterias.Values));
    }
Esempio n. 4
0
        public static string GetDisplayName(FunctionOperator op)
        {
            switch (op)
            {
            case FunctionOperator.Trim: return("TRIM");

            case FunctionOperator.Len: return("LEN");

            case FunctionOperator.Left: return("LEFT");

            case FunctionOperator.Right: return("RIGHT");

            case FunctionOperator.Substring: return("SUBSTRING");

            case FunctionOperator.UpperCase: return("UPPER");

            case FunctionOperator.LowerCase: return("LOWER");

            case FunctionOperator.Like: return("LIKE");

            case FunctionOperator.In: return("IN");

            default:
            {
                throw new NotSupportedException("Function operator '" + op + "' was not expected.");
            }
            }
        }
Esempio n. 5
0
        object ICriteriaVisitor.Visit(FunctionOperator theOperator)
        {
            string OperandFormat = "{2}";

            switch (theOperator.OperatorType)
            {
            case FunctionOperatorType.StartsWith:
                OperandFormat = ".ToLower().StartsWith(\"{2}\".ToLower())";
                break;

            case FunctionOperatorType.EndsWith:
                OperandFormat = ".ToLower().EndsWith(\"{2}\".ToLower())";
                break;

            case FunctionOperatorType.Contains:
                OperandFormat = ".ToLower().Contains(\"{2}\".ToLower())";
                break;
            }
            List <string> parameters = new List <string>();

            foreach (CriteriaOperator operand in theOperator.Operands)
            {
                parameters.Add(operand.Accept(this).ToString());
            }
            parameters.Insert(1, GetFunctionName(theOperator.OperatorType));
            return(string.Format("{0}" + OperandFormat, parameters.ToArray()));
        }
 public CriteriaOperator PrepareCriteria(CriteriaOperator op)
 {
     if (op is FunctionOperator)
     {
         var funcOp = new FunctionOperator();
         for (int i = 0; i < (op as FunctionOperator).Operands.Count; i++)
             funcOp.Operands.Add(PrepareCriteria((op as FunctionOperator).Operands[i]));
         return funcOp;
     }
     else if (op is ConstantValue)
     {
         var cnst = new ConstantValue((op as ConstantValue).Value);
         if (String.Concat((op as ConstantValue).Value).ToLower().IndexOf("@this") > -1)
         {
             IMemberInfo info;
             cnst.Value = ObjectFormatValues.GetValueRecursive((op as ConstantValue).Value.ToString().Replace("@This.", "").Replace("@This", "").Replace("@this.", "").Replace("@this", ""), CurrentObject, out info);
         }
         return cnst;
     }
     else if (op is BinaryOperator)
     {
         var binary = new BinaryOperator();
         binary.LeftOperand = PrepareCriteria((op as BinaryOperator).LeftOperand);
         binary.RightOperand = PrepareCriteria((op as BinaryOperator).RightOperand);
         return binary;
     }
     else
     {
         return op;
     }
 }
Esempio n. 7
0
        string ICriteriaVisitor <string> .Visit(FunctionOperator theOperator)
        {
            try
            {
                _isNeedUpper = theOperator.Operands.Any(IsNeedUpper);

                var str = OracleFormatterHelper.FormatFunction(obj => Process((CriteriaOperator)obj), theOperator.OperatorType, theOperator.Operands.ToArray());
                if (!string.IsNullOrEmpty(str))
                {
                    return(str);
                }

                var operands = new string[theOperator.Operands.Count];
                for (var i = 0; i < theOperator.Operands.Count; i++)
                {
                    operands[i] = Process(theOperator.Operands[i]);
                }
                str = OracleFormatterHelper.FormatFunction(theOperator.OperatorType, operands);
                if (!string.IsNullOrEmpty(str))
                {
                    return(str);
                }

                return(base.VisitInternal(theOperator));
            }
            finally
            {
                _isNeedUpper = false;
            }
        }
        private static Condition Function(FunctionOperator functionOperator)
        {
            if (ReferenceEquals(functionOperator, null))
            {
                return(null);
            }

            OperandProperty opProperty = functionOperator.Operands.Count == 3
                ? functionOperator.Operands[1] as OperandProperty : functionOperator.Operands[0] as OperandProperty;

            OperandValue opValue = functionOperator.Operands.Count > 1
                ? functionOperator.Operands.Count == 3
                        ? functionOperator.Operands[2] as OperandValue
                        : functionOperator.Operands[1] as OperandValue
                : null;

            switch (functionOperator.OperatorType)
            {
            case FunctionOperatorType.Contains:
                return(new Condition(opProperty.PropertyName, Operator.Contains, opValue.Value));

            case FunctionOperatorType.StartsWith:
                return(new Condition(opProperty.PropertyName, Operator.StartsWith, opValue.Value));

            case FunctionOperatorType.EndsWith:
                return(new Condition(opProperty.PropertyName, Operator.EndsWith, opValue.Value));

            case FunctionOperatorType.IsNullOrEmpty:
                return(new Condition(opProperty.PropertyName, Operator.IsNullOrEmpty));

            default:
                throw new FilterException(string.Format(Resource.UnsupportedOperatorError, functionOperator.OperatorType, "function"));
            }
        }
    protected void gvClients_ProcessColumnAutoFilter(object sender, ASPxGridViewAutoFilterEventArgs e)
    {
        if (e.Kind != GridViewAutoFilterEventKind.CreateCriteria)
        {
            return;
        }
        CriteriaOperator co = CriteriaOperator.Parse(gvClients.FilterExpression);

        FindAndRemoveCustomOperator(ref co, e.Column.FieldName);

        FunctionOperator fo = null;

        if (e.Value.Length > 0)
        {
            fo = new FunctionOperator(FunctionOperatorType.Custom, EasySearchStatic.Name, e.Value, new OperandProperty(e.Column.FieldName));
        }
        if (!ReferenceEquals(co, null) || !ReferenceEquals(fo, null))
        {
            gvClients.FilterExpression = MergeCriterias(co, fo).ToString();
        }
        else
        {
            gvClients.FilterExpression = "";
        }
        e.Criteria = null;
    }
Esempio n. 10
0
        protected override object Visit(FunctionOperator theOperator)
        {
            switch (theOperator.OperatorType)
            {
            case FunctionOperatorType.IsNullOrEmpty:
                return(new BinaryOperator(theOperator.Operands[0], new ConstantValue(null), BinaryOperatorType.Equal));

            case FunctionOperatorType.Custom:
                var functionName = ((OperandValue)theOperator.Operands[0]).Value.ToString();
                if (functionName == IsDuringDaysFunction.FunctionName)
                {
                    var daysOperandValue = ((ConstantValue)theOperator.Operands[2]).Value;
                    int days             = 0 - Convert.ToInt32(daysOperandValue);
                    return(new BinaryOperator(theOperator.Operands[1],
                                              new ConstantValue(DateTime.Now.Date.AddDays(days)), BinaryOperatorType.Greater));
                }
                if (functionName == IsLastMonthFunction.FunctionName)
                {
                    DateTime lastMonth = DateTime.Now.AddMonths(-1);
                    var      left      = new BinaryOperator(theOperator.Operands[1],
                                                            new ConstantValue(Utils.Date.MonthBegin(lastMonth)), BinaryOperatorType.GreaterOrEqual);
                    var right = new BinaryOperator(theOperator.Operands[1],
                                                   new ConstantValue(Utils.Date.MonthEnd(lastMonth)), BinaryOperatorType.LessOrEqual);

                    return(CriteriaOperator.And(left, right));
                }

                break;
            }

            return(base.Visit(theOperator));
        }
Esempio n. 11
0
        private static CriteriaOperator CreateExpression(string propertyName)
        {
            CriteriaOperator op = new BinaryOperator(propertyName, 10, BinaryOperatorType.Divide);

            op = new FunctionOperator(FunctionOperatorType.Floor, op);
            return(new BinaryOperator(op, new OperandValue(10), BinaryOperatorType.Multiply));
        }
 public static Boolean ConvertCustomFunctionToValue(FunctionOperator functionOperator, out Object value)
 {
     Boolean result = false;
     value = null;
     if ((functionOperator.OperatorType == FunctionOperatorType.Custom)
             || (functionOperator.OperatorType == FunctionOperatorType.CustomNonDeterministic))
     {
         String customFunctionName = "";
         if (functionOperator.Operands[0] is OperandValue)
         {
             OperandValue operandValue = (OperandValue)functionOperator.Operands[0];
             if (operandValue.Value is String)
             {
                 customFunctionName = (String)operandValue.Value;
             }
         }
         if (!String.IsNullOrWhiteSpace(customFunctionName))
         {
             ICustomFunctionOperator customFunctionOperator = CriteriaOperator.GetCustomFunction(customFunctionName);
             if (customFunctionOperator != null)
             {
                 value = customFunctionOperator.Evaluate(functionOperator.Operands);
                 result = true;
             }
         }
     }
     return result;
 }
        private Guid?ParseBinaryRightValue(CriteriaOperator filter)
        {
            BinaryOperator binary = filter as BinaryOperator;

            if ((object)binary != null)
            {
                var operandValue = binary.RightOperand as OperandValue;
                if ((object)operandValue != null)
                {
                    var value = operandValue.Value;
                    if (typeof(Guid?).IsInstanceOfType(value))
                    {
                        return((Guid?)value);
                    }
                    return(Guid.Empty);
                }
            }
            UnaryOperator unary = filter as UnaryOperator;

            if ((object)unary != null)
            {
                return(GuidExtension.UnassignedGuid);
            }
            FunctionOperator noneFunction = filter as FunctionOperator;

            if ((object)noneFunction != null)
            {
                return(Guid.Empty);
            }
            return(null);
        }
Esempio n. 14
0
        private string GetSqlKeyword(FunctionOperator op, out bool isFormat)
        {
            isFormat = true;

            switch (op)
            {
            case FunctionOperator.Trim: return(_provider.TrimFunction);

            case FunctionOperator.Len: return(_provider.LengthFunction);

            case FunctionOperator.Left: return(_provider.LeftFunction);

            case FunctionOperator.Right: return(_provider.RightFunction);

            case FunctionOperator.Substring: return(_provider.SubstringFunction);

            case FunctionOperator.UpperCase: return(_provider.UpperCaseFunction);

            case FunctionOperator.LowerCase: return(_provider.LowerCaseFunction);

            case FunctionOperator.Like: return(_provider.LikeFunction);

            case FunctionOperator.In: isFormat = false; return("IN");

            default:
            {
                throw new NotSupportedException("Function operator " + op + " is not supported.");
            }
            }
        }
 public CriteriaOperator PrepareCriteria(CriteriaOperator op)
 {
     if (op is FunctionOperator)
     {
         var funcOp = new FunctionOperator();
         for (int i = 0; i < (op as FunctionOperator).Operands.Count; i++)
         {
             funcOp.Operands.Add(PrepareCriteria((op as FunctionOperator).Operands[i]));
         }
         return(funcOp);
     }
     else if (op is ConstantValue)
     {
         var cnst = new ConstantValue((op as ConstantValue).Value);
         if (String.Concat((op as ConstantValue).Value).ToLower().IndexOf("@this") > -1)
         {
             IMemberInfo info;
             cnst.Value = ObjectFormatValues.GetValueRecursive((op as ConstantValue).Value.ToString().Replace("@This.", "").Replace("@This", "").Replace("@this.", "").Replace("@this", ""), CurrentObject, out info);
         }
         return(cnst);
     }
     else if (op is BinaryOperator)
     {
         var binary = new BinaryOperator();
         binary.LeftOperand  = PrepareCriteria((op as BinaryOperator).LeftOperand);
         binary.RightOperand = PrepareCriteria((op as BinaryOperator).RightOperand);
         return(binary);
     }
     else
     {
         return(op);
     }
 }
Esempio n. 16
0
        public static CriteriaOperator GetLikeUpperCriteria(string propertyName, object requiredValue)
        {
            FunctionOperator operandProperty = createOperandProperty(propertyName, FunctionOperatorType.Upper);
            FunctionOperator operandValue    = createOperandValue(requiredValue, FunctionOperatorType.Upper);

            return(new BinaryOperator(operandProperty, operandValue, BinaryOperatorType.Like));
        }
Esempio n. 17
0
        private void OnCustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            GridView view = sender as GridView;

            if (view.OptionsFind.HighlightFindResults && !view.FindFilterText.Equals(string.Empty))
            {
                CriteriaOperator op = ConvertFindPanelTextToCriteriaOperator(view.FindFilterText, view, false);
                if (op is GroupOperator)
                {
                    string findText = view.FindFilterText;
                    if (HiglightSubString(e, findText))
                    {
                        e.Handled = true;
                    }
                }
                else if (op is FunctionOperator)
                {
                    FunctionOperator func            = op as FunctionOperator;
                    CriteriaOperator colNameOperator = func.Operands[0];
                    string           colName         = colNameOperator.LegacyToString().Replace("[", string.Empty).Replace("]", string.Empty);
                    if (!e.Column.FieldName.StartsWith(colName))
                    {
                        return;
                    }

                    CriteriaOperator valueOperator = func.Operands[1];
                    string           findText      = valueOperator.LegacyToString().ToLower().Replace("'", "");
                    if (HiglightSubString(e, findText))
                    {
                        e.Handled = true;
                    }
                }
            }
        }
Esempio n. 18
0
 public Field(string tableName, string fieldName, string fieldAlias, FunctionOperator fieldOperator)
 {
     m_TableName     = tableName;
     m_Name          = fieldName;
     m_Alias         = fieldAlias;
     m_FieldOperator = fieldOperator;
 }
 public override void Visit(FunctionOperator theOperator)
 {
     if (theOperator.OperatorType == FunctionOperatorType.Now)
     {
         this.errors.Add(new CriteriaValidatorError("Invalid function: now()"));
     }
     base.Visit(theOperator);
 }
        protected override Expression VisitConditional(ConditionalExpression node)
        {
            FunctionOperator result = new FunctionOperator(FunctionOperatorType.Iif);

            AppendIifOperands(result, node);
            Result = result;
            return(node);
        }
        public IFunctionOperator RegisterFunction(string text, Action <Stack <IOperand>, IBackingStore, long> doOperation,
                                                  int parameterCount, int maxParameterCount = 0)
        {
            var op = new FunctionOperator(OperatorType.Function, doOperation, text, parameterCount, maxParameterCount);

            Functions.Add(text, op);
            return(op);
        }
Esempio n. 22
0
        private void AddFields(Type classType, string fieldName, string fieldAlias, FunctionOperator fieldOperator)
        {
            ClassMap classMap = null;

            classMap = m_Broker.GetClassMap(PersistentObject.GetClassName(classType));
            Field field = new Field(classMap.Table.Name, classMap.GetAttributeMap(fieldName).Column.Name, fieldAlias, fieldOperator);

            this.m_Fields.Add(field);
        }
Esempio n. 23
0
 object ICriteriaVisitor <object> .Visit(FunctionOperator theOperator)
 {
     Process(theOperator);
     foreach (CriteriaOperator @operator in theOperator.Operands)
     {
         @operator.Accept(this);
     }
     return(null);
 }
Esempio n. 24
0
 private CriteriaToStringVisitResult ConvertCastFunction(FunctionOperator theOperator, Type type)
 {
     CriteriaToStringVisitResult result = null;
     if (theOperator.Operands.Count >= 1)
     {
         result = new CriteriaToStringVisitResult(String.Format("Cast({0} as {1})", Process(theOperator.Operands[0]).Result, type.FullName));
     }
     return result;
 }
 object ICriteriaVisitor.Visit(FunctionOperator theOperator){
     if (theOperator.OperatorType != FunctionOperatorType.Custom){
         if (IsFullIndexed(theOperator.Operands[0])){
             theOperator.OperatorType = FunctionOperatorType.Custom;
             theOperator.Operands.Insert(0, new OperandValue(FullTextContainsFunction.FunctionName));
         }
     }
     return theOperator;
 }
Esempio n. 26
0
        public override CriteriaOperator Visit(FunctionOperator theOperator)
        {
            var result = (FunctionOperator)base.Visit(theOperator);

            if (!object.ReferenceEquals(theOperator, result))
            {
                return(null);
            }
            return(result);
        }
Esempio n. 27
0
        private static bool IsValidFuncOperator(FunctionOperator fo, string fieldName)
        {
            if ((ReferenceEquals(fo, null) ||
                 ((fo.OperatorType != FunctionOperatorType.Custom) && !fo.Operands.Any(f => f.ToString().Contains(fieldName)))))
            {
                return(false);
            }

            return(true);
        }
        protected virtual CriteriaOperator VisitFunction(FunctionOperator theOperator)
        {
            CriteriaOperatorCollection operands = this.VisitOperands(theOperator.Operands);

            if (object.ReferenceEquals(theOperator.Operands, operands))
            {
                return(theOperator);
            }
            return(new FunctionOperator(theOperator.OperatorType, operands));
        }
Esempio n. 29
0
        private static bool IsRemovable(FunctionOperator fo, string fieldName)
        {
            if ((ReferenceEquals(fo, null) ||
                 !fo.Operands.Any(f => f.ToString().Contains(fieldName))))
            {
                return(false);
            }

            return(true);
        }
        object IValueConverter.Convert(object value, Type targetType, object parameter, string language)
        {
            FunctionOperator op = value as FunctionOperator;

            if (object.ReferenceEquals(op, null))
            {
                return(null);
            }
            return(((OperandValue)op.Operands[1]).Value);
        }
Esempio n. 31
0
        string ICriteriaVisitor <string> .Visit(FunctionOperator theOperator)
        {
            List <string> parameters = new List <string>();

            foreach (CriteriaOperator operand in theOperator.Operands)
            {
                parameters.Add(operand.Accept(this));
            }
            return(string.Format("{0}({1})", GetFunctionName(theOperator.OperatorType),
                                 string.Join(", ", parameters.ToArray())));
        }
        private FunctionOperator ExtractCharIndex(MethodCallExpression node)
        {
            FunctionOperator result = new FunctionOperator(FunctionOperatorType.CharIndex,
                                                           ExtractOperand(SafeGetArgument(node.Arguments, 0)), ExtractOperand(node.Object));

            for (int i = 1; i < node.Arguments.Count; i++)
            {
                result.Operands.Add(ExtractOperand(node.Arguments[i]));
            }
            return(result);
        }
Esempio n. 33
0
 protected override CriteriaOperator VisitFunction(FunctionOperator theOperator)
 {
     if (theOperator.OperatorType == FunctionOperatorType.StartsWith ||
         theOperator.OperatorType == FunctionOperatorType.EndsWith ||
         theOperator.OperatorType == FunctionOperatorType.Contains)
     {
         return(new FunctionOperator(theOperator.OperatorType,
                                     CriteriaVisitor.WrapIntoCustomFunction(theOperator.Operands[0]),
                                     CriteriaVisitor.WrapIntoCustomFunction(theOperator.Operands[1])));
     }
     return(base.VisitFunction(theOperator));
 }
Esempio n. 34
0
        private string CreateWhereClauseFunctionOperator(FunctionOperator oprator)
        {
            var operands = oprator.Operands;

            var operatorType = $"ToLower().{oprator.OperatorType}";

            var propertyName = ((OperandProperty)operands[0]).PropertyName;

            var value = ((OperandValue)operands[1]).Value;

            return($"{propertyName}.{operatorType}(\"{value}\") ");
        }
        object ICriteriaVisitor.Visit(FunctionOperator theOperator){
            Process(theOperator);
            if (theOperator.OperatorType == FunctionOperatorType.Custom){
                var customFunctionOperator =CriteriaOperator.GetCustomFunction(((OperandValue)theOperator.Operands.First()).Value.ToString());
                if (customFunctionOperator != null) {
                    var parameters =theOperator.Operands.OfType<OperandValue>().Skip(1).Select(operand => operand.Value);
                    return customFunctionOperator.Evaluate(parameters);
                }

            }
            return theOperator;
        }
Esempio n. 36
0
        public Function(FunctionOperator op, Expression[] args)
        {
            if( op == FunctionOperator.Substring && args.Length == 2 )
            {
                Expression[] newArgs = new Expression[3];
                newArgs[0] = args[0];
                newArgs[1] = args[1];
                newArgs[2] = new Function(FunctionOperator.Len, new Expression[] {(Expression)args[0].Clone()});
                args = newArgs;
            }

            this.Operator = op;
            this.Params = args;
        }
Esempio n. 37
0
 protected override string OnCreateLookupDisplayFilter(string text, string displayMember)
 {
     List<CriteriaOperator> subStringOperators = new List<CriteriaOperator>();
     foreach (string sString in text.Split(' '))
     {
         List<CriteriaOperator> columnsOperators = new List<CriteriaOperator>();
         FunctionOperatorType opType = FunctionOperatorType.Contains;
         foreach (GridColumn col in Columns)
         {
             if (col.Visible && col.ColumnType == typeof(string))
             {
                 FunctionOperator fo = new FunctionOperator(opType, new OperandProperty(col.FieldName), sString);
                 columnsOperators.Add(fo);
             }
         }
         subStringOperators.Add(new GroupOperator(GroupOperatorType.Or, columnsOperators));
     }
     return new GroupOperator(GroupOperatorType.And, subStringOperators).ToString();
 }
		public static bool IsBinaryCompatibleLikeFunction(FunctionOperator func)
		{
			if (object.ReferenceEquals(func, null))
			{
				return false;
			}
			if (func.OperatorType != FunctionOperatorType.Custom)
			{
				return false;
			}
			if (func.Operands.Count != 3)
			{
				return false;
			}
			OperandValue objA = func.Operands[0] as OperandValue;
			if (object.ReferenceEquals(objA, null))
			{
				return false;
			}
			string nm = objA.Value as string;
			return IsName(nm);
		}
Esempio n. 39
0
 public object Visit(FunctionOperator theOperator)
 {
     if (theOperator.OperatorType == FunctionOperatorType.IsNull) {
         if (theOperator.Operands.Count == 2) {
             return BooleanCriteriaStateObject.Value;
         }
         return BooleanCriteriaStateObject.Logical;
     }
     switch (theOperator.OperatorType) {
         case FunctionOperatorType.IsOutlookIntervalBeyondThisYear:
         case FunctionOperatorType.IsOutlookIntervalEarlierThisMonth:
         case FunctionOperatorType.IsOutlookIntervalEarlierThisWeek:
         case FunctionOperatorType.IsOutlookIntervalEarlierThisYear:
         case FunctionOperatorType.IsOutlookIntervalLastWeek:
         case FunctionOperatorType.IsOutlookIntervalLaterThisMonth:
         case FunctionOperatorType.IsOutlookIntervalLaterThisWeek:
         case FunctionOperatorType.IsOutlookIntervalLaterThisYear:
         case FunctionOperatorType.IsOutlookIntervalNextWeek:
         case FunctionOperatorType.IsOutlookIntervalPriorThisYear:
         case FunctionOperatorType.IsOutlookIntervalToday:
         case FunctionOperatorType.IsOutlookIntervalTomorrow:
         case FunctionOperatorType.IsOutlookIntervalYesterday:
         case FunctionOperatorType.IsNullOrEmpty:
             return BooleanCriteriaStateObject.Logical;
         case FunctionOperatorType.Custom:
             return BooleanCriteriaStateObject.Undefined;
     }
     return BooleanCriteriaStateObject.Value;
 }
Esempio n. 40
0
 object FnBigMul(FunctionOperator theOperator)
 {
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if (op == null) { return null; }
     object op2 = Process((CriteriaOperator)theOperator.Operands[1]);
     if (op2 == null) { return null; }
     switch (Type.GetTypeCode(op.GetType())) {
         case TypeCode.UInt16:
         case TypeCode.Int16:
         case TypeCode.Int32:
         case TypeCode.SByte:
         case TypeCode.Byte:
         break;
         default:
         throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, FilteringExceptionsText.ExpressionEvaluatorOperatorSubtypeNotSupportedForSpecificOperandType, typeof(FunctionOperator).Name, FunctionOperatorType.BigMul.ToString(), op.ToString()));
     }
     switch (Type.GetTypeCode(op.GetType())) {
         case TypeCode.UInt16:
         case TypeCode.Int16:
         case TypeCode.Int32:
         case TypeCode.SByte:
         case TypeCode.Byte:
         break;
         default:
         throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, FilteringExceptionsText.ExpressionEvaluatorOperatorSubtypeNotSupportedForSpecificOperandType, typeof(FunctionOperator).Name, FunctionOperatorType.BigMul.ToString(), op2.ToString()));
     }
     return Math.BigMul(Convert.ToInt32(op), Convert.ToInt32(op2));
 }
Esempio n. 41
0
 string GetFirstArgumentAsString(FunctionOperator op)
 {
     return CalcStringArgument(op.Operands[0]);
 }
Esempio n. 42
0
 object FnUpper(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if(str == null) { return null; }
     return str.ToUpper(CultureInfo.InvariantCulture);
 }
Esempio n. 43
0
 object FnPower(FunctionOperator theOperator)
 {
     object oper1 = Process((CriteriaOperator)theOperator.Operands[0]);
     object oper2 = Process((CriteriaOperator)theOperator.Operands[1]);
     if (oper1 == null || oper2 == null) { return null; }
     double value1 = GetDoubleArgument(oper1, typeof(FunctionOperator).Name, FunctionOperatorType.Power.ToString());
     double value2 = GetDoubleArgument(oper2, typeof(FunctionOperator).Name, FunctionOperatorType.Power.ToString());
     return Math.Pow(value1, value2);;
 }
Esempio n. 44
0
 public override Object Visit(FunctionOperator theOperator)
 {
     switch (theOperator.OperatorType)
     {
         case FunctionOperatorType.ToStr:
             return ConvertCastFunction(theOperator, typeof(String));
         case FunctionOperatorType.ToDecimal:
             return ConvertCastFunction(theOperator, typeof(Decimal));
         case FunctionOperatorType.ToDouble:
             return ConvertCastFunction(theOperator, typeof(Double));
         case FunctionOperatorType.ToFloat:
             return ConvertCastFunction(theOperator, typeof(Single));
         case FunctionOperatorType.ToInt:
             return ConvertCastFunction(theOperator, typeof(Int32));
         case FunctionOperatorType.ToLong:
             return ConvertCastFunction(theOperator, typeof(Int64));
         case FunctionOperatorType.Iif:
             if (theOperator.Operands.Count >= 3)
             {
                 return new CriteriaToStringVisitResult(
                     String.Format("case when ({0}) then {1} else {2} end",
                         Process(theOperator.Operands[0]).Result,
                         Process(theOperator.Operands[1]).Result,
                         Process(theOperator.Operands[2]).Result)
                 );
             }
             else
             {
                 return base.Visit(theOperator);
             }
         case FunctionOperatorType.StartsWith:
             return new CriteriaToStringVisitResult(MsSqlFormatterHelper.FormatFunction(
                 new ProcessParameter((o) => Process((CriteriaOperator)o).Result),
                 theOperator.OperatorType,
                 new MsSqlFormatterHelper.MSSqlServerVersion(false, false, false),
                 theOperator.Operands.ToArray()));
         case FunctionOperatorType.Contains:
             if (theOperator.Operands.Count >= 2)
             {
                 return new CriteriaToStringVisitResult(
                     String.Format(CultureInfo.InvariantCulture, "{0} like '%' + {1} + '%'",
                         Process(theOperator.Operands[0]).Result,
                         Process(theOperator.Operands[1]).Result)
                 );
             }
             else
             {
                 return base.Visit(theOperator);
             }
         default:
             object result;
             if (CriteriaToHqlConverterHelper.ConvertCustomFunctionToValue(theOperator, out result))
             {
                 return new CriteriaToStringVisitResult(ValueToString(result));
             }
             else
             {
                 return base.Visit(theOperator);
             }
     }
 }
Esempio n. 45
0
 object FnLen(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if(str == null) { return null; }
     return str.Length;
 }
Esempio n. 46
0
  Object yyparse (yyInput yyLex) {
	if (yyMax <= 0) yyMax = 256;			
	int yyState = 0;								   
	int [] yyStates = new int[yyMax];					
	Object yyVal = null;							   
	Object [] yyVals = new Object[yyMax];			
	int yyToken = -1;					
	int yyErrorFlag = 0;				
	int yyTop = 0;
	goto skip;
	yyLoop:
	yyTop++;
	skip:
	for(;; ++yyTop) {
	  if(yyTop >= yyStates.Length) {			
		int[] i = new int[yyStates.Length + yyMax];
		yyStates.CopyTo(i, 0);
		yyStates = i;
		Object[] o = new Object[yyVals.Length + yyMax];
		yyVals.CopyTo(o, 0);
		yyVals = o;
	  }
	  yyStates[yyTop] = yyState;
	  yyVals[yyTop] = yyVal;
	  yyDiscarded:	
	  for(;;) {
		int yyN;
		if ((yyN = yyDefRed[yyState]) == 0) {	
		  if(yyToken < 0)
			yyToken = yyLex.advance() ? yyLex.token() : 0;
		  if((yyN = yySindex[yyState]) != 0 && ((yyN += yyToken) >= 0)
			  && (yyN < yyTable.Length) && (yyCheck[yyN] == yyToken)) {
			yyState = yyTable[yyN];		
			yyVal = yyLex.value();
			yyToken = -1;
			if (yyErrorFlag > 0) -- yyErrorFlag;
			goto yyLoop;
		  }
		  if((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
			  && yyN < yyTable.Length && yyCheck[yyN] == yyToken)
			yyN = yyTable[yyN];			
		  else
			switch(yyErrorFlag) {
			case 0:
			  yyerror("syntax error");
			  goto case 1;
			case 1: case 2:
			  yyErrorFlag = 3;
			  do {
				if((yyN = yySindex[yyStates[yyTop]]) != 0
					&& (yyN += Token.yyErrorCode) >= 0 && yyN < yyTable.Length
					&& yyCheck[yyN] == Token.yyErrorCode) {
				  yyState = yyTable[yyN];
				  yyVal = yyLex.value();
				  goto yyLoop;
				}
			  } while (--yyTop >= 0);
			  yyerror("irrecoverable syntax error");
			  goto yyDiscarded;
			case 3:
			  if (yyToken == 0)
				yyerror("irrecoverable syntax error at end-of-file");
			  yyToken = -1;
			  goto yyDiscarded;		
			}
		}
		int yyV = yyTop + 1 - yyLen[yyN];
		yyVal = yyV > yyTop ? null : yyVals[yyV];
		switch(yyN) {
case 1:
#line 54 "grammar.y"
  { result = new CriteriaOperator[0]; }
  break;
case 2:
#line 55 "grammar.y"
  { result = ((List<CriteriaOperator>)yyVals[-1+yyTop]).ToArray(); }
  break;
case 3:
#line 59 "grammar.y"
  { yyVal = new List<CriteriaOperator>(new CriteriaOperator[] {(CriteriaOperator)yyVals[0+yyTop]}); }
  break;
case 4:
#line 60 "grammar.y"
  { yyVal = yyVals[-2+yyTop]; ((List<CriteriaOperator>)yyVal).Add((CriteriaOperator)yyVals[0+yyTop]); }
  break;
case 5:
#line 64 "grammar.y"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 6:
#line 65 "grammar.y"
  {
		OperandProperty prop2 = (OperandProperty)yyVals[-2+yyTop];
		OperandProperty prop4 = (OperandProperty)yyVals[0+yyTop];
		prop2.PropertyName = '<' + prop2.PropertyName + '>' + prop4.PropertyName;
		yyVal = prop2;
	}
  break;
case 7:
#line 74 "grammar.y"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 8:
#line 75 "grammar.y"
  { yyVal = new OperandProperty("^"); }
  break;
case 9:
#line 79 "grammar.y"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 10:
#line 80 "grammar.y"
  {
		OperandProperty prop1 = (OperandProperty)yyVals[-2+yyTop];
		OperandProperty prop3 = (OperandProperty)yyVals[0+yyTop];
		prop1.PropertyName += '.' + prop3.PropertyName;
		yyVal = prop1;
	}
  break;
case 11:
#line 89 "grammar.y"
  {
		AggregateOperand agg = (AggregateOperand)yyVals[0+yyTop];
		yyVal = JoinOperand.JoinOrAggreagate((OperandProperty)yyVals[-2+yyTop], null, agg.AggregateType, agg.AggregatedExpression);
	}
  break;
case 12:
#line 93 "grammar.y"
  {
		AggregateOperand agg = (AggregateOperand)yyVals[0+yyTop];
		yyVal = JoinOperand.JoinOrAggreagate((OperandProperty)yyVals[-5+yyTop], (CriteriaOperator)yyVals[-3+yyTop], agg.AggregateType, agg.AggregatedExpression);
	}
  break;
case 13:
#line 97 "grammar.y"
  {
		AggregateOperand agg = (AggregateOperand)yyVals[0+yyTop];
		yyVal = JoinOperand.JoinOrAggreagate((OperandProperty)yyVals[-4+yyTop], null, agg.AggregateType, agg.AggregatedExpression);
	}
  break;
case 14:
#line 101 "grammar.y"
  { yyVal = JoinOperand.JoinOrAggreagate((OperandProperty)yyVals[-3+yyTop], (CriteriaOperator)yyVals[-1+yyTop], Aggregate.Exists, null); }
  break;
case 15:
#line 102 "grammar.y"
  { yyVal = JoinOperand.JoinOrAggreagate((OperandProperty)yyVals[-2+yyTop], null, Aggregate.Exists, null); }
  break;
case 18:
#line 110 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)null, Aggregate.Count, null); }
  break;
case 19:
#line 111 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)null, Aggregate.Exists, null); }
  break;
case 20:
#line 112 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)null, Aggregate.Count, null); }
  break;
case 21:
#line 113 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)null, Aggregate.Exists, null); }
  break;
case 22:
#line 114 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)yyVals[-1+yyTop], Aggregate.Min, null); }
  break;
case 23:
#line 115 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)yyVals[-1+yyTop], Aggregate.Max, null); }
  break;
case 24:
#line 116 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)yyVals[-1+yyTop], Aggregate.Avg, null); }
  break;
case 25:
#line 117 "grammar.y"
  { yyVal = new AggregateOperand((OperandProperty)null, (CriteriaOperator)yyVals[-1+yyTop], Aggregate.Sum, null); }
  break;
case 26:
#line 121 "grammar.y"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 27:
#line 122 "grammar.y"
  {
						  string paramName = (string)yyVals[0+yyTop];
						  if(string.IsNullOrEmpty(paramName)) {
							OperandValue param = new OperandValue();
							resultParameters.Add(param);
							yyVal = param;
						  } else {
							bool paramNotFound = true;
							foreach(OperandValue v in resultParameters) {
							  OperandParameter p = v as OperandParameter;
							  if(ReferenceEquals(p, null))
								continue;
							  if(p.ParameterName != paramName)
								continue;
							  paramNotFound = false;
							  resultParameters.Add(p);
							  yyVal = p;
							  break;
							}
							if(paramNotFound) {
							  OperandParameter param = new OperandParameter(paramName);
							  resultParameters.Add(param);
							  yyVal = param;
							}
						  }
						}
  break;
case 28:
#line 148 "grammar.y"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 29:
#line 149 "grammar.y"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 30:
#line 150 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Multiply ); }
  break;
case 31:
#line 151 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Divide ); }
  break;
case 32:
#line 152 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Plus ); }
  break;
case 33:
#line 153 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Minus ); }
  break;
case 34:
#line 154 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Modulo ); }
  break;
case 35:
#line 155 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.BitwiseOr ); }
  break;
case 36:
#line 156 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.BitwiseAnd ); }
  break;
case 37:
#line 157 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.BitwiseXor ); }
  break;
case 38:
#line 158 "grammar.y"
  {
								yyVal = new UnaryOperator( UnaryOperatorType.Minus, (CriteriaOperator)yyVals[0+yyTop] );
								try {
									if(yyVals[0+yyTop] is OperandValue) {
										OperandValue operand = (OperandValue)yyVals[0+yyTop];
										if(operand.Value is Int32) {
											operand.Value = -(Int32)operand.Value;
											yyVal = operand;
											break;
										} else if(operand.Value is Int64) {
											operand.Value = -(Int64)operand.Value;
											yyVal = operand;
											break;
										} else if(operand.Value is Double) {
											operand.Value = -(Double)operand.Value;
											yyVal = operand;
											break;
										} else if(operand.Value is Decimal) {
											operand.Value = -(Decimal)operand.Value;
											yyVal = operand;
											break;
										}  else if(operand.Value is Int16) {
											operand.Value = -(Int16)operand.Value;
											yyVal = operand;
											break;
										}  else if(operand.Value is SByte) {
											operand.Value = -(SByte)operand.Value;
											yyVal = operand;
											break;
										}
									}
								} catch {}
							}
  break;
case 39:
#line 191 "grammar.y"
  { yyVal = new UnaryOperator( UnaryOperatorType.Plus, (CriteriaOperator)yyVals[0+yyTop] ); }
  break;
case 40:
#line 192 "grammar.y"
  { yyVal = new UnaryOperator( UnaryOperatorType.BitwiseNot, (CriteriaOperator)yyVals[0+yyTop] ); }
  break;
case 41:
#line 193 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Equal); }
  break;
case 42:
#line 194 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.NotEqual); }
  break;
case 43:
#line 195 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Greater); }
  break;
case 44:
#line 196 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Less); }
  break;
case 45:
#line 197 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.GreaterOrEqual); }
  break;
case 46:
#line 198 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.LessOrEqual); }
  break;
case 47:
#line 199 "grammar.y"
  { yyVal = new BinaryOperator( (CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Like); }
  break;
case 48:
#line 200 "grammar.y"
  { yyVal = new UnaryOperator(UnaryOperatorType.Not, new BinaryOperator( (CriteriaOperator)yyVals[-3+yyTop], (CriteriaOperator)yyVals[0+yyTop], BinaryOperatorType.Like)); }
  break;
case 49:
#line 201 "grammar.y"
  { yyVal = new UnaryOperator(UnaryOperatorType.Not, (CriteriaOperator)yyVals[0+yyTop]); }
  break;
case 50:
#line 202 "grammar.y"
  { yyVal = GroupOperator.And((CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop]); }
  break;
case 51:
#line 203 "grammar.y"
  { yyVal = GroupOperator.Or((CriteriaOperator)yyVals[-2+yyTop], (CriteriaOperator)yyVals[0+yyTop]); }
  break;
case 52:
#line 204 "grammar.y"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 53:
#line 205 "grammar.y"
  { yyVal = new UnaryOperator(UnaryOperatorType.IsNull, (CriteriaOperator)yyVals[-2+yyTop]); }
  break;
case 54:
#line 206 "grammar.y"
  { yyVal = new UnaryOperator(UnaryOperatorType.Not, new UnaryOperator(UnaryOperatorType.IsNull, (CriteriaOperator)yyVals[-3+yyTop])); }
  break;
case 55:
#line 207 "grammar.y"
  { yyVal = new InOperator((CriteriaOperator)yyVals[-2+yyTop], (IEnumerable<CriteriaOperator>)yyVals[0+yyTop]); }
  break;
case 56:
#line 208 "grammar.y"
  { yyVal = new BetweenOperator((CriteriaOperator)yyVals[-6+yyTop], (CriteriaOperator)yyVals[-3+yyTop], (CriteriaOperator)yyVals[-1+yyTop]); }
  break;
case 57:
#line 209 "grammar.y"
  { yyVal = new UnaryOperator(UnaryOperatorType.IsNull, (CriteriaOperator)yyVals[-1+yyTop]); }
  break;
case 58:
#line 210 "grammar.y"
  { yyVal = new FunctionOperator(FunctionOperatorType.IsNull, (CriteriaOperator)yyVals[-3+yyTop], (CriteriaOperator)yyVals[-1+yyTop]); }
  break;
case 59:
#line 211 "grammar.y"
  {  FunctionOperator fo = new FunctionOperator((FunctionOperatorType)yyVals[-1+yyTop], (IEnumerable<CriteriaOperator>)yyVals[0+yyTop]); lexer.CheckFunctionArgumentsCount(fo.OperatorType, fo.Operands.Count); yyVal = fo; }
  break;
case 60:
#line 212 "grammar.y"
  { yyVal = null; }
  break;
case 61:
#line 216 "grammar.y"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 62:
#line 217 "grammar.y"
  { yyVal = new List<CriteriaOperator>(); }
  break;
case 63:
#line 221 "grammar.y"
  {
							List<CriteriaOperator> lst = new List<CriteriaOperator>();
							lst.Add((CriteriaOperator)yyVals[0+yyTop]);
							yyVal = lst;
						}
  break;
case 64:
#line 226 "grammar.y"
  {
							List<CriteriaOperator> lst = (List<CriteriaOperator>)yyVals[-2+yyTop];
							lst.Add((CriteriaOperator)yyVals[0+yyTop]);
							yyVal = lst;
						}
  break;
#line default
		}
		yyTop -= yyLen[yyN];
		yyState = yyStates[yyTop];
		int yyM = yyLhs[yyN];
		if(yyState == 0 && yyM == 0) {
		  yyState = yyFinal;
		  if(yyToken < 0)
			yyToken = yyLex.advance() ? yyLex.token() : 0;
		  if(yyToken == 0)
			return yyVal;
		  goto yyLoop;
		}
		if(((yyN = yyGindex[yyM]) != 0) && ((yyN += yyState) >= 0)
			&& (yyN < yyTable.Length) && (yyCheck[yyN] == yyState))
		  yyState = yyTable[yyN];
		else
		  yyState = yyDgoto[yyM];
	 goto yyLoop;
	  }
	}
  }
Esempio n. 47
0
 object FnSign(FunctionOperator theOperator)
 {
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if(op == null) { return null; }
     switch(Type.GetTypeCode(op.GetType())) {
         case TypeCode.Byte:
         case TypeCode.UInt16:
         case TypeCode.UInt32:
         case TypeCode.UInt64:
             return 1;
         case TypeCode.Decimal:
             return (Decimal)Math.Sign((Decimal)op);
         case TypeCode.Double:
             return (double)Math.Sign((double)op);
         case TypeCode.Int16:
             return (Int16)Math.Sign((Int16)op);
         case TypeCode.Int32:
             return (Int32)Math.Sign((Int32)op);
         case TypeCode.Int64:
             return (Int64)Math.Sign((Int64)op);
         case TypeCode.SByte:
             return (sbyte)Math.Sign((sbyte)op);
         case TypeCode.Single:
             return (Single)Math.Sign((Single)op);
         default:
             throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, FilteringExceptionsText.ExpressionEvaluatorOperatorSubtypeNotSupportedForSpecificOperandType, typeof(FunctionOperator).Name, FunctionOperatorType.Sign.ToString(), op.ToString()));
     }
 }
Esempio n. 48
0
 object FnLog(FunctionOperator theOperator)
 {
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if(op == null) { return null; }
     double value = GetDoubleArgument(op, typeof(FunctionOperator).Name, FunctionOperatorType.Log.ToString());
     #if !(CF || SL)
     if (theOperator.Operands.Count >= 2) {
         object op2 = Process((CriteriaOperator)theOperator.Operands[1]);
         if(op2 == null) { return null; }
         double value2 = GetDoubleArgument(op2, typeof(FunctionOperator).Name, FunctionOperatorType.Log.ToString());
         return Math.Log(value, value2);
     }
     #endif
     return Math.Log(value);
 }
Esempio n. 49
0
 object FnReverse(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if(str == null) { return null; }
     return Reverse(str);
 }
Esempio n. 50
0
 object FnReplace(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if(str == null) { return null; }
     string op2 = Process((CriteriaOperator)theOperator.Operands[1]).ToString();
     if(op2 == null) { return null; }
     string op3 = Process((CriteriaOperator)theOperator.Operands[2]).ToString();
     if(op3 == null) { return null; }
     return str.Replace(op2, op3);
 }
Esempio n. 51
0
 object FnRemove(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if (str == null) { return null; }
     int op2 = Convert.ToInt32(Process((CriteriaOperator)theOperator.Operands[1]));
     #if CF || SL
     int op3 = Convert.ToInt32(Process((CriteriaOperator)theOperator.Operands[2]));
     return str.Remove(op2, op3);
     #else
     if (theOperator.Operands.Count >= 3) {
         int op3 = Convert.ToInt32(Process((CriteriaOperator)theOperator.Operands[2]));
         return str.Remove(op2, op3);
     }
     return str.Remove(op2);
     #endif
 }
Esempio n. 52
0
 public virtual object Visit(FunctionOperator theOperator)
 {
     Validate(theOperator.Operands);
     return null;
 }
Esempio n. 53
0
 object FnIsNullOrEmpty(FunctionOperator theOperator)
 {
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if(op == null) return true;
     return string.IsNullOrEmpty(op.ToString());
 }
Esempio n. 54
0
 object FnSubstring(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if(str == null) { return null; }
     object op2 = Process((CriteriaOperator)theOperator.Operands[1]);
     if(op2 == null) { return null; }
     int iop2 = (int)op2;
     object op3 = null;
     if(theOperator.Operands.Count >= 3) {
         op3 = Process((CriteriaOperator)theOperator.Operands[2]);
     }
     if(op3 == null) {
         return str.Substring(iop2);
     }
     else {
         return str.Substring(iop2, (int)op3);
     }
 }
Esempio n. 55
0
 object FnTanh(FunctionOperator theOperator)
 {
     object result;
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if (op == null) { result = null; }
     double value = GetDoubleArgument(op, typeof(FunctionOperator).Name, FunctionOperatorType.Tanh.ToString());
     result = Math.Tanh(value);
     return result;
 }
Esempio n. 56
0
 object FnTrim(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if(str == null) { return null; }
     return str.Trim();
 }
Esempio n. 57
0
 object FnSqr(FunctionOperator theOperator)
 {
     object result;
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if(op == null) { result = null; }
     double value = GetDoubleArgument(op, typeof(FunctionOperator).Name, FunctionOperatorType.Sqr.ToString());
     if(value < 0) {
         throw new ArgumentException("Value can't be negative.");
     }
     result = Math.Sqrt(value);
     return result;
 }
Esempio n. 58
0
 object FnPadRight(FunctionOperator theOperator)
 {
     string str = GetFirstArgumentAsString(theOperator);
     if (str == null) { return null; }
     object op2 = Process((CriteriaOperator)theOperator.Operands[1]);
     if (op2 == null) { return null; }
     switch (Type.GetTypeCode(op2.GetType())) {
         case TypeCode.UInt16:
         case TypeCode.Int16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.SByte:
         case TypeCode.Byte:
         break;
         default:
         throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, FilteringExceptionsText.ExpressionEvaluatorOperatorSubtypeNotSupportedForSpecificOperandType, typeof(FunctionOperator).Name, FunctionOperatorType.PadRight.ToString(), op2.ToString()));
     }
     int totalWidth = Convert.ToInt32(op2);
     if (theOperator.Operands.Count >= 3) {
         object op3 = Process((CriteriaOperator)theOperator.Operands[2]);
         if (op3 == null) { return null; }
         if (op3 is char) {
             return str.PadRight(totalWidth, (char)op3);
         } else if (op3 is string && ((string)op3).Length > 0) {
             return str.PadRight(totalWidth, ((string)op3)[0]);
         }
     }
     return str.PadRight(totalWidth);
 }
Esempio n. 59
0
 object FnRound(FunctionOperator theOperator)
 {
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if(op == null) { return null; }
     switch(Type.GetTypeCode(op.GetType())) {
         case TypeCode.UInt16:
         case TypeCode.UInt32:
         case TypeCode.UInt64:
         case TypeCode.Int16:
         case TypeCode.Int32:
         case TypeCode.Int64:
         case TypeCode.SByte:
         case TypeCode.Byte:
             return op;
         case TypeCode.Decimal:
     #if CF || SL
             return (Decimal)Math.Round(Convert.ToDouble(op));
     #else
             return Math.Round((Decimal)op);
     #endif
         case TypeCode.Double:
             return Math.Round((double)op);
         case TypeCode.Single:
             return (Single)Math.Round((Single)op);
         default:
             throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, FilteringExceptionsText.ExpressionEvaluatorOperatorSubtypeNotSupportedForSpecificOperandType, typeof(FunctionOperator).Name, FunctionOperatorType.Round.ToString(), op.ToString()));
     }
 }
Esempio n. 60
0
 object FnStr(FunctionOperator theOperator)
 {
     object op = Process((CriteriaOperator)theOperator.Operands[0]);
     if(op == null) { return null; }
     return GetStringFromNumber(op, typeof(FunctionOperator).Name, FunctionOperatorType.ToStr.ToString());
 }