private static object ExpCalculateUserFunction(string funcName, ParamObjectCollection arrParams, object callerContext)
        {
            object     result  = null;
            ExpContext context = (ExpContext)callerContext;

            switch (funcName.ToLower())
            {
            case "users":
                result = "USERS";
                break;

            case "organizations":
                result = "ORGANIZATIONS";
                break;

            case "groups":
                result = "GROUPS";
                break;

            case "belongto":
                result = CalculateBelongTo((string)arrParams[0].Value, (string)arrParams[1].Value, (string)arrParams[2].Value, context);
                break;

            case "userrank":
                result = CompareUserRank((string)arrParams[0].Value, (string)arrParams[1].Value, context);
                break;
            }

            return(result);
        }
        private static bool CompareUserRank(string rankName, string op, ExpContext context)
        {
            bool result = false;

            string currentUserRank   = context.UserRow["RANK_CODE"].ToString();
            int    currentUserSortID = FindRankSortID(currentUserRank, context.RankDefine);
            int    predefinedSortID  = FindRankSortID(rankName, context.RankDefine);

            switch (op)
            {
            case "<":
                result = currentUserSortID > predefinedSortID;
                break;

            case "<=":
                result = currentUserSortID >= predefinedSortID;
                break;

            case ">":
                result = currentUserSortID < predefinedSortID;
                break;

            case ">=":
                result = currentUserSortID < predefinedSortID;
                break;

            case "==":
                result = currentUserSortID == predefinedSortID;
                break;
            }

            return(result);
        }
        private static DataSet GetUserRolesDS(DataTable tableExpression, ExpContext context)
        {
            Dictionary <string, string> roleIDs = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (DataRow row in tableExpression.Rows)
            {
                string roleID = row["ROLE_ID"].ToString();

                if (roleIDs.ContainsKey(roleID) == false)
                {
                    string exp = row["EXPRESSION"].ToString();

                    if (EvaluateExp(exp, context))
                    {
                        roleIDs.Add(roleID, roleID);
                    }
                }
            }

            List <string> listRoleIDs = new List <string>();

            foreach (KeyValuePair <string, string> kp in roleIDs)
            {
                listRoleIDs.Add(kp.Key);
            }

            return(GetRolesByIDs(listRoleIDs.ToArray()));
        }
