Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
In order to add a new activity to our SharePoint Designer, first we need to begin a WorkFlow project in Visual Studio 2005, concretely, a Workflow Activity Library (Workflow activity library).
From this point we would create our activity; for this example I am going to create an activity that will send a text to the event viewer.
1: public partial class LogEventViewer : Activity
2: {
3:
4: public static DependencyProperty TextLogProperty =
5: DependencyProperty.Register("TextLog", typeof(string), typeof(LogEventViewer));
6:
7: public LogEventViewer()
8: {
9: InitializeComponent();
10: }
11:
12: /// <summary>
13: /// Valor que figurará en el visor de eventos
14: /// </summary>
15: /// <value>Texto</value>
16: [Description("Texto que saldrá en el visor de eventos")]
17: [Category("User")]
18: [Browsable(true)]
19: [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
20: public string TextLog
21: {
22: get { return (string) GetValue(TextLogProperty); }
23: set { SetValue(TextLogProperty, value); }
24: }
25:
26: /// <summary>
27: /// Ejecución de la actividad
28: /// </summary>
29: /// <param name="provider">Contexto de ejecución de la actividad</param>
30: /// <returns></returns>
31: protected override ActivityExecutionStatus Execute(ActivityExecutionContext provider)
32: {
33: EventLog eventLog = new EventLog("Workflow");
34:
35: eventLog.Source = "SharePoint Workflow";
36:
37: try
38: {
39: eventLog.WriteEntry(TextLog, EventLogEntryType.Information);
40: }
41: finally
42: {
43: eventLog.Dispose();
44: }
45:
46: return ActivityExecutionStatus.Closed;
47: }
48: }
First, we declare a dependent property of the workflow called TextLogProperty, which we will use to pass the text that we wish to show in the event viewer.
The internal property of the activity will be TextLog; this internal property obtains and establishes the value from the dependent property of the workflow.Then we define the Execute method, that will be the method in charge to visualize the message in the event viewer.A good practice is that the activities include a Validador, that I have omitted in the example but that is highly recommended although not obligatory, or if we want to use the activity inside of the visual studio workflow designer.
Once we have made the compilation, we can test it first (another good practice) creating an application to host the workflow and checking the activity.Finally, after we are sure that our activity works correctly, we must install it in the GAC in our SharePoint server. And we need to modify the Web.config to include our assembly in the following section:
<System.Workflow.ComponentModel.WorkflowCompiler> <authorizedTypes> ...... <authorizedType Assembly="IdeSeg.SharePoint.Workflow.Activities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3bba710be857fdc1" Namespace="IdeSeg.SharePoint.Workflow.Activities" TypeName="*" Authorized="True" /> </authorizedTypes> </System.Workflow.ComponentModel.WorkflowCompiler>
Now we need to modify the file WSS.ACTIONS that we saw in the first article in order to add our new action
<Action Name="Log en visor de eventos" ClassName="IdeSeg.SharePoint.Workflow.Activities.LogEventViewer" Assembly="IdeSeg.SharePoint.Workflow.Activities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3bba710be857fdc1" AppliesTo="all" Category="Personalizadas"> <RuleDesigner Sentence="Logear el evento siguiente %1"> <FieldBind Field="TextLog" Text="este mensaje" Id="1" DesignerType="TextArea"/> </RuleDesigner> <Parameters> <Parameter Name="TextLog" Type="System.String, mscorlib" Direction="In" /> </Parameters> </Action>
What we have done in the first place is authorize our assembly so that he is now an integral part of the WorkFlow engine of SharePoint, and secondly, adding it to the WSS.ACTIONS file, we have indicated to the SharePoint Designer that we have added a new activity.When we use SharePoint Designer to publish a site, at the moment that we created a new workflow or we published an existing one, he communicates with SharePoint and recovers the File WSS.ACTIONS to configurate the assistant of the WorkFlow. In this way the new actions will be part of the file XOML that the SharePoint Designer will create. Finally the result within the SharePoint Designer will be as follow: