Exemple #1
0
        public static async Task <TResult> LoadRequestFromNetworkFlow <TRequest, THttpRequest, THttpResult, TResult>(
            TRequest request,
            IRestApiCallTasks <TRequest, THttpRequest, THttpResult, TResult> stages,
            CancellationToken cancelToken)
            where TRequest : class
            where THttpRequest : class
            where THttpResult : class
            where TResult : class
        {
            THttpResult serverResponse = null;
            TResult     parsedData     = null;

            serverResponse = await RestApiCallFlow.LoadResourceFromNetworkFlow(request, stages, cancelToken);

            Func <Exception, ParserException> parseExceptionWrapper = (Exception ex) => new ParserException(TaskFlowErrorMessages.PARSER_EXCEPTION_MESSAGE, ex);
            Task <TResult> asyncParser = stages.ParseResponseDataAsync(serverResponse, cancelToken);

            parsedData = await RestApiCallFlow.IvokeTaskAndWrapExceptions(asyncParser, parseExceptionWrapper);

            ////

            if (null == parsedData)
            {
                throw new ArgumentNullException(TaskFlowErrorMessages.PARSER_RESULT_NULL_MESSAGE);
            }

            return(parsedData);
        }
Exemple #2
0
        public static async Task <THttpResult> LoadResourceFromNetworkFlow <TRequest, THttpRequest, THttpResult>(
            TRequest request,
            IDownloadApiCallTasks <TRequest, THttpRequest, THttpResult> stages,
            CancellationToken cancelToken)
            where TRequest : class
            where THttpRequest : class
            where THttpResult : class
        {
            THttpRequest requestUrl     = null;
            THttpResult  serverResponse = null;

            if (null == request)
            {
                throw new ArgumentNullException(TaskFlowErrorMessages.USER_REQUEST_NULL_MESSAGE);
            }


            Func <Exception, ProcessUserRequestException> urlExceptionWrapper = (Exception ex) => new ProcessUserRequestException(TaskFlowErrorMessages.BAD_USER_REQUEST_MESSAGE, ex);
            Task <THttpRequest> requsetLoader = stages.BuildRequestUrlForRequestAsync(request, cancelToken);

            requestUrl = await RestApiCallFlow.IvokeTaskAndWrapExceptions(requsetLoader, urlExceptionWrapper);

            ////


            if (null == requestUrl)
            {
                throw new ArgumentNullException(TaskFlowErrorMessages.HTTP_REQUEST_NULL_MESSAGE);
            }

            Func <Exception, LoadDataFromNetworkException> httpExceptionWrapper = (Exception ex) =>
            {
                return(new LoadDataFromNetworkException(TaskFlowErrorMessages.NETWORK_EXCEPTION_MESSAGE, ex));
            };
            Task <THttpResult> httpLoader = stages.SendRequestForUrlAsync(requestUrl, cancelToken);

            serverResponse = await RestApiCallFlow.IvokeTaskAndWrapExceptions(httpLoader, httpExceptionWrapper);

            ////


            if (null == serverResponse)
            {
                throw new ArgumentNullException(TaskFlowErrorMessages.SERVER_RESPONSE_NULL_MESSAGE);
            }

            return(serverResponse);
        }