示例#1
0
        public IActionResult InvokeAction(Controller c, ActionDescriptor ad)
        {
            /*
            * Child processes that use such C run-time functions as printf() and fprintf() can behave poorly when redirected.
            * The C run-time functions maintain separate IO buffers. When redirected, these buffers might not be flushed immediately after each IO call.
            * As a result, the output to the redirection pipe of a printf() call or the input from a getch() call is not flushed immediately and delays, sometimes-infinite delays occur.
            * This problem is avoided if the child process flushes the IO buffers after each call to a C run-time IO function.
            * Only the child process can flush its C run-time IO buffers. A process can flush its C run-time IO buffers by calling the fflush() function.
            */

            var methodWithIntParameter = c.GetType().GetMethods().FirstOrDefault(x => x.Name.ToLower() == ad.ActionName.ToLower()
                        && x.GetParameters().Length == 1
                        && x.GetParameters()[0].ParameterType == typeof(string)
                        && x.ReturnType == typeof(IActionResult));

            if (methodWithIntParameter == null)
            {
                throw new HttpNotFound(string.Format(NotFoundHttp, ad.ActionName, ad.ControllerName));
            }

            try
            {
                var actionResult = (IActionResult)methodWithIntParameter.Invoke(c, new object[] { ad.Parameter });
                return actionResult;
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }
        }
示例#2
0
 public IActionResult InvokeAction(Controller controller, ActionDescriptor actionDescriptor)
 {
     return new ActionInvoker().InvokeAction(controller, actionDescriptor);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ParserException"/> class.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="request">
 /// The request.
 /// </param>
 public ParserException(string message, ActionDescriptor request = null)
     : base(message)
 {
 }
 public void TestActionDescriptorWithValidDataShouldReturnCorrect()
 {
     var desc = new ActionDescriptor("a/b/c");
     Assert.AreEqual(desc.ToString(), @"/a/b/c");
 }
 public void TestActionDescriptorWithNullDataShouldReturnDefault()
 {
     var desc = new ActionDescriptor(null);
     Assert.AreEqual(desc.ToString(), @"/Home/Index/Param");
 }
 public void TestActionDescriptorWithEmptyDataShouldReturnDefaultData()
 {
     var desc = new ActionDescriptor(string.Empty);
     Assert.AreEqual(desc.ToString(), @"/Home/Index/Param");
 }