Ejemplo n.º 1
0
        /// <summary>
        ///     Requires the incoming HTTP request to match the specified body.
        /// </summary>
        /// <param name="stump">The <see cref="T:Stumps.Stump"/> intercepting incomming HTTP requests.</param>
        /// <param name="buffer">The array of bytes for the body.</param>
        /// <returns>The calling <see cref="T:Stumps.Stump"/>.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="stump"/> is <c>null</c>.</exception>
        public static Stump MatchingBody(this Stump stump, byte[] buffer)
        {
            if (stump == null)
            {
                throw new ArgumentNullException("stump");
            }

            if (buffer != null)
            {
                stump.AddRule(new BodyMatchRule(buffer.Length, CreateMd5Hash(buffer)));
            }

            return stump;
        }
 internal static void ReplaceFilter(this SubscriptionClient subscriptionClient, string filterName, string filterExpression)
 {
     try
     {
         subscriptionClient.RemoveRule(filterName);
     }
     catch (MessagingEntityNotFoundException)
     {
     }
     try
     {
         subscriptionClient.AddRule(filterName, new SqlFilter(filterExpression));
     }
     catch (MessagingEntityAlreadyExistsException)
     {
     }
 }
Ejemplo n.º 3
0
        public static Stump MatchingUrl(this Stump stump, string url)
        {
            if (stump == null)
            {
                throw new ArgumentNullException("stump");
            }

            stump.AddRule(new UrlRule(url));
            return stump;
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Requires the incoming HTTP request to match the specified <see cref="T:Stumps.IStumpRule"/>.
        /// </summary>
        /// <param name="stump">The <see cref="T:Stumps.Stump"/> intercepting incomming HTTP requests.</param>
        /// <param name="rule">The <see cref="T:Stumps.IStumpRule"/> required to match.</param>
        /// <returns>The calling <see cref="T:Stumps.Stump"/>.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="stump"/> is <c>null</c>.</exception>
        public static Stump MatchingRule(this Stump stump, IStumpRule rule)
        {
            if (stump == null)
            {
                throw new ArgumentNullException("stump");
            }

            stump.AddRule(rule);
            return stump;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Requires the incoming HTTP request to match the specified HTTP method.
        /// </summary>
        /// <param name="stump">The <see cref="T:Stumps.Stump"/> intercepting incomming HTTP requests.</param>
        /// <param name="httpMethod">The HTTP method to match.</param>
        /// <returns>The calling <see cref="T:Stumps.Stump"/>.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="stump"/> is <c>null</c>.</exception>
        public static Stump MatchingMethod(this Stump stump, string httpMethod)
        {
            if (stump == null)
            {
                throw new ArgumentNullException("stump");
            }

            stump.AddRule(new HttpMethodRule(httpMethod));
            return stump;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Requires the incoming HTTP request to match the specified header.
        /// </summary>
        /// <param name="stump">The <see cref="T:Stumps.Stump"/> intercepting incomming HTTP requests.</param>
        /// <param name="headerName">The name of the header to match.</param>
        /// <param name="headerValue">The value of the header to match.</param>
        /// <returns>The calling <see cref="T:Stumps.Stump"/>.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="stump"/> is <c>null</c>.</exception>
        public static Stump MatchingHeader(this Stump stump, string headerName, string headerValue)
        {
            if (stump == null)
            {
                throw new ArgumentNullException("stump");
            }

            stump.AddRule(new HeaderRule(headerName, headerValue));
            return stump;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Requires the incoming HTTP request to contain the specified text in the body.
        /// </summary>
        /// <param name="stump">The <see cref="T:Stumps.Stump"/> intercepting incomming HTTP requests.</param>
        /// <param name="text">The text that must be contained within the body.</param>
        /// <returns>The calling <see cref="T:Stumps.Stump"/>.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="stump"/> is <c>null</c>.</exception>
        public static Stump MatchingBodyContaining(this Stump stump, string[] text)
        {
            if (stump == null)
            {
                throw new ArgumentNullException("stump");
            }

            stump.AddRule(new BodyContentRule(text));
            return stump;
        }
Ejemplo n.º 8
0
 public static IValidationOptions AsRequired(this IValidationOptions options)
 {
     return options.AddRule(typeof(RequiredValidationRule<>));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Declares that the <see cref="UserSecurityActor"/> must be in a specific role
 /// </summary>
 /// <param name="securityActor"><see cref="UserSecurityActor"/> to declare it for</param>
 /// <param name="role">Role</param>
 /// <returns><see cref="UserSecurityActor"/> to continue the chain with</returns>
 public static UserSecurityActor MustBeInRole(this UserSecurityActor securityActor, string role)
 {
     securityActor.AddRule(new RoleRule(securityActor,role));
     return securityActor;
 }
Ejemplo n.º 10
0
 public static PropertyRuleBuilder IsBetween(this PropertyRuleBuilder rb, object minimum, object maximum)
 {
     rb.AddRule(new RangeRule(rb.Property, minimum, maximum));
       return rb;
 }
Ejemplo n.º 11
0
 public static PropertyRuleBuilder IsValidString(this PropertyRuleBuilder rb, params string[] invalidStrings)
 {
     rb.AddRule(new InvalidStringRule(rb.Property, invalidStrings));
       return rb;
 }
Ejemplo n.º 12
0
 public static PropertyRuleBuilder IsStringLengthBetween(this PropertyRuleBuilder rb, int minLength, int maxLength)
 {
     rb.AddRule(new StringLengthRule(rb.Property, minLength, maxLength));
       return rb;
 }
Ejemplo n.º 13
0
 public static PropertyRuleBuilder IsRequired(this PropertyRuleBuilder rb)
 {
     rb.AddRule(new RequiredRule(rb.Property));
       return rb;
 }
Ejemplo n.º 14
0
 public static PropertyRuleBuilder IsMatchingPattern(this PropertyRuleBuilder rb, string pattern)
 {
     rb.AddRule(new RegexRule(rb.Property, pattern));
       return rb;
 }
Ejemplo n.º 15
0
 public static IValidationOptions AsEmail(this IValidationOptions options)
 {
     return options.AddRule(typeof(EmailValidationRule<>));
 }
Ejemplo n.º 16
0
 public static PropertyRuleBuilder IsConvertable(this PropertyRuleBuilder rb)
 {
     rb.AddRule(new TypeConvertableRule(rb.Property));
       return rb;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// 映射一个路由规则
        /// </summary>
        /// <param name="routeTable">简单路由表实例</param>
        /// <param name="name">路由规则名称</param>
        /// <param name="urlPattern">URL 模式</param>
        /// <param name="routeValues">默认/静态路由值</param>
        /// <param name="queryKeys">可用于 QueryString 的路由值</param>
        /// <returns>返回简单路由表实例,便于链式注册</returns>
        public static SimpleRouteTable MapRoute( this SimpleRouteTable routeTable, string name, string urlPattern, IDictionary<string, string> routeValues, string[] queryKeys = null )
        {
            if ( routeTable == null )
            throw new ArgumentNullException( "routeTable" );

              if ( name == null )
            throw new ArgumentNullException( "name" );

              if ( urlPattern == null )
            throw new ArgumentNullException( "urlPattern" );

              if ( routeValues == null )
            routeValues = new Dictionary<string, string>();

              routeTable.AddRule( name, urlPattern, routeValues, queryKeys );
              return routeTable;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Declares that the <see cref="UserSecurityActor"/> must be in set of specific roles
        /// </summary>
        /// <param name="securityActor"><see cref="UserSecurityActor"/> to declare it for</param>
        /// <param name="roles">Roles to specify</param>
        /// <returns><see cref="UserSecurityActor"/> to continue the chain with</returns>
        public static UserSecurityActor MustBeInRoles(this UserSecurityActor securityActor, params string[] roles)
        {
            foreach (var role in roles) securityActor.AddRule(new RoleRule(securityActor,role));

            return securityActor;
        }
Ejemplo n.º 19
0
 public static IValidationOptions AsPhoneNumber(this IValidationOptions options)
 {
     return options.AddRule(typeof(PhoneNumberValidationRule<>));
 }