예제 #1
0
        /// <summary>
        /// �ж��û��Ƿ�����һ���Ĺ���(����ʵ�ʹ���
        /// </summary>
        /// <param name="ruleExpression">����</param>
        /// <returns></returns>
        public static bool AuthorizeByRule(string ruleExpression, System.Security.Principal.IPrincipal principal = null)
        {
            if (string.IsNullOrEmpty(ruleExpression))
            {
                return false;
            }
            if (principal == null)
            {
                principal = System.Threading.Thread.CurrentPrincipal;
            }
            //if (m_isDevelopers)
            //    return true;
            string key = "Authority.AuthorizeByRule:" + ruleExpression;
            return Cache.TryGetCache<bool>(key, new Func<bool>(delegate()
                {
                    if (ruleExpression.ToUpper() == "TRUE")
                        return true;
                    if (ruleExpression.ToUpper() == "FALSE")
                        return false;
                    ruleExpression = ruleExpression.Replace("or", "OR").Replace("and", "AND").Replace("not", "NOT");
                    Parser parser = new Parser();
                    BooleanExpression booleanExpression = parser.Parse(ruleExpression);
                    if (booleanExpression == null)
                    {
                        throw new InvalidOperationException("Invalid rule format " + ruleExpression);
                    }

                    bool result = booleanExpression.Evaluate(principal);
                    return result;
                }));
        }
		private BooleanExpression GetParsedExpression(string ruleName)
		{
			IAuthorizationRule rule = null;
			authorizationRules.TryGetValue(ruleName, out rule);
			if (rule == null) return null;

			string expression = rule.Expression;
			Parser parser = new Parser();

			return parser.Parse(expression);
		}
 /// <summary>
 /// 
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="propertyInfo"></param>
 /// <param name="errors"></param>
 protected override void ValidateCore(object instance, PropertyInfo propertyInfo, IList<ValidationError> errors)
 {
     string expression = (string)propertyInfo.GetValue(instance, null);
     if (expression != null
         && expression.Length != 0)
     {
         try
         {
             Parser parser = new Parser();
             parser.Parse(expression);
         }
         catch (SyntaxException e)
         {
             errors.Add(new ValidationError(instance, propertyInfo.Name, e.Message));
         }
     }
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="ExpressionTextBox"/> class.
 /// </summary>
 public ExpressionTextBox()
     : base()
 {
     parser = new Parser();
 }
        private BooleanExpression Parse()
        {
            parser = new Parser();
            try
            {
                return parser.Parse(this.expressionTextBox.Text);
            }
            catch (SyntaxException ex)
            {
				MessageBoxOptions options = (MessageBoxOptions)0;

				if (RightToLeft == RightToLeft.Yes)
				{
					options = MessageBoxOptions.RtlReading |
					   MessageBoxOptions.RightAlign;
				}

                MessageBox.Show(
                    string.Format(CultureInfo.CurrentCulture, Resources.ParseFailedMessage, ex.Message),
                    Resources.ParseFailedCaption,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
					MessageBoxDefaultButton.Button1,
					options);
                return null;
            }
        }