How do I make the command run?

Jan 28, 2014 at 6:29 PM
I'm currently trying to create a toolkit and I'm running into a problem with a command. I have a command set to run on the instantiation event of the my View. The command however never runs. In the NuPattern Toolkit Extensions output, I see the following error:

NuPattern.Library.Automation.CommandAutomation Warning: 0 : Command LoadStart is missing required inputs and will not be executed:
Errors=... InnerResults=... PropertyName=this Value={ }
Errors: Could not resolve component with id 'VisitorToolkit.Automation.Commands.LoadStart' to an actual instance of type ICommand.
.

What is causing this? I've included the code of LoadStart for reference. I've removed the original code from the execute method to show that even this simple code fails.

namespace VisitorToolkit.Automation.Commands
{
/// <summary>
/// A custom command that performs some automation.
/// </summary>
[DisplayName("LoadStart")]
[Category("General")]
[Description("Load Start stuff")]
[CLSCompliant(false)]
public class LoadStart : NuPattern.Runtime.Command
{
    private static readonly ITracer tracer = Tracer.Get<LoadStart>();


    /// <summary>
    /// Executes this commmand.
    /// </summary>
    /// <remarks></remarks>
    public override void Execute()
    {
        tracer.Warn(
            "Executing LoadProjects on current View defaultView");
    }
}
}
Coordinator
Jan 28, 2014 at 10:24 PM
Erm, something not quite right here....

You normally get this specific error if one of the [Import] properties of your command cannot be satified (assigned) at toolkit runtime.
Your code example does not have any of those. But perhaps you had one or more [Import] props at some point?, and the code that is running is not the code that we see here? Perhaps it has not been built since you removed the imports - or someting wierd like that?
Otherwise I am pretty stumped.
Coordinator
Jan 28, 2014 at 10:24 PM
Are you on the VS2013 bits we just released? or older version?
Coordinator
Jan 28, 2014 at 10:27 PM
Oh wait! you say you have this set on the view? How is that possible?
You cannot configure automation (Command) on the view shape on the patternmodel (can you?)

How have you done that?
Jan 28, 2014 at 11:39 PM

I'm sorry, I meant it was on the pattern itself, not the view.

Jan 29, 2014 at 3:48 PM
I'm going to install the VS2013 bits, I was using 2012 from the previous version
Jan 29, 2014 at 6:06 PM
Alright, I'm trying to run my command on the pattern itself and I'm running into the same error. I have it so the command to import the current IVisitorPattern it's running on; I've pasted the class below. Is this the correct way to get my IVisitorPattern (I'm assuming not) and if not, how should I do so?

namespace VisitorPattern.Automation.Commands
{
/// <summary>
/// A custom command that performs some automation.
/// </summary>
/// <summary>
/// A custom command that performs some automation.
/// </summary>
[DisplayName("LoadStart")]
[Category("General")]
[Description("Load Start stuff")]
[CLSCompliant(false)]
public class LoadStart : NuPattern.Runtime.Command
{
    private static readonly ITracer tracer = Tracer.Get<LoadStart>();

    /// <summary>
    /// Gets or sets the current element.
    /// </summary>
    [Required]
    [Import]
    public IVisitorPattern CurrentElement { get; set; }

    /// <summary>
    /// Executes this commmand.
    /// </summary>
    /// <remarks></remarks>
    public override void Execute()
    {
        tracer.Warn(
            "Executing LoadProjects on current View defaultView");

        // Verify all [Required] and [Import]ed properties have valid values.
        this.ValidateObject();



        // Make initial trace statement for this command
        tracer.Info(
            "Executing LoadProjects on current View defaultView");

        if (CurrentElement.DefaultView.Projects == null)
        {
            CurrentElement.DefaultView.CreateProjects("Projects");
        }

    }
}
}
Coordinator
Jan 30, 2014 at 8:07 AM
OK, I have repro-ed this, and confirm its a problem.
I created a brand new toolkit with either VS2012 or VS2013 bits, with a pattern called "VisitorPattern"
Added a new command called "LoadStart", and pasted your code into it.
Configured it on the pattern element with a command, added Launch point (in my case a contextmenuLP)

It fails as you report, in the trace window.

Then I changed your declaration of the IVisitorPattern Current Element to the following:
    [Required]
    [Import(AllowDefault = true)] 
    public IVisitorPattern CurrentElement { get; set; }
Notice the addition of the (AllowDefault = true).

Rebuilt, and now it works properly

All imports for services and toolkit built interfaces require the (AllowDefault=true) part. Why? see: http://msdn.microsoft.com/en-us/library/vstudio/system.componentmodel.composition.importattribute.allowdefault(v=vs.100).aspx

I am not entirely sure why this has to be, but without it the Import is never satisfied. Might need to ask kzu about why we always need this.


BTW, there is a list of common services you can import into your command in the guidance. Look under the topic: Reference\Automation\Common Automation Tasks\Importing Services into Automation Classes

Hope this all helps, sorry it been so difficult getting going with your pattern (one thing and another)
Marked as answer by wwahammy on 1/30/2014 at 8:47 AM
Jan 30, 2014 at 4:37 PM
Thanks for the fix! I think we're getting there!