-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathFindOptions.cs
More file actions
73 lines (57 loc) · 2.08 KB
/
FindOptions.cs
File metadata and controls
73 lines (57 loc) · 2.08 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
using System;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
namespace InfluxDB.Client.Domain
{
public class FindOptions
{
public const string LimitKey = "limit";
public const string OffsetKey = "offset";
public const string SortByKey = "sortBy";
public const string DescendingKey = "descending";
public const string AfterKey = "after";
[JsonProperty("limit")] public int? Limit { get; set; }
[JsonProperty("offset")] public int? Offset { get; set; }
[JsonProperty("sortBy")] public string SortBy { get; set; }
[JsonProperty("descending")] public bool? Descending { get; set; }
[JsonProperty("after")] public string After { get; set; }
internal static FindOptions GetFindOptions(string link)
{
var options = new FindOptions();
if (string.IsNullOrEmpty(link))
{
return options;
}
var qs = HttpUtility.ParseQueryString(link.Substring(link.LastIndexOf("?", StringComparison.Ordinal)));
var keys = qs.AllKeys;
if (!keys.Contains(LimitKey) && !keys.Contains(OffsetKey) &&
!keys.Contains(SortByKey) && !keys.Contains(DescendingKey) && !keys.Contains(AfterKey))
{
return null;
}
var findOptions = new FindOptions();
if (keys.Contains(LimitKey))
{
findOptions.Limit = int.Parse(qs.Get(LimitKey));
}
if (keys.Contains(OffsetKey))
{
findOptions.Offset = int.Parse(qs.Get(OffsetKey));
}
if (keys.Contains(SortByKey))
{
findOptions.SortBy = qs.Get(SortByKey);
}
if (keys.Contains(AfterKey))
{
findOptions.After = qs.Get(AfterKey);
}
if (keys.Contains(DescendingKey))
{
findOptions.Descending = bool.Parse(qs.Get(DescendingKey));
}
return findOptions;
}
}
}