워크플로 관리자 1.0용 워크플로 작성, 게시 및 관리 방법

 

게시: 2016년 5월

워크플로 작성, 게시 및 관리 작업에서는 워크플로 관리자 API를 사용합니다.이 항목에서는 워크플로 관리자 클라이언트 API의 메서드 및 클래스를 사용하여 워크플로 작업을 수행하는 방법에 대해 설명합니다.

워크플로 작성

Workflow Manager 1.0에서의 워크플로 작성은 다른 워크플로 환경에서의 작성과 유사합니다.워크플로는 미리 정의된 작업 계층을 정의하는 XAML을 사용하여 선언적으로 만들어집니다.다음 코드 예제(사용자 지정 작업 샘플)는 Workflow Manager 1.0에서 실행하기 위해 만든 선언적 워크플로입니다.

<Activity mc:Ignorable="sap sap2010 sads" x:Class="MoviesActivityLibrary.GetMovies"
 xmlns="https://schemas.microsoft.com/netfx/2009/xaml/activities"
 xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
 xmlns:p="https://schemas.microsoft.com/workflow/2012/07/xaml/activities"
 xmlns:sads="https://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
 xmlns:sap="https://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
 xmlns:sap2010="https://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
 xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
 xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
 xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
  <x:Members>
    <x:Property Name="searchKeyword" Type="InArgument(x:String)" />
    <x:Property Name="numItems" Type="InArgument(x:Int32)" />
    <x:Property Name="videoDV" Type="OutArgument(p:DynamicValue)" />
  </x:Members>
  <sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
  <sap2010:WorkflowViewState.IdRef>ActivityLibrary2.Activity1_1</sap2010:WorkflowViewState.IdRef>
  <TextExpression.NamespacesForImplementation>
    <sco:Collection x:TypeArguments="x:String">
      <x:String>System</x:String>
      <x:String>System.Collections.Generic</x:String>
      <x:String>System.Data</x:String>
      <x:String>System.Linq</x:String>
      <x:String>System.Text</x:String>
      <x:String>Microsoft.Activities</x:String>
    </sco:Collection>
  </TextExpression.NamespacesForImplementation>
  <TextExpression.ReferencesForImplementation>
    <sco:Collection x:TypeArguments="AssemblyReference">
      <AssemblyReference>Microsoft.Activities</AssemblyReference>
      <AssemblyReference>Microsoft.CSharp</AssemblyReference>
      <AssemblyReference>Microsoft.Workflow.Common</AssemblyReference>
      <AssemblyReference>Microsoft.Workflow.Tracing</AssemblyReference>
      <AssemblyReference>System</AssemblyReference>
      <AssemblyReference>System.Activities</AssemblyReference>
      <AssemblyReference>System.Core</AssemblyReference>
      <AssemblyReference>System.Data</AssemblyReference>
      <AssemblyReference>System.Runtime.Serialization</AssemblyReference>
      <AssemblyReference>System.ServiceModel</AssemblyReference>
      <AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
      <AssemblyReference>System.Xaml</AssemblyReference>
      <AssemblyReference>System.Xml</AssemblyReference>
      <AssemblyReference>System.Xml.Linq</AssemblyReference>
      <AssemblyReference>mscorlib</AssemblyReference>
      <AssemblyReference>MoviesActivityLibrary</AssemblyReference>
    </sco:Collection>
  </TextExpression.ReferencesForImplementation>
  <Sequence DisplayName="GetMovies" sap2010:WorkflowViewState.IdRef="Sequence_1">
    <p:HttpGet DisplayName="HttpGetFromNetflix" sap2010:WorkflowViewState.IdRef="HttpGet_1" RetryOnConnectionFailure="True">
      <p:HttpGet.ResponseContent>
        <OutArgument x:TypeArguments="p:DynamicValue">
          <mca:CSharpReference x:TypeArguments="p:DynamicValue">videoDV</mca:CSharpReference>
        </OutArgument>
      </p:HttpGet.ResponseContent>
      <p:HttpGet.Uri>
        <InArgument x:TypeArguments="x:String">
          <mca:CSharpValue x:TypeArguments="x:String">"http://odata.netflix.com/Catalog/Titles?$filter=substringof('" + searchKeyword + "', Name)&amp;$format=json&amp;$top=" + numItems + "&amp;$select=Name, Synopsis"</mca:CSharpValue>
        </InArgument>
      </p:HttpGet.Uri>
    </p:HttpGet>
    <sads:DebugSymbol.Symbol>d3dcXHNjcmF0Y2gyXHNjcmF0Y2hcZ2dvZ29sb1xCMiAtIFRlc3RcQ3VzdG9tQ29kZUFjdGl2aXRpZXNcQ3VzdG9tQ29kZUFjdGl2aXR5U2FtcGxlXE1vdmllc0FjdGl2aXR5TGlicmFyeVxHZXRNb3ZpZXMueGFtbAQxAz8OAgEBMgU9EQIBAjoLOusBAgEHNQs1XgIBAw==</sads:DebugSymbol.Symbol>
  </Sequence>
  <sap2010:WorkflowViewState.ViewStateManager>
    <sap2010:ViewStateManager>
      <sap2010:ViewStateData Id="HttpGet_1" sap:VirtualizedContainerService.HintSize="284,120" />
      <sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="306,244">
        <sap:WorkflowViewStateService.ViewState>
          <scg:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
          </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
      </sap2010:ViewStateData>
      <sap2010:ViewStateData Id="ActivityLibrary2.Activity1_1" sap:VirtualizedContainerService.HintSize="346,324" />
    </sap2010:ViewStateManager>
  </sap2010:WorkflowViewState.ViewStateManager>
