/// <summary> /// Constructor for a internal proxy's request handler. /// </summary> /// <param name="proxy">Proxy this request handler belongs to.</param> /// <param name="context">The client http context,</param> /// <param name="routines">The routines, mapped to the URL that should trigger them.</param> /// <param name="defaultMethod">The default method.</param> protected InternalRequestHandler(RCProxy proxy, HttpListenerContext context, Dictionary<String, RoutineMethod> routines, RoutineMethod defaultMethod) : base(proxy, context, LOCAL_REQUEST_PACKAGE_DEFAULT_TIMEOUT) { _routines = routines; _defaultMethod = defaultMethod; }
/// <summary> /// Parses the URI Parameters for the given method. /// </summary> /// <param name="method">The method to parse the parameters for.</param> /// <returns>The Parameters as an Object[].</returns> private Object[] GetParameters(RoutineMethod method) { if (method.ParameterNames == null) { // No parameters return null; } Object[] result = new Object[method.ParameterNames.Length]; // Retrieve parameters string parameters = method.GETParameters ? _originalRequest.Url.Query : Encoding.UTF8.GetString(HttpUtils.ReceiveBody(_originalRequest)); // Parse GET or POST parameters NameValueCollection parameterCollection = HttpUtility.ParseQueryString(parameters); for (int i = 0; i < method.ParameterNames.Length; i++) { String parameterName = method.ParameterNames[i]; Type parameterType = method.ParameterTypes[i]; // Convert to required type object value = parameterCollection.Get(parameterName); if(value == null && parameterType.IsPrimitive) { if (parameterType == typeof(bool)) { value = false; } else { value = 0; } } result[i] = Convert.ChangeType(value, parameterType); } return result; }