locked
Programmatically setting CorrelatesWith property of new Receive Activity in Rehosted Designer RRS feed

  • Question

  • My intention is to set several properties of new Receive activities when they are dropped onto my rehosted designer. So far I have succeeded in setting the ServiceContractName, OperationName and Contents properties however when I try set the CorrelatesWith property I run into a problem.

    I am attempting to set the CorrelatesWith property by using the ModelItem (Corresponding to the new Receive activity). I find the CorrelatesWith Property in the ModelItem and set it to the existing CorrelationHandle Variable i have already added. The problem is that after calling the CorrelationProperty.SetValue, the property is not set and remains equal to null.

    Is there something I am doing incorrectly?

    The code I use is as follows:

    ModelService m

    odelService = this.WorkflowDesigner.Context.Services.GetService<ModelService>();
    System.Activities.Presentation.Converters.
    ModelToObjectValueConverter ModelToObjectConverter = new System.Activities.Presentation.Converters.ModelToObjectValueConverter();
    foreach (ModelItem ChildItem in modelService.Find(modelService.Root, typeof(Variable<System.ServiceModel.Activities.CorrelationHandle>)))
    {
    ModelProperty CurrentProperty = ChildItem.Properties.Single(item => item.Name == "Name");
    //The variable KeyCorrelate already exists in the workflow
    if (CurrentProperty.ComputedValue.ToString() == "KeyCorrelate")
    {
    CorrHndVariableObject = ModelToObjectConverter.Convert(ChildItem,
    typeof(Variable<System.ServiceModel.Activities.CorrelationHandle>), null, null);
    }
    }
    InArgument<System.ServiceModel.Activities.CorrelationHandle> InArgCorr = new InArgument<System.ServiceModel.Activities.CorrelationHandle>(CorrHndVariableObject as Variable<System.ServiceModel.Activities.CorrelationHandle>);
    ModelProperty CorrelationProperty = receiveItem.Properties.Single(item => item.Name == "CorrelatesWith");
    if (CorrelationProperty.Value == null)
    {
    CorrelationProperty.SetValue(InArgCorr);
    }

     

     

     

     

    Friday, January 22, 2010 9:58 AM

Answers

  • OK, I think I see what is going on, hopefully this is right:

    What you are doing in code, should be fine for the runtime object model and your workflow would probably run OK but there are a couple confusing issues:

    1) I would guess that a ModelEditingScope is most probably the reason your ModelProperties look still null after you have tried to set them. In this scenario it probably isn't something you need to do anything about, it just makes things harder to debug.

    2) The CorrelatesWith value has something saved in XAML but is not visible in the expression text box

    I haven't tested it out lately, but the reason for this would probably be either that the ExpressionTextBox only expects Visual Basic Expressions (VisualBasicValue and VisualBasicReference type expressions).

    Longer version, basically the code you write is doing something like this to the underlying object tree, setting a direct variable reference:

      .CorrelatesWith = new InArgument<CorrelationHandle>(VariableReference<CorrelatioHandle>(var));

    but the ETB only displays actual VB expressions built up as strings:

      .CorrelatesWith = new InArgument(new VisualBasicValue<CorrelationHandle>("variable1"));

    There is probably one or two other threads briefly showing an example of how it would look when using these types, here is one that briefly mentions it.

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/ffda684c-952a-48ac-82d0-5ded8fad8f47

    Tim
    • Proposed as answer by Tim Lovell-Smith Monday, January 25, 2010 9:36 AM
    • Marked as answer by robhurry Monday, January 25, 2010 11:15 AM
    Monday, January 25, 2010 9:36 AM

