次の方法で共有


How to Reference a Workflow

Applies To: System Center 2012 - Service Manager

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

You can use Management pack monitoring with Windows Workflow Foundation to provide workflow logic to the management pack. A workflow can be integrated into the management pack by use of the WorkflowSubscription subscription action. The following table describes the two key fields required to link the workflow binary with the subscription action.

Field Description Example Value

AssemblyName

The name of the assembly installed on the Service Manager server.

WorkflowPackageRequest

WorkflowTypeName

The fully qualified name of the class inside the assembly.

WorkflowPackageRequest.PackageInitial

The workflow can be customized by providing parameters. The name and type of a parameter will correspond to the name and type of the desired property on the class instance specified by the subscription action WorkflowTypeName setting. The only valid parameter types are those defined by the WorkflowParameterType enumeration.

Important

The release version of Service Manager requires that if a subscription contains a workflow action, it must be associated with a category to appear in the Service Manager console.

To specify parameters on the workflow

  1. Create an instance of the WorkflowSubscription class.

  2. Set the AssemblyName and WorkflowTypeName properties.

  3. Enable the workflow by setting the Enabled property to true.

  4. Add any workflow parameters needed by the workflow.

  5. Insert the subscription by using the enterprise management group’s subscription API.

  6. Have the management pack accept the changes.

Example

The following example demonstrates how to create a workflow subscription action that uses instance criteria and configures two workflow parameters.

EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
string managementPackName = "RePackaging.Library";
string managementClassName = "RePackaging.Request";

ManagementPackCriteria searchCrit = new ManagementPackCriteria("$Name='" + managementPackName + "'$");
foreach (var mp in mg.ManagementPacks.GetManagementPacks(searchCrit))
{
    InstanceTypeSubscription subCriteria = new InstanceTypeSubscription(OperationType.Add, mp.GetClass(managementClassName).Id, "");
    subCriteria.BatchSize = 100;
    subCriteria.PollingIntervalInSeconds = 60;

    WorkflowSubscription subAction = new WorkflowSubscription("WF_AcceptPackageRequest", "Accepts the package request.", subCriteria);
    subAction.AssemblyName = "WorkflowPackageRequest";
    subAction.WorkflowTypeName = "WorkflowPackageRequest.PackageInitial";
    subAction.Enabled = true;
    subAction.Parameters.Add(new KeyValuePair<string, IWorkflowParameterValueBase>("InternalID", new WorkflowParameterValue(WorkflowParameterType.GuidType, "$Data/BaseManagedEntityId$")));
    subAction.Parameters.Add(new KeyValuePair<string, IWorkflowParameterValueBase>("ClassGUID", new WorkflowParameterValue(WorkflowParameterType.GuidType, "$MPElement[Name='RePackaging.Request']$")));
    
    mg.Subscription.InsertSubscription(mp.Id, subAction);
    mp.AcceptChanges();

    break;
}
<ManagementPack ContentReadable="true" SchemaVersion="1.1" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <Monitoring>
    <Rules>
      <Rule ID="WorkflowSubscription_378b1659_ad6c_405b_b301_2a929e56523b" Enabled="true" Target="SystemCenter!Microsoft.SystemCenter.SubscriptionWorkflowTarget" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100">
        <Category>System</Category>
        <DataSources>
          <DataSource ID="DS" TypeID="SystemCenter1!Microsoft.SystemCenter.CmdbInstanceSubscription.DataSourceModule">
            <Subscription>
              <InstanceSubscription Type="$MPElement[Name='RePackaging.Request']">
                <AddInstance />
              </InstanceSubscription>
              <PollingIntervalInSeconds>60</PollingIntervalInSeconds>
              <BatchSize>100</BatchSize>
            </Subscription>
          </DataSource>
        </DataSources>
        <WriteActions>
          <WriteAction ID="WA" TypeID="SystemCenter1!Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction">
            <Subscription>
              <EnableBatchProcessing>false</EnableBatchProcessing>
              <WindowsWorkflowConfiguration>
                <AssemblyName>AcceptPackageRequest</AssemblyName>
                <WorkflowTypeName>WorkflowAuthoring.AcceptPackageRequest</WorkflowTypeName>
                <WorkflowParameters>
                  <WorkflowParameter Name="InternalID" Type="guid">$Target/Id$</WorkflowParameter>
                </WorkflowParameters>
                <RetryExceptions />
                <RetryDelaySeconds>60</RetryDelaySeconds>
                <MaximumRunningTimeSeconds>7200</MaximumRunningTimeSeconds>
              </WindowsWorkflowConfiguration>
            </Subscription>
          </WriteAction>
        </WriteActions>
      </Rule>
    </Rules>
  </Monitoring>
  <LanguagePacks>
    <LanguagePack ID="ENU" IsDefault="false">
      <DisplayStrings>
        <DisplayString ElementID="WorkflowSubscription_378b1659_ad6c_405b_b301_2a929e56523b">
          <Name>WF_AcceptPackageRequest</Name>
          <Description>Accepts the package request.</Description>
        </DisplayString>
      </DisplayStrings>
    </LanguagePack>
  </LanguagePacks>
</ManagementPack>

Compiling the Code

Namespaces

Microsoft.EnterpriseManagement

Microsoft.EnterpriseManagement.Configuration

Microsoft.EnterpriseManagement.Subscriptions

Assemblies

Microsoft.EnterpriseManagement.Core

See Also

Tasks

How to Create a Subscription

Reference

WorkflowSubscription
WorkflowParameterType

Concepts

Workflow Overview

Other Resources

Scenario: Defining Workflows