Example #1
0
        public HttpResponse Handle(HttpRequest request)
        {
            this.ParseInput(request);
            //TODO check if there is session with given id and execute the method only if user is authorised

            var        method     = this.GetMethod();
            var        controller = this.GetController();
            IInvocable result     =
                (IInvocable)method
                .Invoke(controller, this.methodParams);

            string content = result.Invoke();
            //var response = new HttpResponse()
            //{
            //    ContentAsUTF8 = content,
            //    StatusCode = ResponseStatusCode.Ok
            //};

            //this.ClearRequestParameters();
            //return response;
            var response = new HttpResponse();

            if (!string.IsNullOrEmpty(result.Location))
            {
                response.StatusCode = ResponseStatusCode.Found;
                response.Header.OtherParameters.Add("Location", result.Location);
            }
            else
            {
                response.StatusCode    = ResponseStatusCode.Ok;
                response.ContentAsUTF8 = content;
            }
            return(response);
        }
        public IHttpResponse Handle(IHttpRequest request)
        {
            this.getParameters  = new Dictionary <string, string>(request.UrlParameters);
            this.postParameters = new Dictionary <string, string>(request.FormData);
            this.requestMethod  = request.Method.ToString().ToUpper();

            bool areControllersAndActionValid = this.RetrieveControllerAndActionNames(request);

            if (!areControllersAndActionValid)
            {
                return(new NotFoundResponse());
            }

            MethodInfo methodInfo = this.RetrieveActionForExecution();

            if (methodInfo == null)
            {
                return(new NotFoundResponse());
            }

            this.RetrieveMethodParameters(methodInfo);

            IInvocable actionResult = (IInvocable)methodInfo.Invoke(this.controllerInstance, this.methodParameters);

            string content = actionResult.Invoke();

            IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content);

            return(response);
        }
Example #3
0
        public IHttpResponse Handle(IHttpRequest request)
        {
            if (request.Path == "/favicon.ico")
            {
                return(null);
            }

            this.getParams     = new Dictionary <string, string>(request.UrlParameters);
            this.postParams    = new Dictionary <string, string>(request.FormData);
            this.requestMethod = request.Method.ToString().ToUpper();
            this.PrepareControllerAndActionNames(request.Path);
            var controller = this.GetController();
            var method     = this.GetMethod();

            if (method == null)
            {
                return(new NotFoundResponse());
            }
            this.PrepareMethodParameters(method);

            IInvocable actionResult = (IInvocable)method.Invoke(controller, this.methodParams);

            string content = actionResult.Invoke();

            IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content);

            return(response);
        }
        /// <summary>
        /// Synchronously invoke the specified task on each of the specified
        /// members.
        /// </summary>
        /// <remarks>
        /// <p>
        /// This method will not return until the specified members have
        /// completed their processing, failed in their processing, or died
        /// trying.</p>
        /// <p>
        /// <b>IMember</b>s that are specified but are not currently running
        /// the <b>IInvocationService</b> will not invoke the specified
        /// <see cref="IInvocable"/> object.</p>
        /// <p>
        /// <b>IMember</b>s that leave (gracefully or otherwise) before the
        /// invocation completes will not register a result, and the amount
        /// of processing that completed is indeterminate. <b>IMember</b>s
        /// that encounter an exception during invocation will not be
        /// retried; whatever result has been registered by that point by
        /// that member for that <b>IInvocable</b> object will be returned.
        /// Specifically, the result for a given member will be null under
        /// the following conditions:</p>
        /// <list type="bullet">
        /// <item>if the member did not exist</item>
        /// <item>if the member was not running the service at the time that
        /// the query method was invoked</item>
        /// <item>if the member left (via the shutdown or stop methods, or
        /// unexpectedly) before responding</item>
        /// <item>if the member encountered an exception while processing
        /// and had not registered a non-null result</item>
        /// <item>if the member completed successfully but registered no
        /// result</item>
        /// <item>if the member completed successfully but explicitly
        /// registered a result of null</item>
        /// </list>
        /// </remarks>
        /// <param name="task">
        /// The <b>IInvocable</b> object to distribute to the specified
        /// members in order to be invoked on those members.
        /// </param>
        /// <param name="col">
        /// Optional collection of cluster members to which the
        /// <b>IInvocable</b> object will be distributed; if <c>null</c>, the
        /// <b>IInvocable</b> object will be distributed to all cluster
        /// members that are running this service.
        /// </param>
        /// <returns>
        /// An <b>IDictionary</b> of result objects keyed by <see cref="IMember"/>
        /// object.
        /// </returns>
        public virtual IDictionary Query(IInvocable task, ICollection col)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task cannot be null.");
            }

            if (col != null)
            {
                throw new ArgumentException("directed query not supported; " +
                                            "the specified IMember collection must be null.");
            }

            IChannel          channel = EnsureChannel();
            IMessageFactory   factory = channel.MessageFactory;
            InvocationRequest request = (InvocationRequest)factory.CreateMessage(InvocationRequest.TYPE_ID);

            request.Task = task;

            object  result = channel.Request(request);
            IMember member = OperationalContext.LocalMember;

            IDictionary resultDictionary = new HashDictionary();

            resultDictionary.Add(member, result);
            return(resultDictionary);
        }
