public Task <T> CreateTask <T>(ICommand command, ICommandResponseParser <T> parser)
            where T : Response
        //where T : CommandResponse
        {
            HttpWebRequest request = _builder.Build();

            return(TaskHelper.CreatePostWebRequestTask(request, () => _builder.GetData(command), parser));
        }
 /// <summary>
 /// Creates a new reactive processing service provider using the specified connection object.
 /// </summary>
 /// <param name="connection">The reactive processing service connection.</param>
 /// <param name="commandTextFactory">The command text factory.</param>
 /// <param name="commandResponseParser">The command response parser.</param>
 public ReactiveServiceProvider(
     IReactiveServiceConnection connection,
     ICommandTextFactory <TExpression> commandTextFactory,
     ICommandResponseParser commandResponseParser)
 {
     Connection             = connection;
     _commandTextFactory    = commandTextFactory;
     _commandResponseParser = commandResponseParser;
     Provider = new MetadataQueryProvider(this);
 }
        public T Process <T>(ICommand command, ICommandResponseParser <T> parser)
            where T : Response
        {
            HttpWebRequest request = _builder.Build();

            Task <T> task = TaskHelper.CreatePostWebRequestTask(request, () => _builder.GetData(command), parser);

            return(task.Result);


            //var response = Encoding.ASCII.GetString(task.Result);

            //Console.WriteLine(response);
        }
        public static Task <T> CreatePostWebRequestTask <T>(HttpWebRequest request, Func <byte[]> dataGetter,
                                                            ICommandResponseParser <T> commandResponseParser)
        //where T  : Task<CommandResponse>, new()
            where T : Response
        {
            Task <byte[]> task = CreatePostWebRequestTask(request, dataGetter);

            try
            {
                task.Wait();
            }
            catch (AggregateException e)
            {
                var awse = e.InnerException as AwsSesException;

                if (awse != null)
                {
                    Console.WriteLine("Code : " + awse.ErrorResponse.Code);
                    Console.WriteLine("RequestID : " + awse.ErrorResponse.RequestID);
                    Console.WriteLine("Type : " + awse.ErrorResponse.Type);
                }
                throw;
            }


            //if(task.Exception != null)
            //{
            //    return new Task<T>(()=> new T{ Exception = task.Exception});
            //}

            using (var debug = new StreamReader(new MemoryStream(task.Result)))
            {
                Console.WriteLine(debug.ReadToEnd());
            }

            return(Task <T> .Factory.StartNew(() =>
            {
                using (var stream = new MemoryStream(task.Result))
                {
                    return commandResponseParser.Process(stream);
                }
            }));
        }