[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Service Manager can use Windows Workflow Foundation through any management pack. This enables business logic to be executed when the management pack objects enter specific states. Workflows used by Service Manager are standard .NET Framework 3.5 binaries that contain a Windows Workflow–based class. The procedures in this document show how to create and configure a workflow by using Microsoft Visual Studio 2010. The examples build out a simple DLL used by the other topics in the SDK.

To create a new Sequential Workflow Library project

  1. Open the project template window by creating a new project or adding a new project to an existing solution.

  2. Target the .NET Framework version 3.5.

  3. Under the Workflow template category, select Sequential Workflow Library.

    You can use any project type as long as it compiles to a DLL.
  4. Set the project name to WorkflowPackageRequest, and click OK.

  5. After the project is created, right-click the project in the Solution Explorer window and then click Add Reference.

  6. When the Add Reference dialog appears, click the Browse tab, locate the three SDK binaries, and add all three by holding down the CTRL key and clicking each one. After all three are selected, click OK. For information about these binaries, see Getting Started with the Service Manager SDK.

To design the workflow

  1. Rename the workflow file from Workflow1.cs to PackageInitial.cs.

    If Visual Studio prompts you to rename all references, select Yes.
  2. With the designer for PackageInitial opened, expand the Toolbox tab if it is not already expanded and drag the Code item (under the Windows Workflow v3.0 category) to the area of the designer that contains the text Drop Activities to create a Sequential Workflow.

  3. Select the newly created Code activity, and rename it from codeActivity1 to ObjectCreatedCodeActivity in the Properties window.

  4. Switch the Properties window to display the events of the Code activity by clicking the events button (represented by a lightning bolt).

  5. Double-click the ExecuteCode item to auto-generate the event handler.

To add properties to the workflow

  1. In the code viewer of the PackageInitial workflow, add the following using statements to import the required Service Manager namespaces.

    C#  Copy Code
    using Microsoft.EnterpriseManagement;
    using Microsoft.EnterpriseManagement.Common;
    using Microsoft.EnterpriseManagement.Configuration;
  2. Create a new Guid property named InternalID. Supply both get and set accessors.

  3. Create a new Guid property named ClassGUID. Supply both get and set accessors.

As shown in the following example, the management pack subscription action that calls this workflow has to be configured to provide the required data to these properties. The workflow must get the specific object that the management pack defined as being tied to the workflow. This will be supplied on the InternalID property and is the GUID of the object instance in Service Manager. The ClassGUID property is just an easy reference of the type of object instance identified by the InternalID property. This is the GUID of the object’s class type in Service Manager.

C#  Copy Code
public Guid ClassGUID { get; set; }
public Guid InternalID { get; set; }

To code the workflow

  1. In the code viewer of the PackageInitial workflow, find the code activity’s ExecuteCode method named ObjectCreatedCodeActivity_ExecuteCode.

  2. Connect to the management group server, localhost.

  3. Use the entity types API to get the object instance that this workflow will run against.

  4. Get the management pack class of the object instance.

  5. Set the DisplayName property of the object instance.

  6. Save the changes to the object instance by calling the Commit method.

While you could subscribe to the Initialized and Completed events of the workflow itself, the preceding procedure simply used the activity’s event handler.

As shown in the following example, the connection to the Service Manager store is connecting to localhost because the workflow instance is always executed on the server.

C#  Copy Code
private void ObjectCreatedCodeActivity_ExecuteCode(object sender, EventArgs e)
	// Create a connection to the local server
	EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");

	// Get the object instance triggering the workflow
	EnterpriseManagementObject packageInstance = mg.EntityObjects.GetObject<EnterpriseManagementObject>(InternalID, ObjectQueryOptions.Default);

	// We know the class used by the object instance, so use the workflow parameter supplied property
	ManagementPackClass packageClass = mg.EntityTypes.GetClass(ClassGUID);

	// Set the DisplayName of the workflow so we know it went through the workflow
	packageInstance[packageClass, "DisplayName"].Value += " WENT THROUGH WORKFLOW";

	// Save the object changes

To install and debug the workflow

  1. After compiling the workflow, copy the workflow binary to the %programfiles%\Microsoft System Center\Service Manager 2010 folder on the management group servers that will contain the management pack referencing the workflow.

  2. To debug the workflow, copy the .pdb file together with the .dll into the Service Manager directory.

  3. To trigger the debugger, insert calls to the Break method into the workflow code.

When the workflow is initiated and a code line with the break is executed, the standard debugging dialog box appears. (This requires that you have Visual Studio installed on the server.)