예제 #1
0
            public override IWebResults CallMethod(IWebConnection webConnection, IWebHandlerPlugin webHandlerPlugin)
            {
                object[] arguments = new object[NumParameters];

                // Decode the arguments
                foreach (MimeReader.Part mimePart in webConnection.MimeReader)
                    if (ParameterIndexes.ContainsKey(mimePart.Name))
                    {
                        uint parameterIndex = ParameterIndexes[mimePart.Name];
                        arguments[parameterIndex] = mimePart;
                    }

                // The first argument is always the web connection
                arguments[0] = webConnection;

                object toReturn;

                try
                {
                    toReturn = MethodInfo.Invoke(webHandlerPlugin, arguments);
                }
                catch (TargetInvocationException e)
                {
                    // Invoke wraps exceptions
                    throw e.InnerException;
                }

                return (IWebResults)toReturn;
            }
예제 #2
0
            public override IWebResults CallMethod(IWebConnection webConnection, IWebHandlerPlugin webHandlerPlugin)
            {
                object toReturn;

                try
                {
                    toReturn = MethodInfo.Invoke(webHandlerPlugin, new object[] { webConnection });
                }
                catch (TargetInvocationException e)
                {
                    // Invoke wraps exceptions
                    throw e.InnerException;
                }

                return (IWebResults)toReturn;
            }
예제 #3
0
파일: POST.cs 프로젝트: GWBasic/ObjectCloud
            public override IWebResults CallMethod(IWebConnection webConnection, IWebHandlerPlugin webHandlerPlugin)
            {
                if (null == webConnection.Content)
                    return WebResults.From(Status._400_Bad_Request, "No data sent");

                object toReturn;

                try
                {
                    toReturn = MethodInfo.Invoke(webHandlerPlugin, new object[] { webConnection, GetSecondArgument(webConnection.Content) });
                }
                catch (TargetInvocationException e)
                {
                    // Invoke wraps exceptions
                    throw e.InnerException;
                }

                return (IWebResults)toReturn;
            }
예제 #4
0
 public DelegateWrapper(WebCallableMethod webCallableMethod, IWebHandlerPlugin webHandlerPlugin)
 {
     WebCallableMethod = webCallableMethod;
     FileContainer = webHandlerPlugin.FileContainer;
     WebHandlerPlugin = webHandlerPlugin;
 }
예제 #5
0
 /// <summary>
 /// Calls the method.  The webHandler is the target
 /// </summary>
 /// <param name="webConnection"></param>
 /// <param name="webHandler"></param>
 /// <returns></returns>
 public abstract IWebResults CallMethod(IWebConnection webConnection, IWebHandlerPlugin webHandlerPlugin);
        /// <summary>
        /// Creates a new MethodNameAndContainer for a specfic plugin
        /// </summary>
        /// <param name="methodName"></param>
        /// <param name="fileContainer"></param>
        /// <param name="webHandler"></param>
        /// <returns></returns>
        public static MethodNameAndFileContainer New(string methodName, IFileContainer fileContainer, IWebHandlerPlugin webHandlerPlugin)
        {
            MethodNameAndFileContainer me = new MethodNameAndFileContainer();
            me._MethodName = methodName;
            me._FileContainer = fileContainer;
            me._WebHandlerPlugin = webHandlerPlugin;

            return me;
        }
예제 #7
0
 public override IWebResults CallMethod(IWebConnection webConnection, IWebHandlerPlugin webHandlerPlugin)
 {
     return base.CallMethod(webConnection, webHandlerPlugin, webConnection.PostParameters);
 }
예제 #8
0
        protected IWebResults CallMethod(IWebConnection webConnection, IWebHandlerPlugin webHandlerPlugin, IDictionary<string, string> parameters)
        {
            object[] arguments = new object[NumParameters];

            // Decode the arguments
            foreach (KeyValuePair<string, string> parameter in parameters)
                if (ParameterIndexes.ContainsKey(parameter.Key))
                    try
                    {
                        string value = parameter.Value;
                        uint parameterIndex = ParameterIndexes[parameter.Key];

                        if (null != value)
                        {
                            ParameterInfo parameterInfo = Parameters[parameterIndex];
                            Type parameterType = parameterInfo.ParameterType;

                            // Attempt to convert the value to the requested parameter type

                            // JSON types
                            if ((typeof(Dictionary<string, string>) == parameterType)
                                || (typeof(Dictionary<string, object>) == parameterType)
                                || (parameterType.IsGenericType && typeof(Dictionary<,>) == parameterType.GetGenericTypeDefinition()))
                            {
                                JsonReader jsonReader = new JsonReader(value);
                                arguments[parameterIndex] = jsonReader.Deserialize(parameterType);
                            }
                            else if (typeof(JsonReader) == parameterType)
                                arguments[parameterIndex] = new JsonReader(value);

                            else if (typeof(bool) == parameterType || typeof(bool?) == parameterType)
                            {
                                if ("on".Equals(value.ToLower()))
                                    arguments[parameterIndex] = true;
                                else
                                    arguments[parameterIndex] = Convert.ToBoolean(value);
                            }

                            else if ((typeof(DateTime) == parameterType) || (typeof(DateTime?) == parameterType))
                            {
                                if (null != value)
                                    if (value.Length > 0)
                                    {
                                        JsonReader jsonReader = new JsonReader(value);
                                        arguments[parameterIndex] = jsonReader.Deserialize<DateTime>();
                                    }
                            }

                            else if (typeof(Guid) == parameterType || typeof(Guid?) == parameterType)
                                arguments[parameterIndex] = new Guid(value.ToString());

                            // Nullable
                            else if (parameterType.IsGenericType && typeof(Nullable<>) == parameterType.GetGenericTypeDefinition())
                            {
                                if (value.Length > 0)
                                    arguments[parameterIndex] = Convert.ChangeType(value, parameterType.GetGenericArguments()[0]);
                            }

                            // Arrays
                            else if (parameterType.IsArray)
                            {
                                JsonReader jsonReader = new JsonReader(value);
                                arguments[parameterIndex] = jsonReader.Deserialize(parameterType);
                            }

                            // Everything else
                            else
                                arguments[parameterIndex] = Convert.ChangeType(value, parameterType);
                        }
                        else
                            arguments[parameterIndex] = null;
                    }
                    catch (JsonDeserializationException jde)
                    {
                        throw new WebResultsOverrideException(WebResults.From(
                            Status._400_Bad_Request,
                            "Error parsing " + parameter.Key + ", Bad JSON: " + jde.Message));
                    }
                    catch
                    {
                        throw new WebResultsOverrideException(WebResults.From(
                            Status._400_Bad_Request,
                            "Error parsing " + parameter.Key));
                    }

            // The first argument is always the web connection
            arguments[0] = webConnection;

            object toReturn;

            try
            {
                toReturn = MethodInfo.Invoke(webHandlerPlugin, arguments);
            }
            catch (TargetInvocationException e)
            {
                // Invoke wraps exceptions
                throw e.InnerException;
            }

            return (IWebResults)toReturn;
        }