Example #1
0
        public IHttpActionResult DeviceToken(FToken fToken)
        {
            if (ModelState.IsValid && fToken != null)
            {
                MiddelLayer.FirebaseToken firebaseToken = new MiddelLayer.FirebaseToken();

                return(GetJsonResult(new BaseResponse()
                {
                    ResponseObject = firebaseToken.Insert(fToken),
                    Message = "Device registered successfully",
                    StatusCode = 200
                }));
            }
            return(GetJsonResult(new BaseResponse()
            {
                Message = "All input fields are required.",
                StatusCode = 200
            }));
        }
Example #2
0
        /// <summary>
        /// Handles function parameters
        /// </summary>
        private void ParameterList(FToken e)
        {
            int n = 0;

            if (_PfTokens[_PfTokens.Count - 1] == FToken.User)
            {
                _PfTokens.Add(e);
                n++;
            }

            FToken t = GetToken();

            while (t != FToken.RParen && t != FToken.BadToken)
            {
                PutToken(t);

                int count = _PfTokens.Count;

                Expr();

                if (_PfTokens.Count > count)
                    n++;

                t = GetToken();

                if (t != FToken.Comma)
                    break;

                t = GetToken();
            }

            PutToken(t);

            _PfTokens.Add(FToken.Function);
            _PfTokens.Add((FToken)n);
        }
Example #3
0
        /// <summary>
        /// Handles function parsing
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private bool Function(FToken e)
        {
            string s = _OperandPool[(int)e] as string;

            if (s == null)
            {
                GridColumn col = _OperandPool[(int)e] as GridColumn;

                if (col != null)
                    s = col.Name;
            }

            if (s != null)
            {
                s = s.ToLower();

                FToken t = GetFunction(s);

                if (t != FToken.BadToken)
                {
                    _PfTokens.Add(t);

                    t = GetToken();

                    if (t != FToken.LParen)
                        throw new Exception(_missingParenString);

                    ParameterList(e);

                    t = GetToken();

                    if (t != FToken.RParen)
                        throw new Exception(_missingParenString);

                    return (true);
                }
            }

            return (false);
        }
Example #4
0
 public TokenPair(string text, FToken token)
 {
     Text = text;
     Token = token;
 }
Example #5
0
            public static string GetOpTokenText(FToken token)
            {
                foreach (TokenPair tp in TokenListB)
                {
                    if (tp.Token == token)
                        return (tp.Text);
                }

                foreach (TokenPair tp in TokenListA)
                {
                    if (tp.Token == token)
                        return (tp.Text);
                }

                return ("****");
            }
Example #6
0
        private void InfixOperator(Stack myStack, FToken token)
        {
            if (myStack.Count < 2)
                throw new Exception(_exprErrorString);

            string o1 = InfixValue(myStack.Pop());
            string o2 = InfixValue(myStack.Pop());

            string op = FTokenList.GetOpTokenText(token);

            string s;

            if (token == FToken.Between)
            {
                string o3 = InfixValue(myStack.Pop());

                s = o3 + ColorPart(" is between ", ExprColorPart.Operator) +
                    o2 + ColorPart(" and ", ExprColorPart.Operator) + o1;
            }
            else if (token == FToken.Like)
            {
                s = o2 + ColorPart(" is " + op + " ", ExprColorPart.Operator) + o1;
            }
            else
            {
                s = o2 + " " + ColorPart(op, ExprColorPart.Operator) + " " + o1;
            }

            myStack.Push("(" + s + ")");
        }
Example #7
0
        private void InfixShortCircuit(
            Stack myStack, FToken token)
        {
            string s = GetInfixEx((List<FToken>)_OperandPool[(int)token]);

            myStack.Push(s);
        }
Example #8
0
        private bool ReduceNumeric(
            FToken t, double d1, double d2, out double d3)
        {
            d3 = 0;

            switch (t)
            {
                case FToken.Add:
                    d3 = d2 + d1;
                    break;

                case FToken.Subtract:
                    d3 = d2 - d1;
                    break;

                case FToken.Divide:
                    d3 = d2 / d1;
                    break;

                case FToken.Multiply:
                    d3 = d2 * d1;
                    break;

                case FToken.ShiftLeft:
                    d3 = (int)d2 << (int)d1;
                    break;

                case FToken.ShiftRight:
                    d3 = (int)d2 >> (int)d1;
                    break;

                case FToken.Mod:
                    d3 = d2 % d1;
                    break;

                default:
                    return (false);
            }

            return (true);
        }
