/
RavenUrlExtensions.cs
103 lines (87 loc) · 3.14 KB
/
RavenUrlExtensions.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Browser;
using System.Windows.Browser;
using Raven.Client.Document;
using Raven.Client.Silverlight.Connection.Async;
namespace Raven.Client.Silverlight.Connection
{
public static class RavenUrlExtensions
{
public static string Indexes(this string url, string index)
{
return url + "/indexes/" + index;
}
public static string IndexDefinition(this string url, string index)
{
return url + "/indexes/" + index + "?definition=yes";
}
public static string IndexNames(this string url, int start, int pageSize)
{
return url + "/indexes/?namesOnly=true&start=" + start + "&pageSize=" + pageSize;
}
public static string Stats(this string url)
{
return url + "/stats";
}
public static string Static(this string url, string key)
{
return url + "/static/" + Uri.EscapeUriString(key);
}
public static string Databases(this string url, int pageSize, int start)
{
string databases = url + "/databases/?pageSize=" + pageSize;
if(start > 0)
return databases + "&start=" + start;
return databases;
}
public static string SilverlightEnsuresStartup(this string url)
{
return url + "/silverlight/ensureStartup";
}
public static string Terms(this string url, string index, string field, string fromValue, int pageSize)
{
return url + "/terms/" + index + "?field=" + field + "&fromValue=" + fromValue + "&pageSize=" + pageSize;
}
public static string Docs(this string url, string key)
{
return url + "/docs/" + Uri.EscapeUriString(key);
}
public static string Docs(this string url, int start, int pageSize, bool metadataOnly)
{
var docs = url + "/docs/?start=" + start + "&pageSize=" + pageSize;
if (metadataOnly)
docs += "&metadata-only=true";
return docs;
}
public static string DocsStartingWith(this string url, string prefix, int start, int pageSize, bool metadataOnly)
{
return Docs(url, start, pageSize, metadataOnly) + "&startsWith=" + Uri.EscapeUriString(prefix);
}
public static string Queries(this string url)
{
return url + "/queries/";
}
public static string NoCache(this string url)
{
return (url.Contains("?"))
? url + "&noCache=" + Guid.NewGuid().GetHashCode()
: url + "?noCache=" + Guid.NewGuid().GetHashCode();
}
public static Uri ToUri(this string url)
{
return new Uri(url);
}
public static HttpJsonRequest ToJsonRequest(this string url, AsyncServerClient requestor, ICredentials credentials, Document.DocumentConvention convention)
{
return requestor.JsonRequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(requestor, url, "GET", credentials, convention));
}
public static HttpJsonRequest ToJsonRequest(this string url, AsyncServerClient requestor, ICredentials credentials, DocumentConvention convention, IDictionary<string, string> operationsHeaders, string method)
{
var httpJsonRequest = requestor.JsonRequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(requestor, url, method, credentials, convention));
httpJsonRequest.AddOperationHeaders(operationsHeaders);
return httpJsonRequest;
}
}
}