locked
xaml DisplayName vs NativeActivity DisplayName RRS feed

  • Question

  • New to this and confused. I set the DisplayName for a NativeActivity in the activity disigner but in the Execute function the display name is the "class name".

    Is there a way to get the display name from the xaml so i can use it in the class code?

    </

     

     

    sap:WorkflowViewStateService.ViewState>

    <

     

     

    local:Activity1 sap:VirtualizedContainerService.HintSize="200,22" request="[request]" response="[response]" />

    <

     

     

    local:WaitForInput DisplayName="WaitForInput1" sap:VirtualizedContainerService.HintSize="200,22" request="[request]" response="[response]" />

    <

     

     

    local:Activity1 DisplayName="Activity2" sap:VirtualizedContainerService.HintSize="200,22" request="[request]" response="[response]" />

    </

     

     

    Sequence>

    </

     

     

    Activity>

    public

     

     

    class WaitForInput : NativeActivity

    {

     

     

     

    public WaitForInput()

    :

     

    base()

    {

     

     

    this.BookmarkName = string.Format("bm{0}", this.DisplayName);

    }

     

     

    private string BookmarkName { get; set; }

     

     

    public InArgument<IDictionary> request { get; set; }

     

     

    public OutArgument<IDictionary> response { get; set; }

     

     

    protected override void Execute(NativeActivityContext context)

    {

     

     

    Console.WriteLine(string.Format("Start {0}.", this.DisplayName));

     

     

    IDictionary d = context.GetValue<IDictionary>(request);

     

    context.CreateBookmark(BookmarkName,

     

    new BookmarkCallback(this.Continue));

    }

     

     

    void Continue(NativeActivityContext context, Bookmark bookmark,

     

     

    object obj)

    {

     

     

    Console.WriteLine(string.Format("Resume {0}.",this.DisplayName));

     

     

    IDictionary d = context.GetValue<IDictionary>(request);

    WorkFlowHelpers.

     

    ActivityHelpers helpers = new WorkFlowHelpers.ActivityHelpers();

     

     

    IDictionary result = helpers.WaitForInput(d, this.DisplayName);

     

     

    Dictionary<string, object> parameters = new Dictionary<string, object>();

    parameters.Add(

     

    "response", result);

    context.SetValue(

     

    this.response, parameters);

    }

     

     

    protected override bool CanInduceIdle { get { return true; } }

    }

    Wednesday, July 7, 2010 8:23 PM

Answers

  • I see a problem with the use of DisplayName in your constructor. Properties that are defined in XAML get set after the constructor is called. So you should set things like BookmarkName in CacheMetadata instead of in the constructor.

    But I'm not sure why there'd be a problem in Execute. My sample below works just fine (it prints FooBar). Can you share a full working repro of the problem?

    using System;
    using System.Activities;
    using System.Xaml;
    
    public class MyActivity : NativeActivity
    {
      protected override void Execute(NativeActivityContext context)
      {
        Console.WriteLine(this.DisplayName);
      }
    }
    
    public class Test
    {
      const string xaml =
        "<MyActivity xmlns='clr-namespace:;assembly=Program' DisplayName='FooBar' />";
    
      public static void Main(string[] args)
      {
        Activity a = (Activity)XamlServices.Parse(xaml);
        WorkflowInvoker.Invoke(a);
      }
    }
    • Proposed as answer by Andrew_Zhu Wednesday, July 14, 2010 2:40 AM
    • Marked as answer by Andrew_Zhu Thursday, July 15, 2010 1:38 AM
    Thursday, July 8, 2010 12:13 AM

All replies

  • I see a problem with the use of DisplayName in your constructor. Properties that are defined in XAML get set after the constructor is called. So you should set things like BookmarkName in CacheMetadata instead of in the constructor.

    But I'm not sure why there'd be a problem in Execute. My sample below works just fine (it prints FooBar). Can you share a full working repro of the problem?

    using System;
    using System.Activities;
    using System.Xaml;
    
    public class MyActivity : NativeActivity
    {
      protected override void Execute(NativeActivityContext context)
      {
        Console.WriteLine(this.DisplayName);
      }
    }
    
    public class Test
    {
      const string xaml =
        "<MyActivity xmlns='clr-namespace:;assembly=Program' DisplayName='FooBar' />";
    
      public static void Main(string[] args)
      {
        Activity a = (Activity)XamlServices.Parse(xaml);
        WorkflowInvoker.Invoke(a);
      }
    }
    • Proposed as answer by Andrew_Zhu Wednesday, July 14, 2010 2:40 AM
    • Marked as answer by Andrew_Zhu Thursday, July 15, 2010 1:38 AM
    Thursday, July 8, 2010 12:13 AM
  • Ok that helped some moving it to the Execute, but I seem to still have problems.

    I have a NativeActivity that is in the workflow(xaml) multiple times it calls a helper class and it decides what to do based off of the display name.

    This was following a artical about handeling workflow changes. The idea is that as long as workflow changes only occure in the xaml and external classes it makes changes to the workflow easier to handle without having to direct each instance to the appropiate dll.

    The problem seems to still be activity2 has the same displayName as activity1 for some reason.

    If you have a email address I can send you the prototype I am working on. 

     

     

    Thursday, July 8, 2010 4:48 PM
  • So I'd suggest that rather than using DisplayName, maybe you want to use some property that's a little more customized for the purpose?

    That said, if you can create as small a repro of the problem as possible, you can post it up at skydrive.live.com and I'll take a look.

    (If the repro involves code you can't share publicly, then you can e-mail it to me at dglick at microsoft dot com, but generally having everything public on the forums is good since it makes it easier for people to find answers later.)

    Thursday, July 8, 2010 8:23 PM