TSHOCKPLUGINS-2 #resolve #comment Added.

This commit is contained in:
Lucas Nicodemus 2012-01-03 15:29:36 -07:00
parent 5d61a56fcd
commit 264e633202

View file

@ -128,31 +128,44 @@ namespace Rests
protected virtual object ProcessRequest(object sender, RequestEventArgs e) protected virtual object ProcessRequest(object sender, RequestEventArgs e)
{ {
var uri = e.Request.Uri.AbsolutePath; try
uri = uri.TrimEnd('/');
foreach (var com in commands)
{ {
var verbs = new RestVerbs(); var uri = e.Request.Uri.AbsolutePath;
if (com.HasVerbs) uri = uri.TrimEnd('/');
{
var match = Regex.Match(uri, com.UriVerbMatch);
if (!match.Success)
continue;
if ((match.Groups.Count - 1) != com.UriVerbs.Length)
continue;
for (int i = 0; i < com.UriVerbs.Length; i++) foreach (var com in commands)
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
}
else if (com.UriTemplate.ToLower() != uri.ToLower())
{ {
continue; var verbs = new RestVerbs();
} if (com.HasVerbs)
{
var match = Regex.Match(uri, com.UriVerbMatch);
if (!match.Success)
continue;
if ((match.Groups.Count - 1) != com.UriVerbs.Length)
continue;
var obj = ExecuteCommand(com, verbs, e.Request.Parameters); for (int i = 0; i < com.UriVerbs.Length; i++)
if (obj != null) verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
return obj; }
else if (com.UriTemplate.ToLower() != uri.ToLower())
{
continue;
}
var obj = ExecuteCommand(com, verbs, e.Request.Parameters);
if (obj != null)
return obj;
}
}
catch (Exception exception)
{
return new Dictionary<string, string>
{
{"status", "500"},
{"error", "Internal server error."},
{"errormsg", exception.Message},
{"stacktrace", exception.StackTrace},
};
} }
return new Dictionary<string, string> return new Dictionary<string, string>
{ {