コード例 #1
0
        public ApiRequestObject(ApiRequest request)
        {
            Verb = request.Verb;
            ActionName = request.ActionName;
            Arguments = request.ActionArguments;
            Headers = request.Headers;
            Data = request.Data;

            Respond = delegate(object data, Dictionary<string, object> options) {
                options = Script.Or(options, new Dictionary<string, object>());

                HttpStatusCode statusCode = Script.Or((HttpStatusCode)options["statusCode"],
                                                      (data == null) ? HttpStatusCode.NoContent : HttpStatusCode.OK);

                ServerResponse response = new ServerResponse(statusCode);

                if (data != null) {
                    if (data is string) {
                        response.AddTextContent((string)data, Script.Or((string)options["contentType"], "text/plain"));
                    }
                    else {
                        response.AddObjectContent(data);
                    }
                }

                return Deferred.Create<ServerResponse>(response).Task;
            };
        }
コード例 #2
0
ファイル: ServerResponse.cs プロジェクト: nikhilk/simplecloud
        public static ServerResponse CreateRequestError(string message)
        {
            ServerResponse response = new ServerResponse(HttpStatusCode.BadRequest);

            Dictionary<string, object> error = new Dictionary<string, object>();
            error["message"] = message;

            return response.AddObjectContent(error);
        }
コード例 #3
0
ファイル: ServerResponse.cs プロジェクト: nikhilk/simplecloud
        public static ServerResponse CreateServerError(string message)
        {
            ServerResponse response = new ServerResponse(HttpStatusCode.InternalServerError);

            if (String.IsNullOrEmpty(message) == false) {
                Dictionary<string, object> error = new Dictionary<string, object>();
                error["message"] = message;

                response.AddObjectContent(error);
            }

            return response;
        }