</Activity>

다음 스크린샷에는 Visual Studio 2012에서 열린 워크플로가 나와 있습니다.

GetMovies Workflow

이 예제의 워크플로는 검색 매개 변수를 기반으로 공용 웹 서비스에서 영화 정보를 검색합니다.이러한 매개 변수는 속성(검색 키워드와 레코드 수)으로 정의됩니다.그런 다음 워크플로는 검색된 정보를 DynamicValue로 반환하여 호출자가 반환된 데이터를 속성 모음으로 처리할 수 있도록 합니다.

워크플로 게시

워크플로 관리자를 사용하여 호스팅된 워크플로를 먼저 범위에 게시해야 합니다.범위와의 상호 작용은 WorkflowManagementClient를 사용하여 수행됩니다.다음 코드 샘플에서는 이 샘플의 용도로 워크플로 범위를 만드는 방법을 보여줍니다.

var rootClient = new WorkflowManagementClient(new Uri(rootScope));

            return rootClient.CurrentScope.PublishChildScope(scopeName,
                new ScopeDescription()
                {
                    UserComments = string.Format("For {0} sample only", scopeName)
                });

범위를 설정한 다음에는 해당 범위에 워크플로를 게시할 수 있습니다.모든 XAML 문서는 ActivityDescription을 사용하여 작업으로 업로드됩니다.그런 다음 WorkflowDescription을 통해 워크플로에 연관된 메타데이터가 제공됩니다.다음 코드 샘플에서는 워크플로와 해당 작업을 게시하는 방법을 보여줍니다.

// publish the activity description related with the workflow
client.Activities.Publish(
new ActivityDescription(WorkflowUtils.Translate(xamlFilePath)) { Name = workflowName });

// now, publish the workflow description
WorkflowDescription description = new WorkflowDescription
{
Name = workflowName,
ActivityPath = workflowName,
// additional properties elided for simplicity
};

// publish!
client.Workflows.Publish(description);

워크플로 관리

워크플로가 워크플로 관리자에 게시되고 나면 워크플로가 실행되고 해당 상태를 검색할 수 있습니다.다음 코드 예제에서는 게시된 워크플로를 실행하는 방법을 보여 줍니다.워크플로를 시작하면 T:Microsoft.Workflow.Client.WorkflowStartInfo 개체를 사용하여 시작 정보를 저장하는데, 이는 프로세스에서 StartInfo 개체를 사용하는 방식과 유사합니다.

Console.Write("Starting workflow instance...");
WorkflowStartParameters startParameters = new WorkflowStartParameters();
startParameters.Content.Add("Title", "Titanic");
startParameters.Content.Add("NumberOfMovies", 3);
string instanceId = client.Workflows.Start(workflowName, startParameters);

다음 코드 예제에서는 실행 중인 워크플로의 상태를 쿼리하는 방법을 보여 줍니다.상태는 문자열로 반환됩니다.

WorkflowInstanceInfo instanceInfo = client.Instances.Get(workflowName, instanceId);
currentStatus = instanceInfo.UserStatus;

if (instanceInfo.WorkflowStatus == WorkflowInstanceStatus.Completed)
{
    Console.WriteLine("\nWorkflow instance completed");
}