Ejemplo n.º 1
0
 /// <summary>
 /// A wire that catches exceptions and retries multiple times to send the request.
 /// Throws an exception created from the given funciton if the last attempt fails.
 /// </summary>
 public Retry(int attempts, Func <IDictionary <string, string>, Exception, Exception> exception, IWire origin) : base(request =>
 {
     IDictionary <string, string> response = new Dictionary <string, string>();
     for (int i = 1; i <= attempts; i++)
     {
         try
         {
             response =
                 RuntimeInformation.OSDescription == "Browser"
                 ?
                 origin.Response(request).Result
                 :
                 AsyncContext.Run(() => origin.Response(request));
         }
         catch (Exception ex)
         {
             if (i == attempts)
             {
                 throw exception(request, ex);
             }
         }
     }
     return(Task.FromResult(response));
 })
 { }
Ejemplo n.º 2
0
        /// <summary>
        /// A wire that verifies each response.
        /// </summary>
        public Verified(IWire origin, IVerification verification) : base(request =>
        {
            var response =
                RuntimeInformation.OSDescription == "Browser"
                ?
                origin.Response(request).Result
                :
                AsyncContext.Run(() => origin.Response(request));

            verification.Verify(response);
            return(new TaskFactory().StartNew <IDictionary <string, string> >(() => response));
        })
        { }
Ejemplo n.º 3
0
 /// <summary>
 /// XML data received as a response from the given wire.
 /// </summary>
 public XmlResponse(IWire wire, IDictionary <string, string> request) : base(
         new ScalarOf <IXML>(() =>
                             new XmlBody.Of(
                                 wire.Response(request)
                                 )
                             ),
         live: false
         )
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// A wire that adds extra parts to every request.
 /// </summary>
 public Refined(IWire origin, IEnumerable <IMapInput> requestParts) : base(request =>
                                                                           origin.Response(
                                                                               new Requests.Refined(
                                                                                   request,
                                                                                   requestParts
                                                                                   )
                                                                               )
                                                                           )
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// JSON data received as a response from the given wire.
 /// </summary>
 public JsonResponse(IWire wire, IDictionary <string, string> request) : base(() =>
                                                                              new JsonBody.Of(
                                                                                  wire.Response(request)
                                                                                  )
                                                                              )
 {
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Bytes received as a response from the given wire.
 /// Bytes will be decoded from base 64.
 /// </summary>
 public BytesResponse(IWire wire, IDictionary <string, string> request) : base(() =>
                                                                               new BytesBody.Of(
                                                                                   wire.Response(request)
                                                                                   ).AsBytes()
                                                                               )
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Response from a wire.
 /// </summary>
 public Response(IWire wire, IDictionary <string, string> request) : base(() =>
                                                                          new Synced(wire.Response(request)),
                                                                          live: false
                                                                          )
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Form data received as a response from the given wire.
 /// </summary>
 public FormResponse(IWire wire, IDictionary <string, string> request) : base(() =>
                                                                              new FormParams.Of(
                                                                                  wire.Response(request)
                                                                                  ),
                                                                              live: false
                                                                              )
 {
 }