-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPocoClient.cs
More file actions
80 lines (64 loc) · 1.81 KB
/
Copy pathPocoClient.cs
File metadata and controls
80 lines (64 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using PocoHttp.Grammars;
using PocoHttp.Internal;
using PocoHttp.Internal.LinqHelper;
namespace PocoHttp
{
public class PocoClient : IPocoClient
{
private readonly PocoConfiguration _pocoConfiguration;
private readonly HttpClient _httpClient;
public PocoClient() : this(new PocoConfiguration())
{
}
public PocoClient(PocoConfiguration configuration)
{
_pocoConfiguration = configuration;
if (configuration.Handler == null)
_httpClient = new HttpClient();
else
_httpClient = new HttpClient(configuration.Handler, configuration.DisposeHandler);
}
public IQueryable Context(Type entityType, Uri uri)
{
if(BaseAddress == null &&
(uri == null || !uri.IsAbsoluteUri))
throw new InvalidOperationException("BaseAddress is null and uri is null or relative. Set the base address or provide absolute uri.");
var request = new HttpRequestMessage(HttpMethod.Get, uri);
var httpProvider = new HttpProvider(
new HttpQueryContext()
{
EntityType = entityType,
HttpClient = _httpClient,
Configuration = Configuration,
Request = request
}
);
return (IQueryable)Activator.CreateInstance(typeof(Query<>).MakeGenericType(entityType),
new object[] { httpProvider });
}
public IQueryable Context(Type entityType)
{
return Context(entityType,
Configuration.UriBuilder.BuildUri(entityType, Configuration.UsePluralUrls));
}
public Uri BaseAddress
{
get { return _httpClient.BaseAddress; }
set { _httpClient.BaseAddress = value; }
}
public PocoConfiguration Configuration
{
get { return _pocoConfiguration; }
}
public void Dispose()
{
if(_httpClient!=null)
_httpClient.Dispose();
}
}
}