コード例 #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() );
        }
コード例 #2
0
 private static void DoNothing( Expression expr, string prefix, DelimitedBuilder builder )
 {
     var nodeType = expr.NodeType;
     builder.AppendFormat( "No handler for node type {0}", nodeType.ToString() );
 }
コード例 #3
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( ")" );
        }
コード例 #4
0
 private static void ProcessConstant( Expression expr, string prefix, DelimitedBuilder builder )
 {
     var constantExpr = expr as ConstantExpression;
     builder.Append( HandleFormatting( constantExpr.Value ) );
 }
コード例 #5
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;
                }
            }
        }
コード例 #6
0
 private static void ProcessSubtraction( Expression expr, string prefix, DelimitedBuilder builder )
 {
     ProcessSimpleBinaryExpression( expr, prefix, builder, @"\-" );
 }
コード例 #7
0
 private static void ProcessMultiplication( Expression expr, string prefix, DelimitedBuilder builder )
 {
     ProcessSimpleBinaryExpression( expr, prefix, builder, @"\*" );
 }
コード例 #8
0
 private static void ProcessEquals( Expression expr, string prefix, DelimitedBuilder builder )
 {
     ProcessSimpleBinaryExpression( expr, prefix, builder, ":" );
 }
コード例 #9
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( "]" );
 }
コード例 #10
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 *}" );
 }
コード例 #11
0
 public static void Process( Expression expr, string prefix, DelimitedBuilder builder )
 {
     processors[expr.NodeType]( expr, prefix, builder );
 }
コード例 #12
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 ) );
            }
        }
コード例 #13
0
        private static void ProcessLambda( Expression expr, string prefix, DelimitedBuilder builder )
        {
            var lambda = expr as LambdaExpression;

            Process( lambda.Body, prefix, builder );
        }
コード例 #14
0
 private static bool ConstantExpected( DelimitedBuilder builder )
 {
     var symbols = new[] {"{", "TO ", ":", "[", @"\+", @"\-", @"\\", @"\*"};
     var temp = builder.ToString();
     var last = new string( temp.Skip( temp.Length - 3 ).Take( 3 ).ToArray() );
     return symbols.Any( x => last.EndsWith( x ) );
 }
コード例 #15
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 );
     }
 }