Example #9
0
        private void OpBoolValue(
            Stack myStack, FToken op, object o1, object o2)
        {
            int b1 = GetBoolInt(o1);
            int b2 = GetBoolInt(o2);

            switch (op)
            {
                case FToken.LogicalAnd:
                    myStack.Push((b2 == 1) && (b1 == 1));
                    break;

                case FToken.LogicalOr:
                    myStack.Push((b2 == 1) || (b1 == 1));
                    break;

                case FToken.ConditionalAnd:
                    myStack.Push((b2 == 1) && (b1 == 1));
                    break;

                case FToken.ConditionalOr:
                    myStack.Push((b2 == 1) || (b1 == 1));
                    break;

                case FToken.LogicalXor:
                    myStack.Push((b2 == 1) ^ (b1 == 1));
                    break;

                case FToken.Is:
                case FToken.Equal:
                case FToken.Like:
                    myStack.Push(b2 == b1);
                    break;

                case FToken.NotEqual:
                case FToken.NotEqual2:
                    myStack.Push(b2 != b1);
                    break;

                default:
                    throw new Exception(_invalidBoolOpString);
            }
        }
Example #10
0
        private void OpStringValue(
            Stack myStack, FToken op, object o1, object o2)
        {
            string s1 = (o1 != null ? o1.ToString() : "");
            string s2 = (o2 != null ? o2.ToString() : "");

            switch (op)
            {
                case FToken.Add:
                    myStack.Push(s2 + s1);
                    break;

                case FToken.Is:
                case FToken.Equal:
                    if (_MatchType == FilterMatchType.None)
                    {
                        if (GridPanel.FilterIgnoreMatchCase == true)
                        {
                            s1 = s1.ToLower();
                            s2 = s2.ToLower();
                        }

                        myStack.Push(s2.Equals(s1));
                    }
                    else
                    {
                        if (o2 == null)
                        {
                            myStack.Push(o1 == null);
                        }
                        else
                        {
                            _PostError = false;

                            myStack.Push(Regex.IsMatch(s2, s1,
                                 GridPanel.FilterIgnoreMatchCase ? RegexOptions.IgnoreCase : RegexOptions.None));
                        }
                    }
                    break;

                case FToken.NotEqual:
                case FToken.NotEqual2:
                    if (_MatchType == FilterMatchType.None)
                    {
                        if (GridPanel.FilterIgnoreMatchCase == true)
                        {
                            s1 = s1.ToLower();
                            s2 = s2.ToLower();
                        }

                        myStack.Push(s2.Equals(s1) == false);
                    }
                    else
                    {
                        if (o2 == null)
                        {
                            myStack.Push(o1 != null);
                        }
                        else
                        {
                            _PostError = false;

                            myStack.Push(Regex.IsMatch(s2, s1,
                                GridPanel.FilterIgnoreMatchCase ? RegexOptions.IgnoreCase : RegexOptions.None) == false);
                        }
                    }
                    break;

                case FToken.LessThan:
                    myStack.Push(s2.CompareTo(s1) < 0);
                    break;

                case FToken.LessThanOrEqual:
                    myStack.Push(s2.CompareTo(s1) <= 0);
                    break;

                case FToken.GreaterThan:
                    myStack.Push(s2.CompareTo(s1) > 0);
                    break;

                case FToken.GreaterThanOrEqual:
                    myStack.Push(s2.CompareTo(s1) >= 0);
                    break;

                case FToken.Like:
                    if (_MatchType == FilterMatchType.None)
                    {
                        if (GridPanel.FilterIgnoreMatchCase == true)
                        {
                            s1 = s1.ToLower();
                            s2 = s2.ToLower();
                        }

                        myStack.Push(s2.StartsWith(s1));
                    }
                    else
                    {
                        _PostError = false;

                        myStack.Push(Regex.IsMatch(s2, s1,
                            GridPanel.FilterIgnoreMatchCase ? RegexOptions.IgnoreCase : RegexOptions.None));
                    }
                    break;

                case FToken.Between:
                    object value = ProcessValue(myStack.Pop());

                    if (value == null || value == EmptyOp)
                    {
                        myStack.Push(false);
                    }
                    else
                    {
                        string s3 = (string)(value);

                        myStack.Push(s3.CompareTo(s2) >= 0 && s3.CompareTo(s1) <= 0);
                    }
                    break;

                default:
                    throw new Exception(_invalidStringOpString);
            }
        }