Example #5
0
        public IHttpResponse Handle(IHttpRequest request)
        {
            this.request = request;

            this.getParams = request.UrlParameters;

            this.postParams = request.FormData;

            this.requestMethod = request.Method.ToString();

            this.controllerName = GetControllerName(request.Path);

            this.actionName = GetActionName(request.Path);

            MethodInfo method = this.GetMethod();

            if (method == null)
            {
                return(new NotFoundResponse());
            }

            MapMethodParameters(method);

            IInvocable actionResult = (IInvocable)method.Invoke(this.GetController(), this.methodParams);

            string content = actionResult.Invoke();

            IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content);

            return(response);
        }
Example #6
0
 void ISequence.Invoked(IInvocable setUp)
 {
     Invocations.Add(setUp);
     if (VerifiesUponInvocation())
     {
         VerifyCurrentInvocation();
     }
 }
Example #7
0
        public void Dispatch()
        {
            IInvocable result
                = (IInvocable)this
                  .GetMethod()
                  .Invoke(this.GetController(), this.methodParams);

            result.Invoke();
        }
Example #8
0
 void ISequence.RegisterInvocable(IInvocable setUp)
 {
     SetIsInvocationIndices(setUp.SequenceInvocationIndices != null);
     if (!isInvocationIndices)
     {
         setUp.SequenceInvocationIndices = new SequenceInvocationIndices(Enumerable.Range(setupTimesCount, setUp.ConsecutiveInvocations).ToArray());
         setupTimesCount = setupTimesCount + setUp.ConsecutiveInvocations;
     }
     AddExpectedInvocations(setUp);
     SetBehavior(setUp.Mock);
 }
Example #9
0
 private void AddExpectedInvocations(IInvocable setUp)
 {
     foreach (var sequenceInvocationIndex in setUp.SequenceInvocationIndices)
     {
         try
         {
             expectedInvocations.Add(sequenceInvocationIndex, setUp);
         }
         catch (ArgumentException)
         {
             throw SequenceSetupException.RepeatedCallIndexAcrossSetupsException(sequenceInvocationIndex);
         }
     }
 }
Example #10
0
        private HttpResponse CreateHttpResponse()
        {
            var        method       = this.GetMethod();
            IInvocable actionResult = (IInvocable)this.GetMethod()
                                      .Invoke(this.GetController(), this.methodParams);

            string content  = actionResult.Invoke();
            var    response = new HttpResponse()
            {
                StatusCode    = ResponseStatusCode.Ok,
                ContentAsUTF8 = content
            };

            return(response);
        }
Example #11
0
            private static object Invoke(IInvocable method, object instance, object[] args)
            {
                var finalArgs = args.Where(x => !(x is TypeParameter)).ToArray();
                var refArgs   = new Dictionary <int, RefValue>();
                var outArgs   = new Dictionary <int, OutValue>();

                for (int i = 0; i < method.Parameters.Count; i++)
                {
                    if (method.Parameters[i].ParameterType.IsByRef)
                    {
                        var refArg = finalArgs[i] as RefValue;
                        var outArg = finalArgs[i] as OutValue;
                        if (refArg != null)
                        {
                            refArgs[i] = refArg;
                        }
                        else if (outArg != null)
                        {
                            outArgs[i] = outArg;
                        }
                    }
                }

                foreach (var refArg in refArgs)
                {
                    finalArgs[refArg.Key] = refArg.Value.Value;
                }
                foreach (var outArg in outArgs)
                {
                    finalArgs[outArg.Key] = null;
                }

                var result = method.Invoke(instance, finalArgs);

                foreach (var refArg in refArgs)
                {
                    refArg.Value.Value = finalArgs[refArg.Key];
                }
                foreach (var outArg in outArgs)
                {
                    outArg.Value.Value = finalArgs[outArg.Key];
                }

                return(result);
            }
