Exemple #1
0
        public Task<ViewModels.IReceiveResult> Invoke(Root root, Method method, ViewModels.IReceiveResult result)
        {
            result.Result = "";
            try
            {
                var parsed = Build.Controller(method.ClassName)
                               .Action(method.Name)
                               .Parameters(method.Parameters.ToDictionary(p => p.Name, p => p.Value));
                var returned = parsed.Invoke();

                foreach (var yielded in returned)
                {
                    result.Result += yielded;
                }
            }
            catch (TypeConversionFailedException ex)
            {
                var errorObject = new TypeConversionFailed
                {
                    Message = ex.Message,
                    Argument = ex.Argument,
                    TargetType = ex.TargetType.ToString(),
                    Value = ex.Value
                };
                result.Errors = new[] { errorObject };
            }
            catch (MissingArgumentException ex)
            {
                result.Errors = ex.Arguments
                    .Select(a => new MissingArgument { Message = ex.Message, Argument = a })
                    .ToArray();
            }
            return Task.FromResult(result);
        }
 public async Task<JsonResponse> Invoke(Root root, Method method, Func<Request.Configure, Request.Configure> action)
 {
     var form = method.Parameters.ToDictionary(p => p.Name, p => p.Value);
     foreach (var global in root.GlobalParameters)
     {
         if (!form.ContainsKey(global.Name))
         {
             form.Add(global.Name, global.Value);
         }
     }
     return await Invoke(method, form, action);
 }