All replies

  • Hi Rob,

    I'm having trouble reproducing your problem with a pure code approach (no drag+drop). If you set a breakpoint, on

    CorrelationProperty.SetValue(InArgCorr);

    do you see that it gets called with valid arguments, but after you stepped past the statement the value is still null? (If you are seeing this, it may be because of a ModelEditingScope, rather than a bug and that the value should still get set, but at a slightly later time)

    If the value appears set correctly here, perhaps the value getting overriden to null by someone else at a later time?

    Could you let me know, does the property value look OK in XAML after addding the activity and serializing the file, or is it just not showing up in design surface?

    Thanks,
    Tim
    Friday, January 22, 2010 6:46 PM
  • Hi Tim,

    Thanks for the reply,

    I noticed that all of the properties I set are still null while I debug but are eventually set correctly (as the values have changed) when I view them in the designer. The problem is that for the CorrelatesWith property the value is still null when I view its value in the designer after setting it.

    As you suggested i've saved the workflow and viewed the xaml and it appears the CorrelatesWith property is set in the xaml. The strange thing is that the workflow even though the value is set in the xaml it still appears as null when I reload the workflow.

    Below is the xaml (With only a receive added to a flowchart)

    <Activity mc:Ignorable="sap" x:Class="CorrWF" sap:VirtualizedContainerService.HintSize="654,676" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sd1="clr-namespace:System.Data;assembly=System.Data.DataSetExtensions" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Flowchart sap:VirtualizedContainerService.HintSize="614,636" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces">
        <Flowchart.Variables>
          <x:Reference>__ReferenceID0</x:Reference>
          <x:Reference>__ReferenceID1</x:Reference>
          <x:Reference>__ReferenceID2</x:Reference>
        </Flowchart.Variables>
        <sap:WorkflowViewStateService.ViewState>
          <scg3:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">False</x:Boolean>
            <av:Point x:Key="ShapeLocation">270,2.5</av:Point>
            <av:Size x:Key="ShapeSize">60,75</av:Size>
          </scg3:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <Flowchart.StartNode>
          <x:Null />
        </Flowchart.StartNode>
        <FlowStep>
          <sap:WorkflowViewStateService.ViewState>
            <scg3:Dictionary x:TypeArguments="x:String, x:Object">
              <av:Point x:Key="ShapeLocation">172.5,97</av:Point>
              <av:Size x:Key="ShapeSize">255,86</av:Size>
            </scg3:Dictionary>
          </sap:WorkflowViewStateService.ViewState>
          <p:Receive sap:VirtualizedContainerService.HintSize="255,86" ServiceContractName="CorrWFContract">
            <p:Receive.CorrelatesWith>
              <InArgument x:TypeArguments="p:CorrelationHandle">
                <VariableValue x:TypeArguments="p:CorrelationHandle">
                  <VariableValue.Variable>
                    <Variable x:TypeArguments="p:CorrelationHandle" x:Name="__ReferenceID2" Name="KeyCorrelate" />
                  </VariableValue.Variable>
                </VariableValue>
              </InArgument>
            </p:Receive.CorrelatesWith>
            <p:ReceiveParametersContent>
              <OutArgument x:TypeArguments="x:String" x:Key="KeyId">
                <VariableReference x:TypeArguments="x:String">
                  <VariableReference.Variable>
                    <Variable x:TypeArguments="x:String" x:Name="__ReferenceID0" Name="KeyId" />
                  </VariableReference.Variable>
                </VariableReference>
              </OutArgument>
              <OutArgument x:TypeArguments="x:String" x:Key="SYSPROOperator">
                <VariableReference x:TypeArguments="x:String">
                  <VariableReference.Variable>
                    <Variable x:TypeArguments="x:String" x:Name="__ReferenceID1" Name="SYSPROOperator" />
                  </VariableReference.Variable>
                </VariableReference>
              </OutArgument>
            </p:ReceiveParametersContent>
          </p:Receive>
        </FlowStep>
      </Flowchart>
    </Activity>


    Thanks,

    Rob

    Monday, January 25, 2010 5:17 AM
  • OK, I think I see what is going on, hopefully this is right:

    What you are doing in code, should be fine for the runtime object model and your workflow would probably run OK but there are a couple confusing issues:

    1) I would guess that a ModelEditingScope is most probably the reason your ModelProperties look still null after you have tried to set them. In this scenario it probably isn't something you need to do anything about, it just makes things harder to debug.

    2) The CorrelatesWith value has something saved in XAML but is not visible in the expression text box

    I haven't tested it out lately, but the reason for this would probably be either that the ExpressionTextBox only expects Visual Basic Expressions (VisualBasicValue and VisualBasicReference type expressions).

    Longer version, basically the code you write is doing something like this to the underlying object tree, setting a direct variable reference:

      .CorrelatesWith = new InArgument<CorrelationHandle>(VariableReference<CorrelatioHandle>(var));

    but the ETB only displays actual VB expressions built up as strings:

      .CorrelatesWith = new InArgument(new VisualBasicValue<CorrelationHandle>("variable1"));

    There is probably one or two other threads briefly showing an example of how it would look when using these types, here is one that briefly mentions it.

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/ffda684c-952a-48ac-82d0-5ded8fad8f47

    Tim
    • Proposed as answer by Tim Lovell-Smith Monday, January 25, 2010 9:36 AM
    • Marked as answer by robhurry Monday, January 25, 2010 11:15 AM
    Monday, January 25, 2010 9:36 AM
  • Thanks Tim,

    That's exactly what I was looking for!
    Monday, January 25, 2010 11:16 AM