Ejemplo n.º 1
0
        /// <summary>
        /// Sends a request for a View to the server.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type" /> T of the body for each row result.</typeparam>
        /// <param name="query">The <see cref="IViewQuery" /> representing the query.</param>
        /// <returns>
        /// An <see cref="IViewResult{T}" /> representing the result of the query.
        /// </returns>
        public IViewResult <T> Send <T>(IViewQueryable query)
        {
            IViewResult <T> result;

            try
            {
                query.BaseUri(CachedViewBaseUri);
                result = query.IsStreaming
                    ? _streamingViewClient.Execute <T>(query)
                    : ViewClient.Execute <T>(query);
            }
            catch (Exception e)
            {
                result = new ViewResult <T>
                {
                    Exception  = e,
                    Message    = e.Message,
                    Error      = e.Message,
                    Success    = false,
                    StatusCode = HttpStatusCode.BadRequest,
                    Rows       = new List <ViewRow <T> >()
                };
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a request for a View to the server asynchronously.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type" /> T of the body for each row result.</typeparam>
        /// <param name="query">The <see cref="IViewQuery" /> representing the query.</param>
        /// <returns>
        /// An <see cref="Task{IViewResult}" /> object representing the asynchronous operation.
        /// </returns>
        public Task <IViewResult <T> > SendAsync <T>(IViewQueryable query)
        {
            Task <IViewResult <T> > result;

            try
            {
                query.BaseUri(CachedViewBaseUri);
                result = query.IsStreaming
                    ? _streamingViewClient.ExecuteAsync <T>(query)
                    : ViewClient.ExecuteAsync <T>(query);
            }
            catch (Exception e)
            {
                var tcs = new TaskCompletionSource <IViewResult <T> >();
                tcs.SetResult(new ViewResult <T>
                {
                    Exception  = e,
                    Message    = e.Message,
                    Error      = e.Message,
                    Success    = false,
                    StatusCode = HttpStatusCode.BadRequest,
                    Rows       = new List <ViewRow <T> >()
                });
                result = tcs.Task;
            }
            return(result);
        }