Exemplo n.º 1
0
        public virtual void ProcessRequest(HttpContext httpContext)
        {
            try
            {
                var context = new RushContext(httpContext);
                //authorizer.Authorize(context);

                if (String.IsNullOrWhiteSpace(context.Controller) == false)
                {
                    var controllerType = this.GetType().Assembly.GetTypes().FirstOrDefault(t => t.Name.ToLower() == context.Controller.ToLower());
                    if (controllerType != null)
                    {
                        var controller = (IRushController)RushIoC.Resolve(controllerType);     //Activator.CreateInstance(controllerType, new object[] { context });
                        if (controller != null)
                        {
                            switch (context.Verb)
                            {
                            case HttpVerb.POST:
                                controller.Post();
                                return;

                            case HttpVerb.GET:
                                controller.Get();
                                return;

                            case HttpVerb.PUT:
                                controller.Put();
                                return;

                            case HttpVerb.DELETE:
                                controller.Delete();
                                return;

                            default:
                                break;
                            }
                        }
                    }
                }

                httpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
            }
            catch (RushException ex)
            {
                var json = JsonConvert.SerializeObject(new { Error = ex.Message });
                httpContext.Response.StatusCode = (int)ex.StatusCode;
                httpContext.Response.Write(json);
            }
            catch (Exception ex)
            {
                var json = JsonConvert.SerializeObject(new { Error = ex.Message });
                httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                httpContext.Response.Write(json);
            }
        }
Exemplo n.º 2
0
        public void Authorize(RushContext context)
        {
            string applicationId = null;

            context.Headers.TryGetValue("X-Rush-Application-Id", out applicationId);

            string applicationKey = null;

            context.Headers.TryGetValue("X-Rush-Application-Key", out applicationKey);

            if (String.IsNullOrWhiteSpace(applicationId) || String.IsNullOrWhiteSpace(applicationKey))
            {
                throw new RushException(HttpStatusCode.Unauthorized, "unknown application");
            }

            //TODO: Validate Application Id and Key
        }
Exemplo n.º 3
0
 public RushController(RushContext context)
 {
     this.Context = context;
 }