Example #11
0
        private void OpDateTimeValue(
            Stack myStack, FToken op, object o1, object o2)
        {
            if (op == FToken.Add)
            {
                OpDateTimeValueAdd(myStack, o1, o2);
            }
            else if (op == FToken.Subtract)
            {
                OpDateTimeValueSubtract(myStack, o1, o2);
            }
            else if ((o1 is DateTime || o1 == null) && (o2 is DateTime || o2 == null))
            {
                DateTime d1 = (DateTime)(o1 ?? DateTime.MinValue);
                DateTime d2 = (DateTime)(o2 ?? DateTime.MinValue);

                switch (op)
                {
                    case FToken.Is:
                    case FToken.Equal:
                        myStack.Push(d2.Equals(d1));
                        break;

                    case FToken.NotEqual:
                    case FToken.NotEqual2:
                        myStack.Push(d2.Equals(d1) == false);
                        break;

                    case FToken.LessThan:
                        myStack.Push(d2.CompareTo(d1) < 0);
                        break;

                    case FToken.LessThanOrEqual:
                        myStack.Push(d2.CompareTo(d1) <= 0);
                        break;

                    case FToken.GreaterThan:
                        myStack.Push(d2.CompareTo(d1) > 0);
                        break;

                    case FToken.GreaterThanOrEqual:
                        myStack.Push(d2.CompareTo(d1) >= 0);
                        break;

                    case FToken.Between:
                        object value = ProcessValue(myStack.Pop());

                        if (value == null || value == EmptyOp)
                        {
                            myStack.Push(false);
                        }
                        else
                        {
                            if (value is DateTime == false)
                                throw new Exception(_invalidDateTimeOpString);

                            DateTime d3 = (DateTime)value;

                            myStack.Push(d3 >= d2 && d3 <= d1);
                        }
                        break;

                    default:
                        throw new Exception(_invalidDateTimeOpString);
                }
            }
            else
            {
                throw new Exception(_invalidDateTimeOpString);
            }
        }
Example #12
0
        private void OpEmptyValue(
            Stack myStack, FToken op, object o1, object o2)
        {
            switch (op)
            {
                case FToken.Is:
                case FToken.Like:
                case FToken.Equal:
                case FToken.LessThanOrEqual:
                case FToken.GreaterThanOrEqual:
                    myStack.Push((o2 == EmptyOp && o1 == EmptyOp));
                    break;

                case FToken.NotEqual:
                case FToken.NotEqual2:
                    myStack.Push(o2 != o1);
                    break;

                case FToken.LessThan:
                    myStack.Push(o2 == o1 ? false : o2 == EmptyOp);
                    break;
                
                case FToken.GreaterThan:
                    myStack.Push(o2 == o1 ? false : o2 != EmptyOp);
                    break;

                case FToken.LogicalAnd:
                case FToken.LogicalXor:
                case FToken.Add:
                case FToken.Subtract:
                case FToken.Multiply:
                case FToken.Divide:
                case FToken.Mod:
                case FToken.ShiftLeft:
                case FToken.ShiftRight:
                    myStack.Push(EmptyOp);
                    break;

                default:
                    throw new Exception(_invalidEmptyOpString);
            }
        }
Example #13
0
        private void EvalOperator(Stack myStack, FToken token)
        {
            if (myStack.Count < 2)
                throw new Exception(_exprErrorString);

            _PostError = true;

            object value1 = ProcessValue(myStack.Pop());
            object value2 = ProcessValue(myStack.Pop());

            if (value1 == EmptyOp || value2 == EmptyOp)
                OpEmptyValue(myStack, token, value1, value2);

            else if (value1 is bool || value2 is bool)
                OpBoolValue(myStack, token, value1, value2);

            else if (value1 is DateTime || value2 is DateTime)
                OpDateTimeValue(myStack, token, value1, value2);

            else if (value1 is string || value2 is string)
                OpStringValue(myStack, token, value1, value2);

            else
                OpDoubleValue(myStack, token, value1, value2);
        }
Example #14
0
        private void EvalShortCircuit(
            Stack myStack, FToken token, bool evres)
        {
            bool res = (bool)myStack.Peek();

            if (res == evres)
            {
                res = EvaluateEx(
                    (List<FToken>)_OperandPool[(int)token]);
            }

            myStack.Push(res);
        }
Example #15
0
 /// <summary>
 /// Saves the given token for future use
 /// </summary>
 /// <param name="t"></param>
 private void PutToken(FToken t)
 {
     _PTokens[_PCount++] = t;
 }
