当前位置: 首页>>代码示例>>C#>>正文


C# RestVerbs.Add方法代码示例

本文整理汇总了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."}
                   	};
        }
开发者ID:Ijwu,项目名称:TShock,代码行数:45,代码来源:Rest.cs

示例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." } };
        }
开发者ID:vharonftw,项目名称:TShock,代码行数:31,代码来源:Rest.cs

示例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.",
            };
        }
开发者ID:bladecoding,项目名称:HostScanner,代码行数:50,代码来源:RestServer.cs


注:本文中的RestVerbs.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。