/// <summary> /// Invokes the underlying function of the command. /// </summary> /// <param name="toggle">The toggle status of the command.</param> /// <param name="context">The context under which the command is invoked.</param> /// <param name="args">The results of evaluating each argument given to the command.</param> /// <returns>A status code accompanied by text output.</returns> /// <exception cref="System.ArgumentNullException">Thrown when the given argument array is null.</exception> public EvaluationResult Invoke(Toggler toggle, EvaluationContext context, params Expression[] args) { if (args == null) { throw new ArgumentNullException("args"); } var e1 = new CommandInvocationEventArgs(context, toggle, args); OnInvocation(e1); if (e1.Cancel) { return(new EvaluationResult(CommonStatusCodes.InvocationCanceled, null, e1.CancelReason ?? "Invocation has stopped.")); } #if HCIE var e2 = new HostCommandInvocationEventArgs(this, context, toggle, args); context.Host.OnInvocation(e2); if (e2.Stop) { return(new EvaluationResult(CommonStatusCodes.InvocationCanceled, null, e2.StopReason ?? "Invocation has stopped.")); } #endif try { return(this.InvokeInternal(toggle, context, args)); } catch (Exception x) { return(new EvaluationResult(CommonStatusCodes.ClrException, null, x.ToString(), x)); } }
/// <summary> /// Raisese the <see cref="vCommands.CommandHost.CommandInvocation"/> event. /// </summary> /// <param name="e">A <see cref="vCommands.EventArguments.HostCommandInvocationEventArgs"/> that contains event data.</param> internal void OnInvocation(HostCommandInvocationEventArgs e) { CommandInvocation?.Invoke(this, e); }