示例#4
0
    public ExpContext exp()
    {
        ExpContext _localctx = new ExpContext(Context, State);

        EnterRule(_localctx, 8, RULE_exp);
        int _la;

        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 27;
                ErrorHandler.Sync(this);
                _la = TokenStream.La(1);
                do
                {
                    {
                        State = 27;
                        switch (Interpreter.AdaptivePredict(TokenStream, 0, Context))
                        {
                        case 1:
                        {
                            State = 23; block();
                        }
                        break;

                        case 2:
                        {
                            State = 24; token();
                        }
                        break;

                        case 3:
                        {
                            State = 25; opdef();
                        }
                        break;

                        case 4:
                        {
                            State = 26; Match(NEWLINE);
                        }
                        break;
                        }
                    }
                    State = 29;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.La(1);
                } while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__10) | (1L << T__11) | (1L << TRUE) | (1L << FALSE) | (1L << STRING) | (1L << INT) | (1L << FLOAT) | (1L << ID) | (1L << OP) | (1L << NATIVE) | (1L << OPEN_PAREN) | (1L << OPEN_BRACK) | (1L << NEWLINE))) != 0));
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
示例#5
0
        public ExpContext exp()
        {
            ExpContext _localctx = new ExpContext(_ctx, State);

            EnterRule(_localctx, 2, RULE_exp);
            int _la;

            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State           = 17; _localctx.a = exp2();
                    _localctx.value = _localctx.a.value;
                    State           = 29;
                    _errHandler.Sync(this);
                    _la = _input.La(1);
                    while (_la == ADD || _la == SUB)
                    {
                        {
                            State = 27;
                            _errHandler.Sync(this);
                            switch (_input.La(1))
                            {
                            case ADD:
                            {
                                State           = 19; Match(ADD);
                                State           = 20; _localctx.b = exp2();
                                _localctx.value = _localctx.value + _localctx.b.value;
                            }
                            break;

                            case SUB:
                            {
                                State           = 23; Match(SUB);
                                State           = 24; _localctx.b = exp2();
                                _localctx.value = _localctx.value - _localctx.b.value;
                            }
                            break;

                            default:
                                throw new NoViableAltException(this);
                            }
                        }
                        State = 31;
                        _errHandler.Sync(this);
                        _la = _input.La(1);
                    }
                    System.Console.WriteLine(_localctx.value);
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
    private bool exp_sempred(ExpContext _localctx, int predIndex)
    {
        switch (predIndex)
        {
        case 0: return(Precpred(Context, 9));

        case 1: return(Precpred(Context, 7));

        case 2: return(Precpred(Context, 6));
        }
        return(true);
    }
        public override ASTNode VisitExp([NotNull] ExpContext ctx)
        {
            if (!ctx.exp()?.Any() ?? true)
            {
                string firstToken = ctx.children.First().GetText();
                switch (firstToken)
                {
                case "nil":
                    return(new NullLitExprNode(ctx.Start.Line));

                case "true":
                case "false":
                    return(LitExprNode.FromString(ctx.Start.Line, firstToken));

                case "...":
                    throw new NotImplementedException("...");
                }

                if (ctx.number() is { })
        /// <summary>
        /// 得到用户在某个应用下的角色
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="appCodeName"></param>
        /// <param name="rightMask"></param>
        /// <returns></returns>
        public static DataSet GetUserAppRoles(
            string userID,
            string appCodeName,
            RightMaskType rightMask)
        {
            IList <string> deptIDs         = PrepareUserDepartmentIDs(userID);
            DataTable      tableExpression = GetAllExpressionsInApp(appCodeName, rightMask);

            ExpContext context = new ExpContext();

            DataTable userTable = OGUReader.GetObjectsDetail("USERS", userID, SearchObjectColumn.SEARCH_GUID, string.Empty, SearchObjectColumn.SEARCH_NULL, "RANK_CODE").Tables[0];

            ExceptionHelper.FalseThrow(userTable.Rows.Count > 0, "不能找到User ID为{0}的用户信息", userID);

            context.UserRow    = userTable.Rows[0];
            context.UserDepts  = deptIDs;
            context.RankDefine = OGUReader.GetRankDefine(2).Tables[0].Rows;
            context.UserGroups = PrepareUserGroupIDs(userID);

            return(GetUserRolesDS(tableExpression, context));
        }
		/// <summary>
		/// 得到用户在某个应用下的角色
		/// </summary>
		/// <param name="userID"></param>
		/// <param name="appCodeName"></param>
		/// <param name="rightMask"></param>
		/// <returns></returns>
		public static DataSet GetUserAppRoles(
			string userID,
			string appCodeName,
			RightMaskType rightMask)
		{
			IList<string> deptIDs = PrepareUserDepartmentIDs(userID);
			DataTable tableExpression = GetAllExpressionsInApp(appCodeName, rightMask);

			ExpContext context = new ExpContext();

			DataTable userTable = OGUReader.GetObjectsDetail("USERS", userID, SearchObjectColumn.SEARCH_GUID, string.Empty, SearchObjectColumn.SEARCH_NULL, "RANK_CODE").Tables[0];

			ExceptionHelper.FalseThrow(userTable.Rows.Count > 0, "不能找到User ID为{0}的用户信息", userID);

			context.UserRow = userTable.Rows[0];
			context.UserDepts = deptIDs;
			context.RankDefine = OGUReader.GetRankDefine(2).Tables[0].Rows;
			context.UserGroups = PrepareUserGroupIDs(userID);

			return GetUserRolesDS(tableExpression, context);
		}
示例#10
0
    public ParamContext param()
    {
        ParamContext _localctx = new ParamContext(Context, State);

        EnterRule(_localctx, 4, RULE_param);
        try {
            State = 33;
            ErrorHandler.Sync(this);
            switch (Interpreter.AdaptivePredict(TokenStream, 3, Context))
            {
            case 1:
                _localctx = new RefVarContext(_localctx);
                EnterOuterAlt(_localctx, 1);
                {
                    State = 31; Match(R_VAR);
                }
                break;

            case 2:
                _localctx = new ExpContext(_localctx);
                EnterOuterAlt(_localctx, 2);
                {
                    State = 32; expr(0);
                }
                break;
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
示例#11
0
		private static DataSet GetUserRolesDS(DataTable tableExpression, ExpContext context)
		{
			Dictionary<string, string> roleIDs = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

			foreach (DataRow row in tableExpression.Rows)
			{
				string roleID = row["ROLE_ID"].ToString();

				if (roleIDs.ContainsKey(roleID) == false)
				{
					string exp = row["EXPRESSION"].ToString();

					if (EvaluateExp(exp, context))
						roleIDs.Add(roleID, roleID);
				}
			}

			List<string> listRoleIDs = new List<string>();

			foreach (KeyValuePair<string, string> kp in roleIDs)
				listRoleIDs.Add(kp.Key);

			return GetRolesByIDs(listRoleIDs.ToArray());
		}
示例#12
0
	private bool exp_sempred(ExpContext _localctx, int predIndex) {
		switch (predIndex) {
		case 0: return Precpred(Context, 6);
		case 1: return Precpred(Context, 5);
		case 2: return Precpred(Context, 4);
		}
		return true;
	}
示例#13
0
 public override ASTNode VisitExp([NotNull] ExpContext ctx)
 {
     if (ctx.literal() is { } || ctx.var() is { } || ctx.cexp() is { })
示例#14
0
		private static bool CompareUserRank(string rankName, string op, ExpContext context)
		{
			bool result = false;

			string currentUserRank = context.UserRow["RANK_CODE"].ToString();
			int currentUserSortID = FindRankSortID(currentUserRank, context.RankDefine);
			int predefinedSortID = FindRankSortID(rankName, context.RankDefine);

			switch (op)
			{
				case "<":
					result = currentUserSortID > predefinedSortID;
					break;
				case "<=":
					result = currentUserSortID >= predefinedSortID;
					break;
				case ">":
					result = currentUserSortID < predefinedSortID;
					break;
				case ">=":
					result = currentUserSortID < predefinedSortID;
					break;
				case "==":
					result = currentUserSortID == predefinedSortID;
					break;
			}

			return result;
		}
示例#15
0
        private static bool CalculateBelongTo(string objType, string objID, string parentID, ExpContext context)
        {
            bool result = false;

            switch (objType)
            {
            case "USERS":
                result = objID == context.UserRow["GUID"].ToString();
                break;

            case "ORGANIZATIONS":
                result = ObjIDInList(objID, context.UserDepts);
                break;

            case "GROUPS":
                result = ObjIDInList(objID, context.UserGroups);
                break;
            }

            return(result);
        }
示例#16
0
		private static bool CalculateBelongTo(string objType, string objID, string parentID, ExpContext context)
		{
			bool result = false;

			switch (objType)
			{
				case "USERS":
					result = objID == context.UserRow["GUID"].ToString();
					break;
				case "ORGANIZATIONS":
					result = ObjIDInList(objID, context.UserDepts);
					break;
				case "GROUPS":
					result = ObjIDInList(objID, context.UserGroups);
					break;
			}

			return result;
		}
示例#17
0
	private ExpContext exp(int _p) {
		ParserRuleContext _parentctx = Context;
		int _parentState = State;
		ExpContext _localctx = new ExpContext(Context, _parentState);
		ExpContext _prevctx = _localctx;
		int _startState = 2;
		EnterRecursionRule(_localctx, 2, RULE_exp, _p);
		try {
			int _alt;
			EnterOuterAlt(_localctx, 1);
			{
			State = 51;
			switch (TokenStream.La(1)) {
			case LD:
			case JR:
			case JP:
			case OR:
			case CP:
			case RL:
			case RR:
			case DI:
			case EI:
			case DB:
			case LDD:
			case LDI:
			case ADD:
			case ADC:
			case SBC:
			case BIT:
			case RES:
			case SET:
			case RET:
			case INC:
			case DEC:
			case SUB:
			case AND:
			case XOR:
			case RLC:
			case RRC:
			case POP:
			case SLA:
			case SRA:
			case SRL:
			case NOP:
			case RLA:
			case RRA:
			case DAA:
			case CPL:
			case SCF:
			case CCF:
			case LDH:
			case RST:
			case CALL:
			case PUSH:
			case SWAP:
			case RLCA:
			case RRCA:
			case STOP:
			case HALT:
			case RETI:
				{
				State = 48; op();
				}
				break;
			case REPT:
			case SECTION:
			case INCLUDE:
				{
				State = 49; sys();
				}
				break;
			case LIMSTRING:
				{
				State = 50; label();
				}
				break;
			default:
				throw new NoViableAltException(this);
			}
			Context.Stop = TokenStream.Lt(-1);
			State = 61;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,2,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					if ( ParseListeners!=null )
						TriggerExitRuleEvent();
					_prevctx = _localctx;
					{
					State = 59;
					ErrorHandler.Sync(this);
					switch ( Interpreter.AdaptivePredict(TokenStream,1,Context) ) {
					case 1:
						{
						_localctx = new ExpContext(_parentctx, _parentState);
						PushNewRecursionContext(_localctx, _startState, RULE_exp);
						State = 53;
						if (!(Precpred(Context, 6))) throw new FailedPredicateException(this, "Precpred(Context, 6)");
						State = 54; op();
						}
						break;
					case 2:
						{
						_localctx = new ExpContext(_parentctx, _parentState);
						PushNewRecursionContext(_localctx, _startState, RULE_exp);
						State = 55;
						if (!(Precpred(Context, 5))) throw new FailedPredicateException(this, "Precpred(Context, 5)");
						State = 56; sys();
						}
						break;
					case 3:
						{
						_localctx = new ExpContext(_parentctx, _parentState);
						PushNewRecursionContext(_localctx, _startState, RULE_exp);
						State = 57;
						if (!(Precpred(Context, 4))) throw new FailedPredicateException(this, "Precpred(Context, 4)");
						State = 58; label();
						}
						break;
					}
					} 
				}
				State = 63;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,2,Context);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			UnrollRecursionContexts(_parentctx);
		}
		return _localctx;
	}
示例#18
0
		private static bool EvaluateExp(string exp, ExpContext context)
		{
			return (bool)ExpressionParser.Calculate(exp, new CalculateUserFunction(ExpCalculateUserFunction), context);
		}
示例#19
0
 private static bool EvaluateExp(string exp, ExpContext context)
 {
     return((bool)ExpressionParser.Calculate(exp, new CalculateUserFunction(ExpCalculateUserFunction), context));
 }
    private ExpContext exp(int _p)
    {
        ParserRuleContext _parentctx = Context;
        int        _parentState      = State;
        ExpContext _localctx         = new ExpContext(Context, _parentState);
        ExpContext _prevctx          = _localctx;
        int        _startState       = 10;

        EnterRecursionRule(_localctx, 10, RULE_exp, _p);
        int _la;

        try {
            int _alt;
            EnterOuterAlt(_localctx, 1);
            {
                State = 63;
                ErrorHandler.Sync(this);
                switch (Interpreter.AdaptivePredict(TokenStream, 6, Context))
                {
                case 1:
                {
                    State = 52; Match(Minus);
                    State = 53; exp(8);
                }
                break;

                case 2:
                {
                    State = 54; Match(LeftParen);
                    State = 55; exp(0);
                    State = 56; Match(RightParen);
                }
                break;

                case 3:
                {
                    State = 58; log_exp();
                }
                break;

                case 4:
                {
                    State = 59; trig_exp();
                }
                break;

                case 5:
                {
                    State = 60; Match(LeftParen);
                    State = 61; Match(RightParen);
                }
                break;

                case 6:
                {
                    State = 62; node();
                }
                break;
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 76;
                ErrorHandler.Sync(this);
                _alt = Interpreter.AdaptivePredict(TokenStream, 8, Context);
                while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                {
                    if (_alt == 1)
                    {
                        if (ParseListeners != null)
                        {
                            TriggerExitRuleEvent();
                        }
                        _prevctx = _localctx;
                        {
                            State = 74;
                            ErrorHandler.Sync(this);
                            switch (Interpreter.AdaptivePredict(TokenStream, 7, Context))
                            {
                            case 1:
                            {
                                _localctx = new ExpContext(_parentctx, _parentState);
                                PushNewRecursionContext(_localctx, _startState, RULE_exp);
                                State = 65;
                                if (!(Precpred(Context, 9)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 9)");
                                }
                                State = 66; Match(Power);
                                State = 67; exp(10);
                            }
                            break;

                            case 2:
                            {
                                _localctx = new ExpContext(_parentctx, _parentState);
                                PushNewRecursionContext(_localctx, _startState, RULE_exp);
                                State = 68;
                                if (!(Precpred(Context, 7)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 7)");
                                }
                                State = 69;
                                _la   = TokenStream.LA(1);
                                if (!(_la == Multiply || _la == Divide))
                                {
                                    ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 70; exp(8);
                            }
                            break;

                            case 3:
                            {
                                _localctx = new ExpContext(_parentctx, _parentState);
                                PushNewRecursionContext(_localctx, _startState, RULE_exp);
                                State = 71;
                                if (!(Precpred(Context, 6)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 6)");
                                }
                                State = 72;
                                _la   = TokenStream.LA(1);
                                if (!(_la == Plus || _la == Minus))
                                {
                                    ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 73; exp(7);
                            }
                            break;
                            }
                        }
                    }
                    State = 78;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 8, Context);
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            UnrollRecursionContexts(_parentctx);
        }
        return(_localctx);
    }