Example #12
0
        public HttpResponse Handle(HttpRequest request)
        {
            this.getParams = WebUtilities.RetrieveGetParameters(request.Url);

            this.postParams = WebUtilities.RetrievePostParameters(request.Content);

            this.requestMethod = request.Method.ToString();

            Tuple <string, string> controllerAndActionNames = this.GetControllerAndActionName(request.Url);

            if (controllerAndActionNames == null)
            {
                return(HttpResponseBuilder.NotFound());
            }

            this.controllerName = controllerAndActionNames.Item1;
            this.actionName     = controllerAndActionNames.Item2;

            MethodInfo method = this.GetControllerMethod(this.controllerName, this.actionName, this.requestMethod);

            if (method == null)
            {
                throw new NotSupportedException("Method not supported!");
            }

            this.SetMethodParameters(method);

            IInvocable actionResult = (IInvocable)this.GetControllerMethod(
                this.controllerName,
                this.actionName,
                this.requestMethod)
                                      .Invoke(
                this.GetController(this.GetControllerTypeName(this.controllerName)),
                this.methodParams);

            string content = actionResult.Invoke();

            HttpResponse response = new HttpResponse()
            {
                ContentAsUTF8 = content
            };

            return(response);
        }
        public HttpResponse Handle(HttpRequest request)
        {
            this.ClearParameters();
            this.request  = request;
            this.response = new HttpResponse();
            this.ParseInput();

            IInvocable result =
                (IInvocable)this.GetMethod()
                .Invoke(this.GetController(), this.methodParams);

            if (string.IsNullOrEmpty(this.response.Header.Location))
            {
                this.response.StatusCode    = ResponseStatusCode.Ok;
                this.response.ContentAsUTF8 = result.Invoke();
            }

            return(this.response);
        }
Example #14
0
        public HttpResponse Handle(HttpRequest request)
        {
            this.ParseInput(request);
            //TODO check if there is session with given id and execute the method only if user is authorised

            var        method     = this.GetMethod();
            var        controller = this.GetController();
            IInvocable result     =
                (IInvocable)method
                .Invoke(controller, this.methodParams);

            string content  = result.Invoke();
            var    response = new HttpResponse()
            {
                ContentAsUTF8 = content,
                StatusCode    = ResponseStatusCode.OK
            };

            this.ClearRequestParameters();
            return(response);
        }
        public HttpResponse Handle(HttpRequest request)
        {
            this.request  = request;
            this.response = new HttpResponse();
            ParseInput();


            MethodInfo method       = this.GetMethod();
            Controller controller   = this.GetController();
            IInvocable actionResult = (IInvocable)method
                                      .Invoke(controller, this.methodParams);

            if (string.IsNullOrEmpty(this.response.Header.Location))
            {
                this.response.StatusCode    = ResponseStatusCode.Ok;
                this.response.ContentAsUTF8 = actionResult.Invoke();
            }

            this.ClearParameters();

            return(response);
        }
Example #16
0
        /// <summary>
        /// Restore the contents of a user type instance by reading its state
        /// using the specified <see cref="IPofReader"/> object.
        /// </summary>
        /// <param name="reader">
        /// The <b>IPofReader</b> from which to read the object's state.
        /// </param>
        /// <exception cref="IOException">
        /// If an I/O error occurs.
        /// </exception>
        /// <seealso cref="Request.ReadExternal"/>
        public override void ReadExternal(IPofReader reader)
        {
            base.ReadExternal(reader);

            Task = (IInvocable)reader.ReadObject(1);
        }
