Exemple #1
0
        private static IRequestDispatcher CreateDefaultRequestDispatcher(ClientTypeMapper typeMapper, IWebClient webClient = null)
        {
            var client            = webClient ?? new HttpWebClient();
            var serializerFactory = new PomonaJsonSerializerFactory();

            return(new RequestDispatcher(typeMapper, client, serializerFactory));
        }
Exemple #2
0
        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);
        }
Exemple #4
0
 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;
     }
 }
Exemple #5
0
 public PomonaClient(ClientTypeMapper typeMapper, IWebClient webClient)
     : this(typeMapper, CreateDefaultRequestDispatcher(typeMapper, webClient))
 {
 }
Exemple #6
0
 public PomonaClient(ClientTypeMapper typeMapper, HttpClient httpClient)
     : this(typeMapper, CreateDefaultRequestDispatcher(typeMapper, new HttpWebClient(httpClient)))
 {
 }
Exemple #7
0
 public PomonaClient(ClientTypeMapper typeMapper)
     : this(typeMapper, (IRequestDispatcher)null)
 {
 }