Exemplo n.º 1
0
        /// <summary>
        /// Executes this command with the specified <paramref name="parameters"/>. The parameter
        /// enumeration will be automatically converted to the formal parameters of the target method.
        /// <see cref="LateBoundValue"/> instances will be also resolved when used as parameters.
        /// </summary>
        /// <param name="parameters">Enumeration of actual parameters to be used for the command
        /// execution.</param>
        public void Execute(IEnumerable <object> parameters)
        {
            IDataDescriptor start;

            if (!_source.Evaluate(out start))
            {
                ServiceRegistration.Get <ILogger>().Warn("CommandBaseMarkupExtension: Could not find source value, could not execute command ({0})",
                                                         ToString());
                return;
            }
            IList <object> paramsList = LateBoundValue.ConvertLateBoundValues(parameters);
            object         obj;
            MethodInfo     mi;

            _compiledPath.GetMethod(start, paramsList.Count, out obj, out mi);
            if (mi == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("CommandBaseMarkupExtension: Could not find method, could not execute command ({0})",
                                                         ToString());
                return;
            }
            ParameterInfo[] parameterInfos = mi.GetParameters();
            try
            {
                object[] convertedParameters;
                if (ReflectionHelper.ConsumeParameters(paramsList, parameterInfos, true, out convertedParameters))
                {
                    mi.Invoke(obj, convertedParameters);
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("CommandBaseMarkupExtension: Error executing command '{0}'", e, this);
            }
        }
Exemplo n.º 2
0
        public void Execute()
        {
            IList <object> convertedCommands = LateBoundValue.ConvertLateBoundValues(_commands);

            foreach (object objectCmd in convertedCommands)
            {
                object o;
                if (!TypeConverter.Convert(objectCmd, typeof(IExecutableCommand), out o))
                {
                    throw new ArgumentException(string.Format("CommandList: Command '{0}' cannot be converted to {1}", objectCmd, typeof(IExecutableCommand).Name));
                }
                IExecutableCommand cmd = (IExecutableCommand)o;
                cmd.Execute();
                if (!ReferenceEquals(cmd, objectCmd))
                {
                    MPF.TryCleanupAndDispose(cmd);
                }
            }
        }