Example #17
0
        public HttpResponse Handle(HttpRequest request)
        {
            this.requestParameters = new Dictionary <string, string>();
            string requestMethod = null;

            if (request.Method == RequestMethod.GET)
            {
                this.requestParameters = DecodeParams(request.Url);
            }
            else
            {
                this.requestParameters = DecodeParams(request.Content);
            }

            this.requestMethodType = request.Method.ToString();
            this.MapUrlToControllerAndAction(request.Url);

            MethodInfo method = this.GetMethod();

            if (method == null)
            {
                throw new NotSupportedException("Action is not supported");
            }
            IEnumerable <ParameterInfo> parameters = method.GetParameters();

            this.methodParameters = new object[parameters.Count()];
            int index = 0;

            foreach (ParameterInfo pamfo in parameters)

            {
                if (pamfo.ParameterType.IsPrimitive)
                {
                    object value = this.requestParameters[pamfo.Name];
                    this.methodParameters[index] = Convert.ChangeType(value, pamfo.ParameterType);
                    index++;
                }
                else if (pamfo.ParameterType == typeof(HttpRequest))
                {
                    this.methodParameters[index] = pamfo;
                    index++;
                }
                else if (pamfo.ParameterType == typeof(HttpSession))
                {
                    this.methodParameters[index] = request.HttpSession;
                    index++;
                }
                else
                {
                    Type   bindingModelType = pamfo.ParameterType;
                    object bindingModel     = Activator.CreateInstance(bindingModelType);
                    foreach (var requestParam in this.requestParameters)
                    {
                        PropertyInfo pinfo =
                            bindingModelType.GetProperties()
                            .FirstOrDefault(p => p.Name.ToLower() == requestParam.Key.ToLower());
                        if (pinfo != null)
                        {
                            pinfo.SetValue(bindingModel, Convert.ChangeType(this.requestParameters[pinfo.Name], pinfo.PropertyType));
                        }
                    }
                    this.methodParameters[index] = Convert.ChangeType(bindingModel, bindingModelType);
                    index++;
                }
            }
            Controller controller = this.GetController();

            IInvocable actionResult = (IInvocable)method.Invoke(controller, this.methodParameters);
            string     content      = actionResult.Invoke();
            var        response     = new HttpResponse();

            if (!string.IsNullOrEmpty(actionResult.Location))
            {
                response.StatusCode = ResponseStatusCode.Found;
                response.Header.OtherParameters.Add("Location", actionResult.Location);
            }
            else
            {
                response.StatusCode    = ResponseStatusCode.Ok;
                response.ContentAsUTF8 = content;
            }
            return(response);
        }
        public IHttpResponse Handle(IHttpRequest request)
        {
            var getTokens =
                request
                .UrlParameters;

            foreach (var item in getTokens)
            {
                string key   = item.Key;
                string value = item.Value;

                this.getParams[key] = value;
            }

            var postTokens = request.FormData;

            foreach (var item in postTokens)
            {
                string key   = item.Key;
                string value = item.Value;

                this.postParams[key] = value;
            }

            this.requestMethod = request.Method.ToString().ToUpper();

            string getControllerAndActionTokens =
                request
                .Url
                .Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries)[0];

            if (getControllerAndActionTokens.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries).Length < 2)
            {
                return(new NotFoundResponse());
            }

            string controllerName = getControllerAndActionTokens
                                    .Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0] + "Controller";

            controllerName      = controllerName.First().ToString().ToUpper() + controllerName.Substring(1);
            this.controllerName = controllerName;


            string actionName = getControllerAndActionTokens
                                .Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries).Last();

            actionName      = actionName.First().ToString().ToUpper() + actionName.Substring(1);
            this.actionName = actionName;


            if (actionName == controllerName)
            {
                return(new NotFoundResponse());
            }

            MethodInfo method = this.GetMethod();

            if (method == null)
            {
                return(new NotFoundResponse());
            }

            IEnumerable <ParameterInfo> parameters = method.GetParameters();

            this.methodParams = new object[parameters.Count()];

            int index = 0;

            foreach (ParameterInfo param in parameters)
            {
                if (param.ParameterType.IsPrimitive ||
                    param.ParameterType == typeof(string))
                {
                    object value = this.getParams[param.Name];
                    this.methodParams[index] = Convert.ChangeType(
                        value,
                        param.ParameterType
                        );

                    index++;
                }
                else
                {
                    Type bindingModelType = param.ParameterType;

                    object bindingModel =
                        Activator.CreateInstance(bindingModelType);

                    IEnumerable <PropertyInfo> properties
                        = bindingModelType.GetProperties();

                    foreach (PropertyInfo property in properties)
                    {
                        property.SetValue(bindingModel,
                                          Convert.ChangeType(
                                              postParams[property.Name],
                                              property.PropertyType
                                              )
                                          );
                    }

                    this.methodParams[index] = Convert.ChangeType(
                        bindingModel,
                        bindingModelType
                        );
                    index++;
                }
            }

            IInvocable actionResult = (IInvocable)this.GetMethod()
                                      .Invoke(this.GetController(), this.methodParams);

            string content = actionResult.Invoke();

            IHttpResponse response =
                new ContentResponse(HttpStatusCode.Ok, content);

            return(response);
        }
