Delen via


How to Create a Subscription

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.]

Management pack monitoring enables objects to be processed through custom workflow. This provides a way to create the logic features of a management pack. The two components of the subscription system are the data source and the action. The data source processes an enterprise management object (EMO) and filters it based on any applicable criteria. The EMO is then sent to the action component of the subscription. You can use Windows Workflow Foundation activities as the action component.

To create a Windows workflow subscription action

  1. Find the RePackaging.Library management pack.

  2. Create an instance of the subscription criteria, the InstanceTypeSubscription class, providing the management pack class identifier for the RePackaging.Request class.

  3. Create an instance of the subscription action, the WorkflowSubscription class, providing the previously created subscription criteria.

  4. Add each parameter to the Parameters property of the workflow reference.

  5. Add the workflow to Service Manager by calling the InsertSubscription method on the management group. Provide the Id value and the workflow instance.

  6. Call the AcceptChanges method on the management pack.

Example

The following example uses the InstanceTypeSubscription criteria to trigger when a new RePackaging.Request object is created. The InstanceTypeSubscription class can also be used to trigger when the object is created, updated, or deleted.

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 Reference a Workflow

Reference

InstanceTypeSubscription
WorkflowSubscription

Concepts

Workflow Overview

Other Resources

Scenario: Defining Workflows