Exemple #1
0
 public override object GetParamValue(IRequest request, SidModule moduleInstance)
 {
     if (request.Headers.ContainsKey(headerName)) {
         return request.Headers[headerName].FirstOrDefault();
     }
     return null;
 }
Exemple #2
0
 public override object GetParamValue(IRequest request, SidModule moduleInstance)
 {
     var cookie = request.Cookies[cookieName];
     if (cookie == null) {
         return null;
     }
     return cookie.Value;
 }
 /// <summary>
 /// Processes parameters, and uses the BaseParamAttribute-derived members of the
 /// ParmWrapper objects for the EndPointDescriptor to polymorphically extract the 
 /// appropriate values for each argument.
 /// </summary>
 /// <param name="request">IRequest object.</param>
 /// <param name="endPoint">Endpoint desciptor; has the ParmWrapper objects.</param>
 /// <param name="moduleInstance">Module for this endpoint.</param>
 /// <returns>An array of objects, suitable for using with MethodInfo.Invoke.</returns>
 public static object[] GetArguments(IRequest request, IEndPointDescriptor endPoint, 
                              SidModule moduleInstance)
 {
     var args = new object[endPoint.Parameters.Count];
     for (var i = 0; i < args.Length; i++) {
         var parm = endPoint.Parameters[i];
         args[i] = parm.GetParamValue(request, moduleInstance);
     }
     return args;
 }
Exemple #4
0
 public override object GetParamValue(IRequest request, SidModule moduleInstance)
 {
     var match = request.Match;
     if (match == null || !match.Success) {
         throw new Exception(String.Format("FATAL ERROR - Param {0} missing regex " +
             "match for resolving argument", ParameterInfo.Name));
     }
     var value = match.Groups[ParameterInfo.Name].Value;
     return string.IsNullOrEmpty(value) ? null : ParameterInfo.Convert(value);
 }
        /// <summary>
        /// Construct a RestfulResponse from an exception.
        /// </summary>
        /// <param name="ex">Exception to process.</param>
        /// <param name="moduleInstance">Module for the method that had the exception.</param>
        /// <returns></returns>
        static RestfulResponse HandleDispatchException(Exception ex, SidModule moduleInstance)
        {
            var e = ex.InnerException ?? ex;
            HttpStatusCode errorCode;
            if (e is ApiException) {
                errorCode = ((ApiException)e).Code;
            } else if (e is ArgumentException) {
                errorCode = HttpStatusCode.BadRequest;
            } else{
                errorCode = HttpStatusCode.InternalServerError;
            }

            log.Error(e.Message);

            var body = new {
                Message = e.Message,
                StackTrace = e.StackTrace,
            };
            return new RestfulResponse() {
                StatusCode = errorCode,
                Body = JsonConvert.SerializeObject(body),
                Headers = moduleInstance == null ? null : moduleInstance.ResponseHeaders
            };
        }
Exemple #6
0
 public abstract object GetParamValue(IRequest request, SidModule moduleInstance);