コード例 #1
0
ファイル: Ballot.cs プロジェクト: zszqwe/MvcBase
        /// <summary>
        /// checking a series conditions
        /// </summary>
        /// <param name="ballotType"></param>
        /// <param name="ballotRelation"></param>
        /// <returns></returns>
        public static bool?Vote(BallotType ballotType, BallotRelation ballotRelation)
        {
            object result = string.Empty;

            return(Vote(ballotType, ballotRelation, null, null, null, out result));
        }
コード例 #2
0
ファイル: Ballot.cs プロジェクト: zszqwe/MvcBase
        /// <summary>
        /// checking a series conditions.
        /// When voters vote for a ballot type, they do not change anything; they only check some conditions. It means
        /// race condition will not arise. Thus, ballot mechanism can be used by multiple threads at the same time,
        /// without mutual exclusion being needed, that is, no lock is needed.
        /// </summary>
        /// <param name="ballotType"></param>
        /// <param name="ballotRelation"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="arg4"></param>
        /// <returns></returns>
        public static bool?Vote(BallotType ballotType, BallotRelation ballotRelation, object arg1, object arg2, object arg3, out object arg4)
        {
            arg4 = string.Empty;

            if (!_checkFuncDic.Keys.Contains <BallotType>(ballotType))
            {
                return(null);
            }
            bool isCheckPass = default(bool);

            switch (ballotRelation)
            {
            case BallotRelation.AND:
                foreach (var item in _checkFuncDic[ballotType])
                {
                    bool?result = item(arg1, arg2, arg3, out arg4);
                    if (!result.HasValue)
                    {
                        continue;
                    }
                    if (!result.Value)
                    {
                        return(false);
                    }
                }
                isCheckPass = true;
                break;

            case BallotRelation.NONE:
                foreach (var item in _checkFuncDic[ballotType])
                {
                    bool?result = item(arg1, arg2, arg3, out arg4);
                    if (!result.HasValue)
                    {
                        continue;
                    }
                    if (result.Value)
                    {
                        return(false);
                    }
                }
                isCheckPass = true;
                break;

            case BallotRelation.OR:
                foreach (var item in _checkFuncDic[ballotType])
                {
                    bool?result = item(arg1, arg2, arg3, out arg4);
                    if (!result.HasValue)
                    {
                        continue;
                    }
                    if (result.Value)
                    {
                        return(true);
                    }
                }
                isCheckPass = false;
                break;
            }

            return(isCheckPass);
        }
コード例 #3
0
ファイル: Ballot.cs プロジェクト: zszqwe/MvcBase
        /// <summary>
        /// checking a series conditions
        /// </summary>
        /// <param name="ballotType"></param>
        /// <param name="ballotRelation"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <returns></returns>
        public static bool?Vote(BallotType ballotType, BallotRelation ballotRelation, object arg1, object arg2, object arg3)
        {
            object result = string.Empty;

            return(Vote(ballotType, ballotRelation, arg1, arg2, arg3, out result));
        }