forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fitzchak Yitzchak
committed
Dec 14, 2011
1 parent
0c034f1
commit ae7a1dc
Showing
4 changed files
with
102 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Raven.Studio.Models; | ||
|
||
namespace Raven.Studio.Infrastructure | ||
{ | ||
public class UrlParser | ||
{ | ||
private readonly string url; | ||
private string Url | ||
{ | ||
get { return url; } | ||
} | ||
|
||
private Dictionary<string, string> queryParams; | ||
|
||
public UrlParser(string url) | ||
{ | ||
this.url = url; | ||
} | ||
|
||
public Dictionary<string, string> QueryParams | ||
{ | ||
get | ||
{ | ||
if (queryParams == null) | ||
{ | ||
queryParams = new Dictionary<string, string>(); | ||
var indexOf = Url.IndexOf('?'); | ||
if (indexOf == -1) | ||
return queryParams; | ||
|
||
var options = Url.Substring(indexOf + 1).Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries); | ||
foreach (var option in options) | ||
{ | ||
var param = option.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); | ||
queryParams.Add(param[0], param[1]); | ||
} | ||
} | ||
return queryParams; | ||
} | ||
} | ||
|
||
private string path; | ||
public string Path | ||
{ | ||
get | ||
{ | ||
if (path == null) | ||
{ | ||
var indexOf = Url.IndexOf('?'); | ||
path = indexOf != -1 ? Url.Substring(0, indexOf) : Url; | ||
} | ||
return path; | ||
} | ||
} | ||
|
||
public string GetQueryParam(string name) | ||
{ | ||
if (QueryParams.ContainsKey(name)) | ||
return QueryParams[name]; | ||
return null; | ||
} | ||
|
||
public void SetQueryParam(string name, object value) | ||
{ | ||
if (value == null) return; | ||
QueryParams[name] = value.ToString(); | ||
} | ||
|
||
public bool RemoveQueryParam(string name) | ||
{ | ||
return QueryParams.Remove(name); | ||
} | ||
|
||
public string BuildUrl() | ||
{ | ||
EnsureDatabaseParameterIncluded(); | ||
|
||
var uri = Path; | ||
if (string.IsNullOrWhiteSpace(uri)) | ||
uri = "/home"; | ||
var query = string.Join("&", QueryParams.Select(x => string.Format("{0}={1}", x.Key, x.Value))); | ||
if (string.IsNullOrEmpty(query) == false) | ||
{ | ||
uri += "?" + query; | ||
} | ||
return uri; | ||
} | ||
|
||
private void EnsureDatabaseParameterIncluded() | ||
{ | ||
if (GetQueryParam("database") != null) | ||
return; | ||
|
||
SetQueryParam("database", ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name); | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Raven.Studio.Models; | ||
|
||
namespace Raven.Studio.Infrastructure | ||
{ | ||
public class UrlParser | ||
{ | ||
private readonly string url; | ||
private string Url | ||
{ | ||
get { return url; } | ||
} | ||
|
||
private Dictionary<string, string> queryParams; | ||
|
||
public UrlParser(string url) | ||
{ | ||
this.url = url; | ||
} | ||
|
||
public Dictionary<string, string> QueryParams | ||
{ | ||
get | ||
{ | ||
if (queryParams == null) | ||
{ | ||
queryParams = new Dictionary<string, string>(); | ||
var indexOf = Url.IndexOf('?'); | ||
if (indexOf == -1) | ||
return queryParams; | ||
|
||
var options = Url.Substring(indexOf + 1).Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries); | ||
foreach (var option in options) | ||
{ | ||
var param = option.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); | ||
queryParams.Add(param[0], param[1]); | ||
} | ||
} | ||
return queryParams; | ||
} | ||
} | ||
|
||
private string path; | ||
public string Path | ||
{ | ||
get | ||
{ | ||
if (path == null) | ||
{ | ||
var indexOf = Url.IndexOf('?'); | ||
path = indexOf != -1 ? Url.Substring(0, indexOf) : Url; | ||
} | ||
return path; | ||
} | ||
} | ||
|
||
public string GetQueryParam(string name) | ||
{ | ||
if (QueryParams.ContainsKey(name)) | ||
return QueryParams[name]; | ||
return null; | ||
} | ||
|
||
public void SetQueryParam(string name, object value) | ||
{ | ||
if (value == null) return; | ||
QueryParams[name] = value.ToString(); | ||
} | ||
|
||
public bool RemoveQueryParam(string name) | ||
{ | ||
return QueryParams.Remove(name); | ||
} | ||
|
||
public string BuildUrl() | ||
{ | ||
EnsureDatabaseParameterIncluded(); | ||
|
||
var uri = Path; | ||
if (string.IsNullOrWhiteSpace(uri)) | ||
uri = "/home"; | ||
var query = string.Join("&", QueryParams.Select(x => string.Format("{0}={1}", x.Key, x.Value))); | ||
if (string.IsNullOrEmpty(query) == false) | ||
{ | ||
uri += "?" + query; | ||
} | ||
return uri; | ||
} | ||
|
||
private void EnsureDatabaseParameterIncluded() | ||
{ | ||
if (GetQueryParam("database") != null) | ||
return; | ||
|
||
SetQueryParam("database", ApplicationModel.Database.Value.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters