Custom Workflow Activity to calculate and return

The following sample workflow activity demonstrates how to return a calculated value from an activity.



using System;
using System.Collections;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Reflection;

using Microsoft.Crm.Workflow;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Sdk.Query;

namespace SampleWorkflows
{
[CrmWorkflowActivity("Return a Calculated Value")]
public class AddActivity : Activity
{

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
result = new CrmNumber(a.Value + b.Value);
return base.Execute(executionContext);
}

public static DependencyProperty aProperty =
DependencyProperty.Register("a",
typeof(CrmNumber),
typeof(AddActivity));

[CrmInput("a")]
public CrmNumber a
{
get
{
return (CrmNumber)base.GetValue(aProperty);
}
set
{
base.SetValue(aProperty, value);
}

}

public static DependencyProperty bProperty =
DependencyProperty.Register("b",
typeof(CrmNumber),
typeof(AddActivity));

[CrmInput("b")]
public CrmNumber b
{
get
{
return (CrmNumber)base.GetValue(bProperty);
}
set
{
base.SetValue(bProperty, value);
}

}

public static DependencyProperty resultProperty =
DependencyProperty.Register("result",
typeof(CrmNumber),
typeof(AddActivity));

[CrmOutput("result")]
public CrmNumber result
{
get
{
return (CrmNumber)base.GetValue(resultProperty);
}
set
{
base.SetValue(resultProperty, value);
}

}
}
}