private static IRequestDispatcher CreateDefaultRequestDispatcher(ClientTypeMapper typeMapper, IWebClient webClient = null) { var client = webClient ?? new HttpWebClient(); var serializerFactory = new PomonaJsonSerializerFactory(); return(new RequestDispatcher(typeMapper, client, serializerFactory)); }
public PomonaClient(ClientTypeMapper typeMapper, IRequestDispatcher dispatcher) { if (typeMapper == null) { throw new ArgumentNullException(nameof(typeMapper)); } dispatcher = dispatcher ?? CreateDefaultRequestDispatcher(typeMapper); this.typeMapper = typeMapper; this.dispatcher = dispatcher; Settings = new ClientSettings(); dispatcher.RequestCompleted += (s, e) => RaiseRequestCompleted(e.Request, e.Response, e.ThrownException); }
public static T AddNew <T>(this ICollection <T> collection, Action <T> initAction) where T : IClientResource { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (initAction == null) { throw new ArgumentNullException(nameof(initAction)); } var form = ClientTypeMapper.CreatePostForm <T>(); initAction(form); collection.Add(form); return(form); }
public RequestDispatcher(ClientTypeMapper typeMapper, IWebClient webClient, ITextSerializerFactory serializerFactory, IEnumerable <KeyValuePair <string, IEnumerable <string> > > defaultHeaders = null) { this.defaultHeaders = defaultHeaders; if (typeMapper != null) { this.typeMapper = typeMapper; } if (webClient != null) { WebClient = webClient; } if (serializerFactory != null) { this.serializerFactory = serializerFactory; } }
public PomonaClient(ClientTypeMapper typeMapper, IWebClient webClient) : this(typeMapper, CreateDefaultRequestDispatcher(typeMapper, webClient)) { }
public PomonaClient(ClientTypeMapper typeMapper, HttpClient httpClient) : this(typeMapper, CreateDefaultRequestDispatcher(typeMapper, new HttpWebClient(httpClient))) { }
public PomonaClient(ClientTypeMapper typeMapper) : this(typeMapper, (IRequestDispatcher)null) { }