Exemplo n.º 1
0
        /// <summary>
        /// Resolves the command for the specified post data.
        /// </summary>
        public ActionInfo ResolveCommand(IDotvvmRequestContext context, DotvvmView view)
        {
            // get properties
            var data            = context.ReceivedViewModelJson ?? throw new NotSupportedException("Could not find ReceivedViewModelJson in request context.");
            var path            = data["currentPath"].Values <string>().ToArray();
            var command         = data["command"].Value <string>();
            var controlUniqueId = data["controlUniqueId"]?.Value <string>();
            var args            = data["commandArgs"] is JArray argsJson?
                                  argsJson.Select(a => (Func <Type, object>)(t => a.ToObject(t))).ToArray() :
                                      new Func <Type, object> [0];

            // empty command
            if (string.IsNullOrEmpty(command))
            {
                return(null);
            }

            // find the command target
            if (!string.IsNullOrEmpty(controlUniqueId))
            {
                var target = view.FindControlByUniqueId(controlUniqueId);
                if (target == null)
                {
                    throw new Exception(string.Format("The control with ID '{0}' was not found!", controlUniqueId));
                }
                return(commandResolver.GetFunction(target, view, context, path, command, args));
            }
            else
            {
                return(commandResolver.GetFunction(view, context, path, command, args));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves the command for the specified post data.
        /// </summary>
        public ActionInfo ResolveCommand(IDotvvmRequestContext context, DotvvmView view)
        {
            // get properties
            var data            = context.ReceivedViewModelJson;
            var path            = data["currentPath"].Values <string>().ToArray();
            var command         = data["command"].Value <string>();
            var controlUniqueId = data["controlUniqueId"]?.Value <string>();
            var args            = data["commandArgs"]?.ToObject <object[]>() ?? new object[0];

            // empty command
            if (string.IsNullOrEmpty(command))
            {
                return(null);
            }

            // find the command target
            if (!string.IsNullOrEmpty(controlUniqueId))
            {
                var target = view.FindControlByUniqueId(controlUniqueId);
                if (target == null)
                {
                    throw new Exception(string.Format("The control with ID '{0}' was not found!", controlUniqueId));
                }
                // TODO(exyi) parameters from
                return(commandResolver.GetFunction(target, view, context, path, command, args));
            }
            else
            {
                return(commandResolver.GetFunction(view, context, path, command, args));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Resolves the command for the specified post data.
        /// </summary>
        public void ResolveCommand(IDotvvmRequestContext context, DotvvmView view, string serializedPostData, out ActionInfo actionInfo)
        {
            // get properties
            var data            = JObject.Parse(serializedPostData);
            var path            = data["currentPath"].Values <string>().ToArray();
            var command         = data["command"].Value <string>();
            var controlUniqueId = data["controlUniqueId"]?.Value <string>();

            if (string.IsNullOrEmpty(command))
            {
                // empty command
                actionInfo = null;
            }
            else
            {
                // find the command target
                if (!string.IsNullOrEmpty(controlUniqueId))
                {
                    var target = view.FindControlByUniqueId(controlUniqueId);
                    if (target == null)
                    {
                        throw new Exception(string.Format("The control with ID '{0}' was not found!", controlUniqueId));
                    }
                    actionInfo = commandResolver.GetFunction(target, view, context, path, command);
                }
                else
                {
                    actionInfo = commandResolver.GetFunction(view, context, path, command);
                }
            }
        }