Example #16
0
        private bool ReduceTerm(FToken t)
        {
            if (_PfTokens.Count >= 2)
            {
                FToken t1 = _PfTokens[_PfTokens.Count - 1];
                FToken t2 = _PfTokens[_PfTokens.Count - 2];

                if (t1 < FToken.Operator && t2 < FToken.Operator)
                {
                    object o1 = _OperandPool[(int) t1];
                    object o2 = _OperandPool[(int) t2];

                    if (o1 != null && o2 != null && o1.GetType() == o2.GetType())
                    {
                        if (o1 is string)
                        {
                            switch (t)
                            {
                                case FToken.Add:
                                    string s = (string) o2 + (string) o1;

                                    _PfTokens.RemoveAt(_PfTokens.Count - 1);
                                    _PfTokens[_PfTokens.Count - 1] = ProcessObject(s);

                                    return (true);

                                default:
                                    return (false);
                            }
                        }

                        if (o1 is int)
                        {
                            double d1 = Convert.ToDouble(o1);
                            double d2 = Convert.ToDouble(o2);

                            double d3;

                            if (ReduceNumeric(t, d1, d2, out d3) == false)
                                return (false);

                            int n = (int) d3;

                            _PfTokens.RemoveAt(_PfTokens.Count - 1);
                            _PfTokens[_PfTokens.Count - 1] = ProcessObject(n);

                            return (true);
                        }

                        if (o1 is double)
                        {
                            double d3;

                            if (ReduceNumeric(t, (double) o1, (double) o2, out d3) == false)
                                return (false);

                            _PfTokens.RemoveAt(_PfTokens.Count - 1);
                            _PfTokens[_PfTokens.Count - 1] = ProcessObject(d3);

                            return (true);
                        }
                    }
                }
            }

            return (false);
        }
Example #17
0
        private void OpDoubleValue(
            Stack myStack, FToken op, object o1, object o2)
        {
            if (o1 == null && o2 == null)
            {
                switch (op)
                {
                    case FToken.LogicalAnd:
                    case FToken.LogicalXor:
                    case FToken.Add:
                    case FToken.Subtract:
                    case FToken.Multiply:
                    case FToken.Divide:
                    case FToken.Mod:
                    case FToken.ShiftLeft:
                    case FToken.ShiftRight:
                        myStack.Push(0d);
                        break;

                    case FToken.Is:
                    case FToken.Equal:
                    case FToken.LessThanOrEqual:
                    case FToken.GreaterThanOrEqual:
                    case FToken.Like:
                        myStack.Push(true);
                        break;

                    case FToken.NotEqual:
                    case FToken.NotEqual2:
                    case FToken.LessThan:
                    case FToken.GreaterThan:
                    case FToken.ConditionalAnd:
                    case FToken.ConditionalOr:
                        myStack.Push(false);
                        break;

                    default:
                        throw new Exception(_invalidNumericOpString);
                }
            }
            else
            {
                double d1 = Convert.ToDouble(o1);
                double d2 = Convert.ToDouble(o2);

                switch (op)
                {
                    case FToken.LogicalAnd:
                        myStack.Push((double)((int)d2 & (int)d1));
                        break;

                    case FToken.LogicalOr:
                        myStack.Push((double)((int)d2 | (int)d1));
                        break;

                    case FToken.LogicalXor:
                        myStack.Push((double)((int)d2 ^ (int)d1));
                        break;

                    case FToken.Add:
                        myStack.Push(d2 + d1);
                        break;

                    case FToken.Subtract:
                        myStack.Push(d2 - d1);
                        break;

                    case FToken.Multiply:
                        myStack.Push(d2 * d1);
                        break;

                    case FToken.Divide:
                        myStack.Push(d2 / d1);
                        break;

                    case FToken.Mod:
                        myStack.Push(d2 % d1);
                        break;

                    case FToken.ShiftLeft:
                        myStack.Push((double)((int)d2 << (int)d1));
                        break;

                    case FToken.ShiftRight:
                        myStack.Push((double)((int)d2 >> (int)d1));
                        break;

                    case FToken.Equal:
                        myStack.Push(o1 == null | o2 == null ? false : d1 == d2);
                        break;

                    case FToken.Is:
                    case FToken.Like:
                        myStack.Push(d2 == d1);
                        break;

                    case FToken.NotEqual:
                    case FToken.NotEqual2:
                        myStack.Push(o1 == null | o2 == null ? true : d1 != d2);
                        break;

                    case FToken.LessThan:
                        myStack.Push(d2 < d1);
                        break;

                    case FToken.LessThanOrEqual:
                        myStack.Push(d2 <= d1);
                        break;
                    case FToken.GreaterThan:
                        myStack.Push(d2 > d1);
                        break;

                    case FToken.GreaterThanOrEqual:
                        myStack.Push(d2 >= d1);
                        break;

                    case FToken.Between:
                        object value = ProcessValue(myStack.Pop());

                        if (value == null || value == EmptyOp)
                        {
                            myStack.Push(false);
                        }
                        else
                        {
                            double d3 = Convert.ToDouble(value);

                            myStack.Push(d3 >= d2 && d3 <= d1);
                        }
                        break;

                    default:
                        throw new Exception(_invalidNumericOpString);
                }
            }
        }