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


C# HttpListenerContext.JsonResponse方法代码示例

本文整理汇总了C#中System.Net.HttpListenerContext.JsonResponse方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerContext.JsonResponse方法的具体用法?C# HttpListenerContext.JsonResponse怎么用?C# HttpListenerContext.JsonResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.HttpListenerContext的用法示例。


在下文中一共展示了HttpListenerContext.JsonResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TakePhoto

        public bool TakePhoto(WebServer server, HttpListenerContext context)
        {
            try
            {
                if (IsRunningOnMono())
                {
                    var process = Process.Start("raspistill",
                        "-o /home/pi/target/ui/" + DateTime.Now.ToString("yyyMMdd-HHmm") + ".jpg");

                    process.WaitForExit();
                }
                else
                {
                    var filename = Path.Combine(photodir, DateTime.Now.ToString("yyyMMdd-HHmm") + ".jpg");

                    (new WebClient()).DownloadFile("http://unosquare.github.io/assets/embedio.png", filename);
                }

                var dir = new DirectoryInfo(photodir);
                var files = dir.GetFiles("*.jpg").Select(x => x.Name).Take(10);

                return context.JsonResponse(files);
            }
            catch (Exception ex)
            {
                return HandleError(context, ex);
            }
        }
开发者ID:unosquare,项目名称:unolabs-pi,代码行数:28,代码来源:WebApiController.cs

示例2: HandleError

            protected bool HandleError(HttpListenerContext context, Exception ex, int statusCode = 500) {
                var errorResponse = new {
                    Title = "Unexpected Error",
                    ErrorCode = ex.GetType().Name,
                    Description = ex.ExceptionMessage(),
                };

                context.Response.StatusCode = statusCode;
                return context.JsonResponse(errorResponse);
            }
开发者ID:gro-ove,项目名称:actools,代码行数:10,代码来源:PlayerStatsWebServer.cs

示例3: GetHosts

        public bool GetHosts(WebServer server, HttpListenerContext context)
        {
            try
            {
                var data = LocalCdn.HostEntries;

                return context.JsonResponse(data);
            }
            catch (Exception ex)
            {
                return HandleError(context, ex);
            }
        }
开发者ID:geoperez,项目名称:localcdn,代码行数:13,代码来源:ApiController.cs

示例4: Get

        public bool Get(WebServer server, HttpListenerContext context)
        {
            try
            {
                var data = EntryRepository.GetAll();

                var lastSegment = context.Request.Url.Segments.Last();

                if (lastSegment.EndsWith("/"))
                    return context.JsonResponse(data.Select(x => x.Name));

                if (data.Any(p => p.Name == lastSegment))
                {
                    return context.JsonResponse(data.FirstOrDefault(p => p.Name == lastSegment));
                }

                throw new KeyNotFoundException("Key Not Found: " + lastSegment);
            }
            catch (Exception ex)
            {
                return HandleError(context, ex);
            }
        }
开发者ID:geoperez,项目名称:localcdn,代码行数:23,代码来源:ApiController.cs

示例5: GetPhotos

        public bool GetPhotos(WebServer server, HttpListenerContext context)
        {
            try
            {
                var dir = new DirectoryInfo(photodir);
                var files = dir.GetFiles("*.jpg").Select(x => x.Name).Take(10);

                return context.JsonResponse(files);
            }
            catch (Exception ex)
            {
                return HandleError(context, ex);
            }
        }
开发者ID:unosquare,项目名称:unolabs-pi,代码行数:14,代码来源:WebApiController.cs

示例6: GetPeople

        public bool GetPeople(WebServer server, HttpListenerContext context)
        {
            try
            {
                var model = context.ParseJson<GridDataRequest>();

                return context.JsonResponse(model.CreateGridDataResponse(People.AsQueryable()));
            }
            catch (Exception ex)
            {
                // here the error handler will respond with a generic 500 HTTP code a JSON-encoded object
                // with error info. You will need to handle HTTP status codes correctly depending on the situation.
                // For example, for keys that are not found, ou will need to respond with a 404 status code.
                return HandleError(context, ex);
            }
        }
开发者ID:Vic30,项目名称:tubular,代码行数:16,代码来源:PeopleController.cs

示例7: GetPeople

            public bool GetPeople(WebServer server, HttpListenerContext context)
            {
                try
                {
                    // read the last segment
                    var lastSegment = context.Request.Url.Segments.Last();

                    // if it ends with a / means we need to list people
                    if (lastSegment.EndsWith("/"))
                        return context.JsonResponse(RestApiSample.People);

                    // otherwise, we need to parse the key and respond with the entity accordingly
                    int key = 0;
                    if (int.TryParse(lastSegment, out key) && People.Any(p => p.Key == key))
                    {
                        return context.JsonResponse(People.FirstOrDefault(p => p.Key == key));
                    }

                    throw new KeyNotFoundException("Key Not Found: " + lastSegment);
                }
                catch (Exception ex)
                {
                    // here the error handler will respond with a generic 500 HTTP code a JSON-encoded object
                    // with error info. You will need to handle HTTP status codes correctly depending on the situation.
                    // For example, for keys that are not found, ou will need to respond with a 404 status code.
                    return HandleError(context, ex, (int) HttpStatusCode.InternalServerError);
                }
            }
开发者ID:ngdadu,项目名称:embedio,代码行数:28,代码来源:RestApiSample.cs

示例8: ButtonIo

        public async Task<bool> ButtonIo(WebServer server, HttpListenerContext context)
        {
            var lastSegment = context.Request.Url.Segments.Last();
            var bcmPinNumber = int.Parse(lastSegment);

            return context.JsonResponse(new
            {
                count = ButtonCheck[bcmPinNumber]
            });
        }
开发者ID:unosquare,项目名称:unolabs-pi,代码行数:10,代码来源:WebApiController.cs


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