本文整理汇总了C#中RestVerbs.Add方法的典型用法代码示例。如果您正苦于以下问题:C# RestVerbs.Add方法的具体用法?C# RestVerbs.Add怎么用?C# RestVerbs.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestVerbs
的用法示例。
在下文中一共展示了RestVerbs.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
protected virtual object ProcessRequest(object sender, RequestEventArgs e)
{
try
{
var uri = e.Request.Uri.AbsolutePath;
uri = uri.TrimEnd('/');
foreach (var com in commands)
{
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;
for (int i = 0; i < com.UriVerbs.Length; i++)
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
}
else if (com.UriTemplate.ToLower() != uri.ToLower())
{
continue;
}
var obj = ExecuteCommand(com, verbs, e.Request.Parameters, e.Request);
if (obj != null)
return obj;
}
}
catch (Exception exception)
{
return new RestObject("500")
{
{"error", "Internal server error."},
{"errormsg", exception.Message},
{"stacktrace", exception.StackTrace},
};
}
return new RestObject("404")
{
{"error", "Specified API endpoint doesn't exist. Refer to the documentation for a list of valid endpoints."}
};
}
示例2: ProcessRequest
protected virtual object ProcessRequest(object sender, RequestEventArgs e)
{
var uri = e.Request.Uri.AbsolutePath;
uri = uri.TrimEnd('/');
foreach (var com in commands)
{
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;
for (int i = 0; i < com.UriVerbs.Length; i++)
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
}
else if (com.UriTemplate.ToLower() != uri.ToLower())
{
continue;
}
var obj = ExecuteCommand(com, verbs, e.Request.Parameters);
if (obj != null)
return obj;
}
return new Dictionary<string, string> { { "status", "404" }, { "error", "Specified API endpoint doesn't exist. Refer to the documentation for a list of valid endpoints." } };
}
示例3: ProcessRequest
protected virtual object ProcessRequest(object sender, HttpListenerContext e)
{
try
{
var uri = e.Request.Url.AbsolutePath;
uri = uri.TrimEnd('/');
foreach (var com in commands)
{
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;
for (int i = 0; i < com.UriVerbs.Length; i++)
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
}
else if (com.UriTemplate.ToLower() != uri.ToLower())
{
continue;
}
var nvc = new NameValueCollection();
CopyCollection(e.Request.QueryString, nvc);
CopyCollection(GetFormData(e), nvc);
//This overwrites get collisions with post data.
var obj = ExecuteCommand(com, verbs, nvc);
if (obj != null)
return obj;
}
}
catch (Exception exception)
{
var eobj = new RestObject(500)
{
Error = exception.Message
};
eobj["stacktrace"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(exception.StackTrace));
return eobj;
}
return new RestObject(404)
{
Error = "Specified API endpoint doesn't exist. Refer to the documentation for a list of valid endpoints.",
};
}