Example #19
0
        public IHttpResponse Handle(IHttpRequest request)
        {
            foreach (var urlParam in request.UrlParameters)
            {
                this.getParams[urlParam.Key] = urlParam.Value;
            }

            foreach (var postParam in request.FormData)
            {
                this.postParams[postParam.Key] = postParam.Value;
            }

            this.requestMethod = request.Method.ToString().ToUpper();

            var urlTokens = request.Url.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            if (urlTokens.Length != 2)
            {
                return(new NotFoundResponse());
            }
            if (request.Url.Contains("?"))
            {
                int ind = urlTokens[urlTokens.Length - 1].IndexOf("?");

                urlTokens[urlTokens.Length - 1] = urlTokens[urlTokens.Length - 1].Substring(0, ind);
            }

            string controllerName = urlTokens[0].Substring(0, 1).ToUpper() + urlTokens[0].Substring(1).ToLower() + MvcContext.Get.ControllerSuffix;
            string actionName     = urlTokens[1].Substring(0, 1).ToUpper() + urlTokens[1].Substring(1).ToLower();

            this.controllerName = controllerName;
            this.actionName     = actionName;

            MethodInfo method = this.GetMethod();

            if (method == null)
            {
                return(new NotFoundResponse());
            }

            IEnumerable <ParameterInfo> parameters = method.GetParameters();

            this.methodParams = new object[parameters.Count()];

            int index = 0;

            foreach (ParameterInfo param in parameters)
            {
                if (param.ParameterType.IsPrimitive || param.ParameterType == typeof(string))
                {
                    object value = this.getParams[param.Name];
                    this.methodParams[index] = Convert.ChangeType(value, param.ParameterType);
                    index++;
                }
                else
                {
                    Type   bindingModelType = param.ParameterType;
                    object bindingModel     = Activator.CreateInstance(bindingModelType);

                    IEnumerable <PropertyInfo> properties = bindingModelType.GetProperties();

                    foreach (PropertyInfo property in properties)
                    {
                        property.SetValue(
                            bindingModel, Convert.ChangeType(
                                postParams[property.Name],
                                property.PropertyType
                                )
                            );
                    }

                    this.methodParams[index] = Convert.ChangeType(
                        bindingModel,
                        bindingModelType);
                    index++;
                }
            }

            IInvocable actionResult = (IInvocable)this.GetMethod()
                                      .Invoke(this.GetController(), this.methodParams);

            string content = actionResult.Invoke();

            IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content);

            return(response);
        }
