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() ); }
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( ")" ); }
private static void ProcessConstant( Expression expr, string prefix, DelimitedBuilder builder ) { var constantExpr = expr as ConstantExpression; builder.Append( HandleFormatting( constantExpr.Value ) ); }
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; } } }
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( "]" ); }
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 *}" ); }
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 ) ); } }
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 ); } }