Example #1
0
        public void Begin( string status, IDictionary<string, string> headers )
        {
            var builder = new DelimitedBuilder("\r\n");
            var headerBuilder = new HeaderBuilder( headers );

            builder.AppendFormat( "HTTP/1.1 {0}", status );

            headers.ForEach( x => builder.AppendFormat( "{0}: {1}", x.Key, x.Value ) );
            builder.Append( "\r\n" );
            var header = builder.ToString();
            var headerBuffer = Encoding.UTF8.GetBytes( header );
			PendingWrite.Reset();
            OnNext( new ArraySegment<byte>(headerBuffer), () => PendingWrite.Set() );
        }
Example #2
0
        private static void ProcessSimpleBinaryExpression( Expression expr, string prefix, DelimitedBuilder builder,
                                                           string token )
        {
            var binaryExpr = expr as BinaryExpression;
            if ( binaryExpr.NodeType == ExpressionType.AndAlso || binaryExpr.NodeType == ExpressionType.OrElse )
                builder.Append( "(" );

            Process( binaryExpr.Left, prefix, builder );
            builder.Append( token );
            Process( binaryExpr.Right, prefix, builder );

            if ( binaryExpr.NodeType == ExpressionType.AndAlso || binaryExpr.NodeType == ExpressionType.OrElse )
                builder.Append( ")" );
        }
Example #3
0
 private static void ProcessConstant( Expression expr, string prefix, DelimitedBuilder builder )
 {
     var constantExpr = expr as ConstantExpression;
     builder.Append( HandleFormatting( constantExpr.Value ) );
 }
Example #4
0
        private static void ProcessCall( Expression expr, string prefix, DelimitedBuilder builder )
        {
            var call = expr as MethodCallExpression;
            var name = call.Method.Name;

            if ( ConstantExpected( builder ) )
            {
                var constValue = Expression.Lambda( expr ).Compile().DynamicInvoke();
                builder.Append( HandleFormatting( constValue ) );
            }
            else
            {
                switch( name )
                {
                    case "StartsWith":
                        Process( call.Object, prefix, builder );
                        builder.Append( ":" );
                        call.Arguments.ForEach( x => Process( x, prefix, builder ) );
                        builder.Append( "*" );
                        break;
                    case "EndsWith":
                        Process( call.Object, prefix, builder );
                        builder.Append( ":" );
                        builder.Append( "*" );
                        call.Arguments.ForEach( x => Process( x, prefix, builder ) );
                        break;
                    case "Contains":
                        Process( call.Object, prefix, builder );
                        builder.Append( ":" );
                        builder.Append( "*" );
                        call.Arguments.ForEach( x => Process( x, prefix, builder ) );
                        builder.Append( "*" );
                        break;
                    case "Any":
                        var memberName = GetMemberName( call.Arguments.First() as MemberExpression );
                        var newPrefix = string.IsNullOrEmpty( prefix )
                                            ? memberName
                                            : "{0}.{1}".AsFormat( prefix, memberName );
                        call.Arguments.Skip( 1 ).ForEach( x => { Process( x, newPrefix, builder ); } );
                        break;
                    default:
                        call.Arguments.ForEach( x => Process( x, prefix, builder ) );
                        break;
                }
            }
        }
Example #5
0
 private static void ProcessLessThanEqualTo( Expression expr, string prefix, DelimitedBuilder builder )
 {
     var binaryExpr = expr as BinaryExpression;
     Process( binaryExpr.Left, prefix, builder );
     builder.Append( ":[* TO " );
     Process( binaryExpr.Right, prefix, builder );
     builder.Append( "]" );
 }
Example #6
0
 private static void ProcessGreaterThan( Expression expr, string prefix, DelimitedBuilder builder )
 {
     var binaryExpr = expr as BinaryExpression;
     Process( binaryExpr.Left, prefix, builder );
     builder.Append( ":{" );
     Process( binaryExpr.Right, prefix, builder );
     builder.Append( " TO *}" );
 }
Example #7
0
        private static void ProcessParameter( Expression expr, string prefix, DelimitedBuilder builder )
        {
            var parameterExpr = expr as ParameterExpression;

            if ( parameterExpr.Name.Length > 1 )
            {
                var paramValue = Expression.Lambda( parameterExpr ).Compile().DynamicInvoke();
                builder.Append( HandleFormatting( paramValue ) );
            }
        }
Example #8
0
 private static void ProcessMemberAccess( Expression expr, string prefix, DelimitedBuilder builder )
 {
     var symbols = new[] {"{", "TO ", ":", "[", @"\+", @"\-", @"\\", @"\*"};
     var memberExpr = expr as MemberExpression;
     var temp = builder.ToString();
     var last = new string( temp.Skip( temp.Length - 3 ).Take( 3 ).ToArray() );
     if ( ConstantExpected( builder ) )
     {
         var memberValue = Expression.Lambda( expr ).Compile().DynamicInvoke();
         builder.Append( HandleFormatting( memberValue ) );
     }
     else
     {
         var memberName = GetMemberName( memberExpr );
         var value = string.IsNullOrEmpty( prefix )
                         ? memberName
                         : "{0}.{1}".AsFormat( prefix, memberName );
         builder.Append( value );
     }
 }