Example #20
0
        public HttpResponse Handle(HttpRequest request)
        {
            this.RetrieveRequestParams(request);

            this.requestMethod = request.Method.ToString();

            string[] urlComponents = request.Url.Split('/');

            if (urlComponents.Length >= 2)
            {
                this.controllerName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(urlComponents[1]) + "Controller";

                this.actionName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(urlComponents[2].Split('?')[0]);
            }

            MethodInfo method = GetMethod();

            if (method == null)
            {
                throw new NotSupportedException("No such method!");
            }

            //////////////////////////////////////////

            IEnumerable <ParameterInfo> parameters = method.GetParameters();

            this.methodParams = new object[parameters.Count()];

            int index = 0;

            foreach (ParameterInfo param in parameters)
            {
                if (param.ParameterType.IsPrimitive)
                {
                    object value = this.getParams[param.Name];

                    this.methodParams[index] = Convert.ChangeType(value, param.ParameterType);
                    index++;
                }
                else
                {
                    Type   bindingModelType = param.ParameterType;
                    object bindingModel     = Activator.CreateInstance(bindingModelType);

                    IEnumerable <PropertyInfo> properties = bindingModelType.GetProperties();

                    foreach (PropertyInfo property in properties)
                    {
                        property.SetValue(bindingModel, Convert.ChangeType(postParams[property.Name], property.PropertyType));
                    }
                    this.methodParams[index] = Convert.ChangeType(bindingModel, bindingModelType);
                    index++;
                }
            }

            IInvocable actionResult = (IInvocable)this.GetMethod().Invoke(this.GetController(), this.methodParams);

            string content = actionResult.Invoke();

            var response = new HttpResponse
            {
                StatusCode    = ResponseStatusCode.Ok,
                ContentAsUTF8 = content
            };

            return(response);

            //////////////////////////////////////////
        }
 /// <summary>
 /// Test if invoking the SampleInvocable instance works.
 /// </summary>
 /// <param name="sampleInvocable">Can be real local instance or remote
 /// proxy.</param>
 private static void InvokeSampleInvokable(IInvocable sampleInvocable)
 {
     Assert.Equal("FOO", sampleInvocable.Invoke(new[] { "Foo" }));
 }
Example #22
0
        public HttpResponse Handle(HttpRequest request)
        {
            string url   = WebUtility.UrlDecode(request.Url);
            string query = string.Empty;

            if (url.Contains('?'))
            {
                query = url.Split('?')[1];
            }

            var controllerActionParams = url.Split('?');
            var controllerAction       = controllerActionParams[0].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            controllerActionParams = query.Split('&');

            if (controllerActionParams.Length >= 1)
            {
                foreach (var getPar in controllerActionParams)
                {
                    if (getPar.Contains('='))
                    {
                        var keyValue = getPar.Split('=');
                        getParams.Add(keyValue[0], keyValue[1]);
                    }
                }
            }

            string contentParam = request.Content;

            if (contentParam != null)
            {
                contentParam = WebUtility.UrlDecode(contentParam);
                var postRequestParams = contentParam.Split('&');

                foreach (var postPar in postRequestParams)
                {
                    var parametersRest = postPar.Split('=');
                    postParams.Add(parametersRest[0], parametersRest[1]);
                }
            }

            this.requestMethod = request.Method.ToString();

            string controllerNameFormat = controllerAction[0].First().ToString().ToUpper() + String.Join("", controllerAction[0].Skip(1)) + "Controller";

            this.controllerName = controllerNameFormat;

            string actionNameFormat = controllerAction[1].First().ToString().ToUpper() + String.Join("", controllerAction[1].Skip(1));

            this.actionName = actionNameFormat;

            MethodInfo method = this.GetMethod();

            if (method == null)
            {
                throw new NotSupportedException("No such method");
            }

            IEnumerable <ParameterInfo> parameters = method.GetParameters();

            this.methodParams = new object[parameters.Count()];

            int index = 0;

            foreach (ParameterInfo param in parameters)
            {
                if (param.ParameterType.IsPrimitive)
                {
                    object value = this.getParams[param.Name];
                    this.methodParams[index] = Convert.ChangeType(value, param.ParameterType);
                    index++;
                }
                else
                {
                    Type   bindingModelType = param.ParameterType;
                    object bindingModel     = Activator.CreateInstance(bindingModelType);
                    IEnumerable <PropertyInfo> properties = bindingModelType.GetProperties();

                    foreach (PropertyInfo property in properties)
                    {
                        property.SetValue(bindingModel, Convert.ChangeType(postParams[property.Name], property.PropertyType));
                    }

                    this.methodParams[index] = Convert.ChangeType(bindingModel, bindingModelType);
                    index++;
                }
            }

            IInvocable actionResult = (IInvocable)this.GetMethod()
                                      .Invoke(this.GetController(), this.methodParams);

            string content  = actionResult.Invoke();
            var    response = new HttpResponse()
            {
                StatusCode    = ResponseStatusCode.Ok,
                ContentAsUTF8 = content
            };

            this.ClearParamDictionaries();
            return(response);
        }
 /// <summary>
 /// Synchronously invoke the specified task on each of the specified
 /// members.
 /// </summary>
 /// <remarks>
 /// <p>
 /// This method will not return until the specified members have
 /// completed their processing, failed in their processing, or died
 /// trying.</p>
 /// <p>
 /// <b>IMember</b>s that are specified but are not currently running
 /// the <b>IInvocationService</b> will not invoke the specified
 /// <see cref="IInvocable"/> object.</p>
 /// <p>
 /// <b>IMember</b>s that leave (gracefully or otherwise) before the
 /// invocation completes will not register a result, and the amount
 /// of processing that completed is indeterminate. <b>IMember</b>s
 /// that encounter an exception during invocation will not be
 /// retried; whatever result has been registered by that point by
 /// that member for that <b>IInvocable</b> object will be returned.
 /// Specifically, the result for a given member will be null under
 /// the following conditions:</p>
 /// <list type="bullet">
 /// <item>if the member did not exist</item>
 /// <item>if the member was not running the service at the time that
 /// the query method was invoked</item>
 /// <item>if the member left (via the shutdown or stop methods, or
 /// unexpectedly) before responding</item>
 /// <item>if the member encountered an exception while processing
 /// and had not registered a non-null result</item>
 /// <item>if the member completed successfully but registered no
 /// result</item>
 /// <item>if the member completed successfully but explicitly
 /// registered a result of null</item>
 /// </list>
 /// </remarks>
 /// <param name="task">
 /// The <b>IInvocable</b> object to distribute to the specified
 /// members in order to be invoked on those members.
 /// </param>
 /// <param name="col">
 /// Optional collection of cluster members to which the
 /// <b>IInvocable</b> object will be distributed; if <c>null</c>, the
 /// <b>IInvocable</b> object will be distributed to all cluster
 /// members that are running this service.
 /// </param>
 /// <returns>
 /// An <b>IDictionary</b> of result objects keyed by <see cref="IMember"/>
 /// object.
 /// </returns>
 public IDictionary Query(IInvocable task, ICollection col)
 {
     return(RunningInvocationService.Query(task, col));
 }
