Example #1
0
        public Outcome <HttpReply> Send(HttpRequestSpec spec)
        {
            try
            {
                var request  = CreateRequest(spec);
                var response = client.SendAsync(request).Result;

                var descriptor = new HttpReplyStatus
                                 (
                    ProtocolCode: HttpResultCodes.Find((int)response.StatusCode),
                    SystemCode: SystemResultCodes.Success
                                 );

                var data         = response.Content.ReadAsStringAsync().Result;
                var notification = response.IsSuccessStatusCode
                                 ? none <IApplicationMessage>()
                                 : some(HttpStatusMessages.ErrorStatus(descriptor, data));
                return(success(
                           new HttpReply(descriptor, data),
                           notification.ValueOrDefault(ApplicationMessage.Empty)
                           ));
            }
            catch (Exception e)
            {
                return(InterpretError(e, spec));
            }
        }
Example #2
0
        static Outcome <HttpReply> InterpretWebException(WebException we, HttpRequestSpec spec)
        {
            try
            {
                //If we can successfully retrieve an error response, then whatever
                //happened is not considered a systemic failure
                var response = we.Response;
                if (response == null)
                {
                    return(SystemFailed(we, spec));
                }

                using (var stream = response.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var data       = reader.ReadToEnd();
                        var descriptor = new HttpReplyStatus
                                         (
                            ProtocolCode: response.GetHttpStatusCode(),
                            SystemCode: SystemResultCodes.Success
                                         );


                        return(new Outcome <HttpReply>(true, new HttpReply(descriptor, data),
                                                       HttpStatusMessages.ErrorStatus(descriptor, data)));
                    }
            }
            catch (Exception e)
            {
                return(SystemFailed(e, spec));
            }
        }
Example #3
0
 public HttpServiceResponse(HttpReplyStatus ResultDescriptor, TContent Content)
 {
     this.ResultDescriptor = ResultDescriptor;
     this.Content          = Content;
 }
Example #4
0
 public HttpReply(HttpReplyStatus Status, string Data)
 {
     this.Status = Status;
     this.Data   = Data;
 }
Example #5
0
 public HttpStatusDescription(HttpReplyStatus Status, string ErrorResponse)
 {
     this.SystemResult   = Status.SystemCode;
     this.ProtocolResult = Status.ProtocolCode;
     this.ErrorResponse  = ErrorResponse;
 }
Example #6
0
 public HttpResponse(HttpReplyStatus Result)
 {
     this.Result  = Result;
     this.Content = none <C>();
 }
Example #7
0
 public HttpResponse(HttpReplyStatus Result, C Content)
 {
     this.Result  = Result;
     this.Content = Content;
 }
Example #8
0
 public static IApplicationMessage ErrorStatus(HttpReplyStatus Status, string ErrorResponse)
 => ApplicationMessage.Error("System Result:@SystemResult; Protocol Result:@ProtocolResult; @ErrorResponse",
                             new HttpStatusDescription(Status, ErrorResponse));