Example #24
0
        public IHttpResponse Handle(IHttpRequest request)
        {
            this.getParams     = request.UrlParameters;
            this.postParams    = request.FormData;
            this.requestMethod = request.Method.ToString();

            string[] urlArgs = request
                               .Url
                               .Split(new[] { '/', '?' },
                                      StringSplitOptions.RemoveEmptyEntries);

            if (urlArgs.Length <= 2)
            {
                string controller = urlArgs[1];
                string action     = urlArgs[2];

                this.controllerName = string.Concat(
                    char.ToUpper(controller[0]),
                    controller.Substring(1),
                    "Controller");

                this.actionName = string.Concat(
                    char.ToUpper(action[0]),
                    action.Substring(1));
            }

            MethodInfo method = this.GetMethod();

            if (method == null)
            {
                return(new NotFoundResponse());
            }

            IEnumerable <ParameterInfo> parameters = method.GetParameters();

            this.methodParams = new object[parameters.Count()];

            int index = 0;

            foreach (ParameterInfo param in parameters)
            {
                if (param.ParameterType.IsPrimitive ||
                    param.ParameterType == typeof(string))
                {
                    object value = this.getParams[param.Name];
                    this.methodParams[index] = Convert.ChangeType(value, param.ParameterType);
                    index++;
                }
                else
                {
                    Type   bindingModelType = param.ParameterType;
                    object bindingModel     = Activator.CreateInstance(bindingModelType);

                    IEnumerable <PropertyInfo> properties = bindingModelType.GetProperties();

                    foreach (PropertyInfo property in properties)
                    {
                        property.SetValue(
                            bindingModel,
                            Convert.ChangeType(
                                this.postParams[property.Name],
                                property.PropertyType));
                    }

                    this.methodParams[index] = Convert.ChangeType(bindingModel, bindingModelType);
                    index++;
                }
            }

            IInvocable actionResult = (IInvocable)this.GetMethod()
                                      .Invoke(this.GetController(), this.methodParams);

            string        content  = actionResult.Invkoe();
            IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content);

            return(response);
        }